Commit Graph

29 Commits

Author SHA1 Message Date
Konstantin Shcheglov 1309dffc0a CQ. Move analyzer diagnostics back into analyzer.
Move the analyzer-only Diagnostic, DiagnosticMessage, Severity, and
locatable diagnostic helper types out of _fe_analyzer_shared and into
package:analyzer.

I paln to make changes outlined in
https://github.com/dart-lang/sdk/issues/63311 and chat discussion.
Keeping these classes in the analyzer simplifies the migration and
avoids introducing a shared abstraction before there is a concrete need
for one.

If we decide later need to have a shared abstraction, we can always
extract one at that point. With coding agents internal code motion is
cheap.

Update analyzer, analysis server plugin, analyzer plugin, linter, and
scanner call sites to import the moved APIs from analyzer libraries, and
refresh API baselines to reflect the new public owner.

Change-Id: Ie0ef0f01c6e4be7ebaac25619ac3e3fe991a44d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501000
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-07 13:54:59 -07:00
Konstantin Shcheglov e20704c3b0 CQ. Move PackageConfigFileBuilder to analyzer_testing.
Move PackageConfigFileBuilder into the analyzer_testing public API and
deprecate the copy exposed from package:analyzer. The builder is only
used by test infrastructure, so keeping it in analyzer_testing makes the
ownership clearer and avoids exposing test-only utilities from analyzer.

Update the builder API to accept a rootFolder instead of a rootPath.
This lets callers pass the resource-provider folder directly, so the
generated rootUri is derived from the same file-system abstraction that
created the test files. This avoids accidentally passing POSIX paths
where resource provider paths are required, such as on Windows.

Update existing test utilities and callers to import the new library and
pass Folder objects. Remove the production analysis server dependency on
the builder by emitting the temporary plugin package config JSON
directly.

Change-Id: I46b14710626e0d6d5884afcdc5a05b23077acfc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499081
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-29 13:18:35 -07:00
Paul Berry dca8eb4ae6 [API summary] Consider publicly exported names to be part of public API.
Changes the logic for deciding whether to output details about a top
level element. Previously, details would be output if the library
containing the element's declaration was in `lib` but not
`lib/src`. This led to a bug: if a top level element was declared in
`lib/src` but exported by an `export` directive in `lib`, no details
would be output, and the API summary would just show `(non-public)`
after the exported name.

This bug was mostly benign because we were working around it with an
analyzer-specific hack: when analyzing the `analyzer` package, top
level elements with an annotation of type `AnalyzerPublicApi` would
have their details output regardless of where they were declared. But
it wasn't completely benign: the tool was failing to output details of
`DartDocumentLinkVisitor` and `DocumentLink` (from
`package:analyzer_plugin`), as well as `PackageBuilder` (from
`package:analyzer_testing`).

The new logic is: details are output if the element appears in the
export namespace of any library in `lib` but not `lib/src`. I've
re-run the API summary tool so the `api.txt` files in
`package:analyzer_plugin` and `package:analyzer_testing` now include
the details they were missing.

The analyzer-specific hack is left in place, though, because there are
some analyzer classes that aren't exported, but still considered part
of the analyzer public API. In a follow-up CL, I will make the API
summary tool extensible so that this analyzer-specific logic can be
injected by the analyzer when generating its `api.txt` file, and it
won't pollute the incipient `api_summary` tool.

Change-Id: I6a6a69641d656caa4f8e6361557c13fa7485e422
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482440
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-02-20 11:21:15 -08:00
Paul Berry c6a9c9536e [api_summary] Add class modifier support.
Adds the modifiers `abstract`, `base`, `final`, and `interface` to the
API summary output.

This information is an important part of the public API of a package,
because it determines whether a client can:

- Construct an instance of the class,
- Extend the class, or
- Implement the class.

Change-Id: I6a6a6964ba07db1714bc2fcb549cc15230e87058
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482362
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-02-20 10:49:45 -08:00
Paul Berry dfd26d463c [messages] Move AbstractAnalysisRule class hierarchy into src.
Moves the following classes from
`package:analyzer/analysis_rule/analysis_rule.dart` into
`package:analyzer/src/analysis_rule/analysis_rule.dart`:

- `AbstractAnalysisRule`
- `AnalysisRule`
- `MultiAnalysisRule`
- `RemovedAnalysisRule`

These classes are part of the analyzer public API, so the file
`package:analyzer/analysis_rule/analysis_rule.dart` remains, exporting
the declarations so that they can still be used by clients.

This paves the way for a follow-up CL that will use extensions to add
functionality that we *don't* want to include in the analyzer public
API yet.

Change-Id: I6a6a696431f00f69b4b80e0d98b1b8fbb33f020f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481164
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-02-17 14:35:19 -08:00
Paul Berry 2b5e655c34 [messages] Fix test failure output.
Changes the test logic in `analysis_server` and `analyzer_testing` so
that after printing `To accept the current state, expect:`, it prints
diagnostic codes in their proper camelCase format.

Also removes some bogus code from
`pkg/analyzer_testing/lib/analysis_rule/analysis_rule.dart` that
erroneously suggested passing a `name:` parameter to the top level
`error` function. This function does not accept any parameter called
`name`.

Previously, only tests in `pkg/analyzer/test` printed the diagnostic
codes correctly.

Fixes https://github.com/dart-lang/sdk/issues/62651.

Change-Id: I6a6a6964b17cf798c1355e09f9a4633e1fbe388c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480041
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-02-12 10:15:31 -08:00
Paul Berry 599f4bf94e [messages] Move string extensions into analyzer_testing.
These extensions were previously in `pkg/analyzer_utilities`, which is
not published on `pub`. That meant they could not be used from within
the `lib` directory of any package that *is* published on
`pub`. Specifically, they could not be used from within
`pkg/analyzer_testing/lib`.

In a follow-up CL, I will modify the testing logic so that after
printing `To accept the current state, expect:`, it prints diagnostic
codes in their proper camelCase format.

Change-Id: I6a6a696432d7162906b2c235ea88310dc0aa1fa9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480040
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-02-12 10:12:02 -08:00
Sam Rawlins 39f8aa4ba8 analyzer_testing: Remove old mock APIs and old mock sources
Change-Id: If0f40090eb689438598f092877f72525a9ba7325
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477764
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-02-03 08:18:19 -08:00
Sam Rawlins 9062f80146 analyzer_testing: Deprecate the flutter_test mock; only used in two DAS tests.
Work towards https://github.com/dart-lang/sdk/issues/61597

Change-Id: I32caa38bff42ad9117829cca9be8b892da228a9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472960
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-01-14 11:03:09 -08:00
Sam Rawlins 25f0d80c15 analyzer: Refactor how the mock 'dart:ui' library is discovered
Fixes https://github.com/dart-lang/sdk/issues/62234 by making the
'dart:ui' library discoverable in the same way that the real one is
discoverable: by the sky_engine _embedder.yaml file.

Coupled with this change is the motivation: the stubs are out-of-date,
with `double width` and `double height` parameters on the Preview
constructor. But this has been changed to use a `Size` object, and
`Size` is written in 'dart:ui'. So to write a test that uses `Size`, the
test now needs proper access to 'dart:ui', and we should not write
'package:ui/ui.dart' in our test cases. These changes are in
`.../lib/mock_packages/package_content/flutter/lib/src/widget_previews/widget_previews.dart`
and in `invalid_widget_preview_private_argument_test.dart`.

Change-Id: I6f608eb3e1f431ad576ba8f3572454e42a39f9f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467680
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-01-13 15:32:51 -08:00
Sam Rawlins 49dc34715e analyzer plugins: Document how to add a stub package in tests
Fixes https://github.com/dart-lang/sdk/issues/61915

I add documentation to a few APIs, and primarily document `newPackage`
and `PackageBuilder.addFile`, which already have sufficient doc
comments.

Change-Id: Ice088c2d76604ccb991d895a1e4bb408c492b963
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467240
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-12-09 14:53:52 -08:00
Sam Rawlins 0a95e6f149 analyzer_testing: Deprecate the angular_meta mocks
Change-Id: I17a6db9acdcad8c1c8e396d4a85d1acae9007ca2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461984
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-14 13:01:19 -08:00
Sam Rawlins be3237e3ec analyzer_testing: deprecate MockPackagesMixin.addPedantic
Change-Id: I377e054a9abb167f7208f27067c905ff5947897c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460481
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-07 14:38:12 -08:00
Sam Rawlins c2d5e5726c analyzer_testing: deprecate 'package:js'-related APIs.
This includes MockPackagesMixin.addJs and
PubPackageResolutionTest.addJsPackageDep.

package:js is discontinued. We don't need to keep mocking it.

Change-Id: I71e44ee1a4c79f71bb8fa76e972f71dc64d8f56c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460520
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-11-07 13:49:36 -08:00
Paul Berry 3f29cf4b7d [analyzer_testing] Propagate linter exceptions by default.
Changes the behavior of the `analysisOptionsContent` function so that
unless `propagateLinterExceptions: false` is passed to it, it creates
an analysis options file that specifies a `true` value for
`propagate-linter-exceptions`.

This ensures that when tests that use `package:analyzer_testing` are
run, exceptions that occur while processing lint rules will cause the
test to fail. Previously, such exceptions would be silently swallowed
by the analyzer, and the test would pass.

Change-Id: I6a6a69643d76cf15d801eab5c4ce6a77c7dbac96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-11-06 14:39:20 -08:00
Sam Rawlins c0bd240db8 Simplify testing analysis rule by registering in AnalysisRuleTest
This changes the API of writing an analysis rule test. Instead of
overriding the `String get analysisRule` property, and registering the
rule in `setUp` (which requires importing a private type), the
developer can now just set the `AbstractAnalysisRule rule` field in
`setUp`. This both removes the requirement to manually register the
rule, and reduces the risk of typos, by removing the String API.

Fixes https://github.com/dart-lang/sdk/issues/61793

Change-Id: Ic7753d3157e06906ba5ccbccfea67aaa3179dcc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459340
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-11-03 10:20:00 -08:00
FMorschel 240eda5647 [analyzer] Migrates to contexMessages from analyzer_testing package
This also includes some small refactorings for parameter names to start using the diagnostic wording instead of error. As well as a small change to `contextMessage` and related to use a list of `Pattern`s instead of a single `String` for better matching.

In future CLs, the TODOs added in this one will be addressed so we can fully migrate this. Added them because of the size of the CL.

Bug: https://github.com/dart-lang/sdk/issues/61557
Change-Id: I5557668a1baed98faff977255c9f22e0d9d96008
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452180
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-10-20 13:37:00 -07:00
FMorschel ffd6c48d01 [analyzer_testing] Duplicates ExpectedContextMessage to start migrating
This is a first step towards migrating and merging tests helper classes to one central location. In a following CL, the old `ExpectedError` and `ExpectedContextMessage` will be removed and all clients will be migrated to the version under this package.

Bug: https://github.com/dart-lang/sdk/issues/61557
Change-Id: I7fb8a83cbd659192a22848ace99ebafed5dc2b88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451542
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-09-26 12:48:28 -07:00
FMorschel 0aacd0c8c9 [DAS] Makes AbstractContextTest.createAnalysisOptionsFile like analysisOptionsContent
This change is only meant to improve consistency and readability in the test code. The `analysisOptionsContent` function had more parameters and now both take the same things. Also, `createAnalysisOptionsFile` now doesn't implement the same behaviour as `analysisOptionsContent` because it simply invokes it instead.

Change-Id: Ie84f30f4affc1fb106598d636cd6fcf263e6520e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445100
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
2025-09-26 11:24:21 -07:00
Paul Berry 8b23e3449d [analyzer] Move some error reporting code into _fe_analyzer_shared.
The following classes are moved from `package:analyzer` to
`package:_fe_analyzer_shared`:

- `Diagnostic`
- `DiagnosticMessage`
- `DiagnosticMessageImpl`

The following declarations are also moved, since they are needed by
the above classes:

- `formatList`
- `Severity`
- `Source`
- `TimestampedData`

There is no change to the analyzer public API, and `export`
declarations have been added to the analyzer libraries that the
declarations have been moved from, so that code depending on these
declarations is unaffected.

These changes are part of a larger arc of work that introduces methods
`.withArguments` and `.at`, forming a literate API for reporting
analyzer errors that looks roughly like this:

    diagnosticReporter.reportError(
        ERROR_CODE.withArguments(...arguments...).at(...location...));

Moving this code into `_fe_analyzer_shared` is necessary because
scanner error codes are defined inside `_fe_analyzer_shared` (to allow
the scanner to be shared between the analyzer and CFE). Hence, to
avoid a circular depedency between `_fe_analyzer_shared` and
`analyzer`, the `.withArguments` and `.at` methods will need to live
in `_fe_analyzer_shared` too, as well as the classes representing the
diagnostic messages they create.

Note that there are some minor changes to
`pkg/analysis_server_plugin/api.txt` and
`pkg/analyzer_plugin/api.txt`; these have to do with the way the
`api.txt` generator chooses to report referenced elements, and don't
reflect actual API changes.

Change-Id: I6a6a6964a5c46f4a0205ce0d85620669ce55eb3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444620
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-08-12 11:09:33 -07:00
Sam Rawlins 69e9fd545f analyzer_testing: split assertDiagnosticsIn into multiple, overridable methods
Work towards https://github.com/dart-lang/sdk/issues/61271

Change-Id: I3732176b84fb0ce79d2de180e8fb32d76ea4a08c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444361
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-08-11 09:47:30 -07:00
Sam Rawlins f81079035f analyzer_testing: Move LintRuleTest and linter's PubPackageResolutionTest
Most of the behavior of LintRuleTest is extracted into a public class
in analyzer_testing, AnalysisRuleTest. A little bit of code is left in
LintRuleTest, so that first-party lint rules can be tested by
registering the first-party lint rules. And those lint rules can
declare the `lintRule` that each is concerned with, rather than the
new `analysisRule` getter.

PubPackageResolutionTest is left as private impl, because I think it
may undergo some changes, and we may be merging more shared code, and
the name may change. A few first-party lint rules have tests that
refer to this class, which is OK.

Other than that, no code or behavior changes are in this CL.

Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: I447850c438af7d0fe90889d2eaec6f2f8b4f8281
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-20 10:25:50 -07:00
Sam Rawlins e35e665259 analyzer_testing: convert all modifyFile users to modifyFile2
This also involves tidying up blaze_watcher_test, in order to
easily get back a File object from a helper method.

Change-Id: If9dc812dc3a97a205dee600b89c3e8490e9efcba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429201
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-05-19 07:11:23 -07:00
Sam Rawlins 750ecda6b3 Remove two underused methods from ResourceProviderMixin
Change-Id: I41f288f216e7db5a744d10a38074e104321e49f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429220
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-17 10:39:12 -07:00
Sam Rawlins bd700772ff analyzer: move testing utilities to analyzer_testing package
Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: Iae062d95e5cf3b94b540496242b3627268ac2612
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428844
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-05-15 16:28:50 -07:00
Sam Rawlins c4c9854b9b analyzer_testing: Move ResourceProviderMixin to analyzer_testing
Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: I31932409e495369793dd16c017385c98b86cf44c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427480
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-09 16:56:29 -07:00
Sam Rawlins 2f706c4290 analyzer_testing: move experiments library to analyzer_testing
Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: I9c5aa920e9f96f99ea00d6993b5f4dafd415f831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426986
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-07 13:12:13 -07:00
Sam Rawlins 7431e885e8 analyzer_testing: Move in the mock packages.
Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: Ic789b8347d3bfc71a02af423fbb1a8c58da7b32d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424921
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-05-06 11:32:22 -07:00
Sam Rawlins fafad4e03d analyzer: Move the API tool so that it can generate API for other packages
Also, add some scripts to generate the analyzer_testing API, and checkin
the api.txt file for analyzer_testing.

In order to avoid a private analyzer import, I add `isExperimental` and
`hasExperimental` support for `@experimental` annotation, and switch
to using public APIs in `_dumpElement`.

Change-Id: I44319270d4e6083b80973b45933268c472876232
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426282
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-05-02 14:22:31 -07:00