Commit Graph

64 Commits

Author SHA1 Message Date
Sam Rawlins ed640293af meta: Annotate _Literal with TargetKind.constructor
Work towards https://github.com/dart-lang/sdk/issues/62253

The removed tests are for code which is no longer related to this
warning. Reporting on an extension type or a method is the purview of
the `invalid_annotation_target` warning. I'll note this in the summary.

Change-Id: Ide349bc1e414da339b9e89da25e383859a8144a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469761
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-12-30 09:29:37 -08:00
Sam Rawlins 89250d64b9 meta: Annotate nonVirtual with TargetKind.overridableMember
In the analyzer, reduce our custom warning for `nonVirtual`, (largely
replaced by the existing `invalid_annotation_target` warning). The
tests for that warning are mostly covered by the existing
`invalid_annotation_target` tests, but I added a few to fill some gaps.

Otherwise, we still report a specific warning for this annotation being
placed on an abstract member, or an instance member of an extension
type.

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

Change-Id: Ibcde2f99cf53460bff636bfc8bbf07e80779a942
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469104
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-12-23 09:47:27 -08:00
Sam Rawlins 971aa0b12a meta: Annotate visibleForOverriding and visibleForTesting with TargetKinds
In the analyzer, remove our custom warning for `visibleForOverriding`,
`invalid_visible_for_overriding_annotation` (replaced by the existing
`invalid_annotation_target` warning). The tests for that warning are
mostly covered by the existing `invalid_annotation_target` tests, but
I added a few to fill some gaps.

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

Change-Id: Ie960db6ebe007afde787f68e4b6b9f20a1835639
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468702
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-12-18 12:05:43 -08:00
Sam Rawlins 2e090517db analyzer_testing: Move last flutter mocks to multi-line strings
Work towards https://github.com/dart-lang/sdk/issues/61597

Change-Id: Idbd74c5b6ef8f4f68624c790686cf8bf8b05f9a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467441
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-12-10 14:58:21 -08:00
Sam Rawlins 43404dd651 analyzer_testing: Add mixed-in types; other fixes
My generator was not writing "with clauses," so this corrects that.

Additionally:

* `Diagnosticable.debugFillProperties` has annotations that I missed.
* `DiagnosticableTree.debugDescribeChildren` has an annotation that I
  missed, and can be abstract.
* VoidCallback was moved to `dart:ui`, and I had missed this.

Change-Id: I6c4c79a1532ede84e8fdbeed754662b67e5c8282
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467380
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2025-12-10 10:23:29 -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 ccb30ca650 analyzer_testing: Move Flutter rendering and widgets mocks to multi-line strings
Work towards https://github.com/dart-lang/sdk/issues/61597

Change-Id: I3ddd08896c91f297d4a993fb39f75e8777cd4cea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466980
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-12-09 13:30:49 -08:00
Paul Berry b23165db60 [messages] Use lower case diagnostic names in analyzer_testing.
Changes the logic in `pkg/analyzer_testing` to use
`DiagnosticCode.lowerCaseName` instead of `DiagnosticCode.name`. This
ensures that diagnostic codes are matched in a case-insensitive
fashion.

This paves the way for deprecating (and eventually removing) the
`DiagnosticCode.name` getter.

Change-Id: I6a6a69640838d820e8e466c23289bdf2c30eb517
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466280
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-12-09 06:41:22 -08:00
Paul Berry 7ac6ad6d42 [messages] Make lint name matching case insensitive.
Adjusts the logic in the lint `Registry` class so that lint names are
matched in case-insensitive fashion. For the most part this is
accomplished by adding calls to `.toLowerCase()` inside the `Registry`
class, preserving its API.

For the `enabled` method, preserving the API would have been a pain (I
would have had to translate the keys in the `ruleConfigs` parameter to
lower case). So instead I added an assertion to verify that the keys
were lower case, and pushed the responsibility to the callers to
create lower case keys.

This paves the way for a follow-up CL that will translate diagnostic
codes to `lower_snake_case` conventions.

It also solves a longstanding problem with the mixed case lint rules
`no_runtimeType_toString`, `prefer_for_elements_to_map_fromIterable`,
`prefer_iterable_whereType`. Previously, the user had to carefully
imitate the capitalization of the lint rules when specifying them in
the `analysis_options.yaml` file, even though `// ignore:` comments
for the lints matched in case insensitive fashion. With this CL, the
lint rule names in `analysis_options.yaml` are matched in case
insensitive fashion as well.

Change-Id: I6a6a6964d83241e49878bbf96ef9b94cbb12098b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465964
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-12-03 13:14:49 -08:00
Sam Rawlins 81f561c7f6 analyzer_testing: Migrate flutter painting mock libraries
Change-Id: Ia29fd5f1413e0b3d0b32e24c7232c755d7f2bafb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465960
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-12-03 12:06:02 -08:00
Sam Rawlins c5b86a3dd8 analyzer_testing: Migrate flutter mocks to in-code Strings
(just animation, foundation, and widget_previews)

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

In this CL, I try to keep the elements generally the same as they
are in `pkg/analyzer_testing/lib/mock_packages/package_content/flutter`
and only correcting things that are wrong/out of date. To that end:

* AnimationController extends Animation, which is defined in
  `lib/src/animation/animation.dart`, so we add that.
* FlutterErrorDetails.new has many more parameters.
* Listenable and ValueListenable are necessary, so those are added in
  `lib/src/foundation/change_notifier.dart`.
* There is no `Key._` constructor, but there is now `Key.empty`.
* Preview no longer has a `width` or `height` property (or constructor
  parameter) but now has `size`.

Change-Id: I7e73d26e6fdf9896b24e1d908f0bf2950f67db16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465660
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-12-02 14:02:40 -08:00
Konstantin Shcheglov 20085c0902 DeCo. Don't remove experiment from shared experimentsForTests.
Change-Id: If746609320113a42c161021f7c7328cf79bd46fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465483
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-12-01 16:07:30 -08:00
Sam Rawlins 870c08b50a analyzer_testing: Migrate dart:ui mocks to live in source strings
Change-Id: Idf51f83dfdf5c6173bbbdedabcd41d76c928cc8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465160
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-12-01 14:54:50 -08:00
Kallen Tu 2110e90d68 Rename 'declaring-constructors' to 'primary-constructors' experiment flag.
Changed the flag to `primary-constructors` to align with the rest of
the feature's public naming.

Renamed tests and existing usages of the flag.

Bug: https://github.com/dart-lang/sdk/issues/61526
Change-Id: Id649447a50917ba5bcddb49661555889dc81ba14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464761
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
2025-12-01 13:54:52 -08:00
Sam Rawlins 701af8d0d1 analyzer_testing: Move mock meta package into strings
Change-Id: I80c4c888be656f230ea3bc9a53154c5f632e22e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462840
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-21 08:30:41 -08:00
Sam Rawlins b65b23650e analyzer_testing: Add deprecation to required annotations
When generating the mock packages from the real packages, I found this
discrepancy; we're missing this deprecation. To keep things aligned as
close as possible, we should add it.

Change-Id: Ibbfd9164be5b344c358a4546542723f7deaff73d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463162
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-20 13:46:18 -08:00
Konstantin Shcheglov 429062a0eb Fine. Use 'withFineDependencies: true' in analyzer_testing/.
Change-Id: I85dad7f6c51bbdf120174af0fa009fcb797e3562
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462220
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-11-14 14:59:11 -08:00
Sam Rawlins 35f4795cf1 analyzer_testing: Move mock ffi package
The only piece that _changed_ is the Allocator class and Opaque class.
The previous (deleted) mock package for ffi included these classes,
but the real ffi package does not declare either. Instead,
`dart:ffi` declares these classes. The mock dart:ffi already has a
stub Opaque class, and this change adds the Allocator class.

Change-Id: I561bda1375c8711ae819ffe0bc562e5570b31cc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461902
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-14 13:17:20 -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 da5701683b analyzer_testing: Move three mock packages
This moves the sources for the mock fixnum, test_reflective_loader,
and vector_math packages to be loaded via multi-line Dart strings.

Change-Id: I95800ebc417afd4a6b1a5103ffd9e69329022cf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461526
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-11-13 11:08:11 -08:00
Paul Berry 9f6d1c1029 [messages] Start using toplevel diagnostic constants.
Changes the analyzer and related packages so that when they refer to
diagnostic constants, they do so via the import prefix `diag`, which
refers to the appropriate `diagnostic.dart` file containing the top
level diagnostic constant declarations, rather than the static
declarations inside `DiagnosticCode`-derived classes (which will soon
be removed).

This CL was created by the following steps:

- Run the script
  `pkg/analyzer_utilities/tool/messages/switch_to_toplevel_diagnostics.dart`.

- Execute `dart fix --apply --code=unused_import,unnecessary_import`
  on the following directories (this removes imports that are no
  longer necessary due to the change):
  - `pkg/analysis_server`
  - `pkg/analyzer`
  - `pkg/linter`
  - `pkg/analysis_server_plugin`
  - `pkg/analyzer_plugin`
  - `pkg/analyzer_testing`
  - `pkg/front_end`
  - `pkg/analyzer_cli`

- Execute `dart format` on the following files and directories:
  - `pkg/analysis_server`
  - `pkg/analyzer`
  - `pkg/linter`
  - `pkg/analysis_server_plugin`
  - `pkg/analyzer_plugin`
  - `pkg/analyzer_testing`
  - `pkg/front_end/test/scanner_test.dart`

  (Note that `pkg/front_end` and `pkg/analyzer_cli` are not
  re-formatted as whole directories because they contain `.dart` files
  that are test cases rather than source code, and reformatting those
  files might change test expectations.)

- Manually add `diag` to
  pkg/front_end/test/spell_checking_list_tests.txt.

- Manually fix the ignore comment in
  `pkg/analyzer_testing/lib/src/analysis_rule/pub_package_resolution.dart`. (The
  script `switch_to_toplevel_diagnostics.dart` automatically adds it
  after `import 'package:analyzer/src/diagnostic/diagnostic.dart' as
  diag;`, but then executing `dart format` bumps the ignore comment to
  the following line, where it has no effect.)

Change-Id: I6a6a69643022aab2b5a6224fb4124eead243260d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461521
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-11-12 16:53:42 -08:00
Sam Rawlins b5bc76081d analyzer_testing: Simplify caching mock files
Before this change, `_cacheFiles` was a function that took a Map as a
parameter, which was always empty, and returned `void`, because the
Map is an output parameter. This was kind of like a return type, but
with extra steps.

In this CL, I make the function return a Map, and then
`MockPackagesMixin._cachedFiles` can be made non-nullable, and
`late final`, with a simpler lifecycle.

Change-Id: Iae236e43de32d4ed82466cfa5661d266c52b14ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460202
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-10 13:46:58 -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
Sam Rawlins 0b0a6373b4 analyzer_testing: deprecate PubPackageResolutionTest.addKernelPackageDep
This shared mock did not carry its weight. It should have more use cases
in order to support as a pre-made mock package. We can instead make a
simple custom mock package in the one test that used it.

Change-Id: I9877b114918bc42f5b72616b91085adecf6c194b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460500
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-11-07 11:55:51 -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
Chloe Stefantsova 32eb405d69 [analyzer] Include static-extensions in experimentsForTests
Part of https://github.com/dart-lang/sdk/issues/61484
Part of https://github.com/dart-lang/sdk/issues/61485

Change-Id: I06bfb52304857568330cf35281f6d3e70807918d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454780
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-10-20 08:35:13 -07:00
Sam Rawlins 3eb9614c36 analyzer_testing: Introduce PubPackageResolutionTest.newPackage
Work towards https://github.com/dart-lang/sdk/issues/61079

This change offers up a convenient API for adding packages (often mock
packages) to the resource provider used in tests.

Change-Id: I0f29e2fa5ece0b6260173949c9e8418fce63fc91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453844
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-10-08 08:56:23 -07:00
Robert Nystrom 557db62620 Add experiment flag for "Private Named Parameters".
Fix #61631.

Change-Id: If797277e0ff294f11515ccfec845381b07c34a11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453643
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2025-10-07 17:15:11 -07:00
Kallen Tu 4cdf9740e9 Add 'declaring-constructors' experiment flag.
This CL adds the flag for the primary/declaring constructors feature.
We'll develop the feature under this flag.

Bug: https://github.com/dart-lang/sdk/issues/61526
Change-Id: I0318998cef7ee1a306af243f4dc15c65ae9f8d96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453640
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-10-07 11:17:17 -07:00
Sam Rawlins 1188d014a9 analyzer_testing: improve error message when trying to use built-in mocks
Work towards https://github.com/dart-lang/sdk/issues/61597

The analyzer_testing package's mock packages are "data" or "resource"
files which are notoriously hard to find on disk. No dart tooling I
know of can give me "the root directory of a package which is
referenced in a Dart program via "package:". Konstantin notes that
a program may be compiled ahead of time, and so the running VM itself
does not know where source files originally came from.

When users of the analyzer_testing package try to use
`addFlutterPackageDep` in a test, which attempts to locate the Dart
SDK's `pkg/` root directory, they get a StateError. This CL adds more
information and context to that error.

Change-Id: I3ae55cd580c8fa16ca86d66e6f7b655b8f9bcc42
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452532
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-30 21:21:39 -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
Sam Rawlins 952d76898c analyzer_testing: Add comment about awaiting various APIs.
Change-Id: I8761223d45756ddea4ed21c59530239b8414855e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451122
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-23 21:00:20 -07:00
Paul Berry bdff48309f [meta] Remove @experimental annotation from @redeclare.
This annotation has been supported for some time, and is a valuable
piece of the "extension types" feature.

Change-Id: I6a6a6964f02564ff673cbdd6fca6b8bc69e5a06a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451160
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-09-23 16:38:03 -07:00
Sam Rawlins a2491e487b analyzer_testing: bump to language 3.9
Change-Id: Iaf20cd6e78e3950935a1f2002bd5854a9d4108bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447120
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-08-27 07:24:44 -07:00
Kallen Tu f93aea7c54 Enable 'dot-shorthands' feature flag for Dart 3.10
This CL enables the dot shorthand feature by default in Dart 3.10.

Dot shorthands allow you to omit the type name when accessing a static member in a context where that type is expected.

These are some examples of ways you can use dot shorthands:

```dart
Color color = .blue;
switch (color) {
  case .blue:
    print('blue');
  case .red:
    print('red');
  case .green:
    print('green');
}
```

```dart
Column(
  crossAxisAlignment: .start,
  mainAxisSize: .min,
  children: widgets,
)
```

To learn more about the feature, check out the feature specification located here: https://github.com/dart-lang/language/blob/main/working/3616%20-%20enum%20value%20shorthand/proposal-simple-lrhn.md

Tested: Feature tested with language tests and unit tests for the frontends, VM, web.
Bug: https://github.com/dart-lang/sdk/issues/57036
Fixes: https://github.com/dart-lang/sdk/issues/57037
Change-Id: I4e2cab29e33ed266603942eaebf3f9671ef60766
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427802
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-08-18 12:38:35 -07:00
Paul Berry f2123a8f7c [analyzer] Rename error constants to camelCase.
This change was generated by the following process:

- The script `pkg/analyzer/tool/messages/rename_error_constants.dart`
  was run. This generated the vast majority of the diffs.

- Then all modified files were reformatted using
  `tools/sdk/dart-sdk/bin/dart/format`.

- Finally, the script `pkg/analyzer/tool/messages/generate.dart` was
  run, to rebuild generated code.

Change-Id: I6a6a69644ed8740ad6269d98cb169076151824ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444921
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-08-13 22:02:42 -07:00
Sam Rawlins af5e3aaab9 analyzer: Remove some exports from rule_context.dart
Until recently, everything in rule_context.dart was found in
linter.dart. That file was broken up [1]. That file previously had a
lot of exports; it was a sort of barrel file for lint rules. In order
to make that change "minimal," (it was still huge), I retained some of
the exports. Now we're in the process of removing those exports.

In this change, I remove the exports for `rule_state.dart` and `linter_visitor.dart`. This doesn't affect too many files.

[1]: https://github.com/dart-lang/sdk/commit/438b560e44659cebf73bccba3ecf968806477c5c

Change-Id: I83110b22a07186560f6c853f033e070ac050ecd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445123
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-08-13 17:41:23 -07:00
Sam Rawlins 438b560e44 analyzer: Dismantle legacy 'linter.dart' library
This library mostly exports _public_ API, and the to-be-deprecated
NodeLintRegistry class. So we just move private RuleContext classes
into a new library, and remove the exports.

The lint rules then are adjusted, mostly just renaming
NodeLintRegistry -> RuleVisitorRegistry. But also, this removes a lot
of implementation imports; most rules now have _no_ private imports!

Change-Id: I023f7efa979f94d208a6ae7421902145e8761c9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443364
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-08-11 13:59:53 -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 8546b2e4e6 analyzer_testing: Move Spelunker into this package
The Spelunker class is only used by analyzer_testing's
PubPackageResolutionTest class, and by a utility script. So I believe
the best place for this class is in analyzer_testing, for two reasons:

* Would we also move the utility script
  (`pkg/linter/tool/spelunk.dart`)? This is a script that lets you see
  a visual tree of the syntax nodes of a Dart script. It has been
  helpful to people writing lint rules, as it helps you understand how
  you need to walk up or down the tree to check conditions. Therefore,
  it will be at least as helpful to people writing analysis rules in
  analyzer plugins (the primary consumers of PubPackageResolutionTest).
  It doesn't need to live in `bin` (though that's one possibility). It
  can live in `analyzer_testing/tool`.
* Then if the utility script lives in analyzer_testing, and
  PubPackageResolutionTest lives in analyzer_testing, and these are the
  sole consumers of Spelunker, it makes sense to move it into
  analyzer_testing. It does not need to be public API; just live in the
  source code.

Change-Id: Id607091b35ab83c96b8cd73f0ece63923c934fb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444240
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-08-07 12:29:10 -07:00
Lasse R.H. Nielsen f7f0f71a2e Don't use part of library.name in platform libraries.
The feature will go away when we get any new part-affecting
language feature, whether enhanced parts or import shorthands.
Might as well be prepared.

Not touching tools/dom.

CoreLibraryReviewExempt: No changes to actual code. Also, vacation.
Tested: No behavior change, no new tests.
Change-Id: Ie70f07b9f8f73edd93bf37b93de60662e271a0e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/440221
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-08-07 07:05:19 -07:00
Chloe Stefantsova d6ad61c2ca [analyzer] Collect enabled experiments in experimentsForTests
This CL removes the unnecessary overrides of the `experiments` getter
from the tests and collects the corresponding experiment flags added to
the returned value of the getter in the individual tests to the
'experimentsForTests' list that is used by all tests. Specifically, the
experiments `variance` is enabled for all tests.

The flag `inference_update_1` is removed from the experiments list,
since it's enabled by default. In the tests that explicitly require a
distinction between the flag being enabled and disabled, the getter
`_isEnabled` is overridden and returns a value corresponding to the
test.

The flag `inference_update_4` still appears in one of the overrides of
the `experiments` getter, since enabling it in all tests appears
breaking.

This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/430720/comment/4c3f016e_4933f925/

Change-Id: I4d35e3c6259e2f7e6751d180b5790c13f68de1ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434360
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-07-01 22:48:49 -07:00
Sam Rawlins f51d37e9b1 analyzer: Rename ErrorReporter to DiagnosticReporter
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I84b095199773040fc0444364964654c4373a9d77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433740
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-10 12:24:34 -07:00
Sam Rawlins 7b42aae99f analyzer: Deprecate AnalysisResultWithErrors.errors in favor of .diagnostics
Also rename UnitAnalysisResult.errors (package-private API) to .diagnostics

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

Change-Id: I0bdd7c9c19cff3bff9ee61fe4689564a7b5b727b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433581
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-09 15:51:01 -07:00
Sam Rawlins c219974ecf analyzer: Deprecate Diagnostic.errorCode in favor of diagnosticCode
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I2c7d64a81bc214e64fbc3ac95cf1fe2363a6ebd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433242
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-06-09 09:22:22 -07:00
Sam Rawlins 903d77cc82 analyzer: Rename ErrorListener classes to DiagnosticListener
Work towards https://github.com/dart-lang/sdk/issues/60635

I tried to keep this minimal but still sensible:

* Rename AnalysisErrorListener and all subtypes to use 'Diagnostic'.
* Rename all instantiations of such classes if they previously
  contained the word 'error'.
* Rename `RecordingDiagnosticListener.errors` to `.diagnostics`.
* Rename some _testing_ instance members that had the word 'error'
  to instead use 'diagnostic'.

Change-Id: I3948e27ba28ac2494092e04f4e1d201a20cc1135
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433004
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-06-05 14:05:40 -07:00