Files
sdk/pkg/analyzer/doc/implementation/pub_diagnostics.md
T
Jonas Finnemann Jensen 43c8d637bd Refactor PubspecValidator
Unclear, if this was intentionally written as classes.
It just seemed confusing to me. Since the classes were essentially
functions that had some of their arguments passed in the constructor
and some of their arguments passed in a method call.

It also seemed impossible to reuse the actual objects.

Change-Id: I56b341ee4851d24b9d176857a53b96f7eb941335
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317883
Commit-Queue: Jonas Jensen <jonasfj@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-08-16 12:31:30 +00:00

55 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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:
1. Introduce a new `PubspecWarningCode` code to `messages.yaml`.
2. Re-generate Dart error code files (run `generate_files`).
3. Add corresponding tests to a new test library in
`test/src/pubspec/diagnostics`.
4. Implement analysis in a new validator in `lib/src/pubspec/validators` and
add it to list of validators in `pubspec_validator.dart`
(or enhance an existing one).
Once implemented, youll 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](https://ci.chromium.org/p/dart/builders/ci.sandbox/analyzer-analysis-server-linux)
[flutter-analyze-try](https://ci.chromium.org/p/dart/builders/ci.sandbox/flutter-analyze)
[flutter-engine-linux-try](https://ci.chromium.org/p/dart/builders/ci.sandbox/flutter-engine-linux)
Youll 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.
[pub client check](https://github.com/dart-lang/pub/blob/ab41ef0aaef7a20f759c6147aa8121a1396ee589/lib/src/validator/deprecated_fields.dart#L18-L35)
1. The initial PR: https://dart-review.googlesource.com/c/sdk/+/204420 (notice
the breakage to analyzer_plugin and telemetry that needed fixing).
2. Flutter repo fixes: https://github.com/flutter/flutter/pull/84997 and
https://github.com/flutter/flutter/pull/85036.