This doc lives internally (@ go/analyzer-pub-diagnostics) but Jonas suggested it might better serve in the analyzer docs, so here it is! :) Change-Id: Iec50c263c6621fe15d05282cfcac2eafea5a420e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285884 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
2.3 KiB
Adding a new pubspec diagnostic
This document describes the process of adding a new (non-lint) pubspec diagnostic to the analyzer.
Background
Analyzer parses pubspecs and sends change notifications to a validator that can be used to produce diagnostics in pubspec.yaml files. Taking advantage of this we can provide rich dynamic feedback to authors as they type.
Recipe
The basic recipe for implementing a new pubspec diagnostic is as follows:
- Introduce a new
PubspecWarningCodecode tomessages.yaml. - Re-generate Dart error code files (run
generate_files). - Add corresponding tests to a new test library in
test/src/pubspec/diagnostics. - Implement analysis in a new validator in
lib/src/pubspec/validatorsand invoke it from PubspecValidator (or enhance an existing one).
Once implemented, you’ll want to look for ecosystem breakages. Useful bots to watch:
- [analyzer-analysis-server-linux-try][] analyzes SDK packages and is a great early warning system
- [flutter-analyze-try][] and
- [flutter-engine-linux-try][] will tell you if your change will block an SDK roll into Flutter
analyzer-analysis-server-linux-try flutter-analyze-try flutter-engine-linux-try
You’ll need to clean up these downstream breakages before you can land yours.
In the case of SDK breakages, you can fix them in your initial PR. Flutter and Flutter Engine breakages should be handled in PRs to their respective Flutter repos.
Example: Deprecated Fields
The introduction of diagnostics for deprecated fields (corresponding to the existing [pub client check][]) demonstrates a lot of these ideas and serves as a good jumping off point for future diagnostics.
- The initial PR: https://dart-review.googlesource.com/c/sdk/+/204420 (notice the breakage to analyzer_plugin and telemetry that needed fixing).
- Flutter repo fixes: https://github.com/flutter/flutter/pull/84997 and https://github.com/flutter/flutter/pull/85036.