Commit Graph

615 Commits

Author SHA1 Message Date
Konstantin Shcheglov be4df1a869 API. Add Folder.getFile/Folder, deprecate getChildAssumingFile/Folder
This aligns names with ResourceProvider.getFile/Folder.

Change-Id: I30383ef1fa6f7cbe60b187338e25b8ca75806730
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/511120
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-06-11 07:46:21 -07:00
Jake Macdonald 7c3c71ae4d Don't lint on raw types in constant patterns if the matched type is of type Type.
The issue does not have total consensus but I do feel strongly and the
fix was trivial and so I am just sending this out.

Feel free to push back if you feel strongly, or I should go through some
formal process.

Bug: https://github.com/dart-lang/sdk/issues/59334
Change-Id: I7c5e25e9754c4cebd427b8dc9ccfbe8daa57e71a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510460
Auto-Submit: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2026-06-10 08:23:43 -07:00
Brian Wilkerson 9f47e3186d Add an unnecessary_primary_constructor_body lint
The lint will fire even when there is a comment in the body, such as
```dart
class C() {
  this { /* comment */ }
}
```

I think this is the right behavior because I can't think of any useful
comment that wouldn't be better somewhere else, but let me know if you
disagree.

This doesn't yet have a fix, but it should.

Change-Id: Ia5ffa6b06c75a6a7400ec32a9d22209c08a9c73d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510401
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-06-09 11:39:04 -07:00
Keerti Parthasarathy 9bbfa6ffd9 [primary contructors] Fix use_declaring_parameters to ignore fields with doc comments.
Closes https://github.com/dart-lang/sdk/issues/63518

Change-Id: I51fb1a07a758e3d94a212537bc5560e66c483982
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509181
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-06-08 15:13:54 -07:00
Sam Rawlins d7d118f75e linter: Fix bug in no_dynamic_casts w.r.t. Object? for-loop variable
I discovered this bug while migrating Flutter to the new lint rule.

Change-Id: I7944adff58299907e50bf0b2af3b992ec25721ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510142
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-06-08 15:04:42 -07:00
Sam Rawlins d33ce2f88d linter: Introduce no_dynamic_casts replacing strict-casts
Work towards https://github.com/dart-lang/sdk/issues/63527

We will want to deprecate the `analyzer/language/strict-casts` setting,
but we first need to ship an SDK to Flutter that offers the lint rule,
before we deprecate the setting, which will cause CI to fail (like a
Dart->Flutter roll).

When the deprecation is enabled, we can also ship the automated fix.

Change-Id: I0e9651171b721577acbd416d254bca3d0324f3f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509521
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-06-05 07:02:01 -07:00
Sam Rawlins 4c6fe56ae3 linter: Introduce no_raw_types replacing strict-raw-types
Work towards https://github.com/dart-lang/sdk/issues/63516

I have code here to deprecate the `analyzer/language/strict-raw-types`
setting. But I disabled it, as I realized we first need to ship an SDK
to Flutter that offers the lint rule, before we deprecate the setting,
which will cause CI to fail (like a Dart->Flutter roll).

When the deprecation is enabled, we can also ship the automated fix.

Change-Id: I17d1ea9aba96063059e37891c05d4a8bd3f02737
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509063
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-06-04 14:12:28 -07:00
FMorschel ab017d3bda [linter, DAS] Adds new diagnostic opposite of unnecessary_await_in_return
Bug: https://github.com/dart-lang/sdk/issues/62555
Change-Id: Ica84ea93efcb2c74d2fd260cdceebbf6558e7bf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477660
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: FMorschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-06-02 15:06:00 -07:00
Sam Rawlins 02ecbc8cf2 Report and offer fix for wildcard stack trace variable
Fixes https://github.com/dart-lang/sdk/issues/55738

Turns out there are many unused StackTrace variables here and there in
our tests, so those are ignored in a few files.

Change-Id: Iff9d0db265b96aca608261cb4518b372255d19cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501223
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-06-01 15:55:44 -07:00
Brian Wilkerson 3b81982dec Fix a false positive in avoidUnusedConstructorParameters
Primary constructor parameters can be referenced in field initializers,
and the lint was failing to account for that.

Change-Id: Ib68d4a923cdbd7568be6b463d8f9f6ff1b0b682e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507201
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-29 07:41:59 -07:00
Konstantin Shcheglov a898adf8b7 Augment. Support for abstract top-level variables and static fields.
Change-Id: Idf0ce319492c405dd06364cb6feb81e000a7c741
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506606
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-05-28 09:19:15 -07:00
Paul Berry afcfbbeba8 Migrate developer experience packages to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates the packages owned by the developer experience
team to use the new constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) bumping the
packages' SDK constraints to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Since this change requires bumping SDK constaints to `3.13.0-0`, it
was only performed on packages that are *not* published on
pub. (Packages that *are* published on pub should remain on lower
language versions until at least after the stable version of 3.13 is
released, so that we don't block users on the stable channel from
receiving updates to those packages.)

Change-Id: Ibb4daebafd239da58251e838ea6a3f336a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505046
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
2026-05-27 14:52:58 -07:00
Konstantin Shcheglov ba760c36a4 Augment. Report augmentationInducedGetterAlreadyComplete and augmentationInducedSetterAlreadyComplete.
Change-Id: I87ba9c5b6c489417173a387bded700f52b52e7ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506501
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-27 11:17:44 -07:00
Sam Rawlins 0fa39c9649 linter: Switch cascade_invocations to report once for a set of cascadable statements
Fixes https://github.com/dart-lang/sdk/issues/58688

Change-Id: I022b58109deedfbd6e57e6aa5159942081e6d8fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503941
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-27 08:58:12 -07:00
Brian Wilkerson aa67f94ba2 Fix a bug in unreachableFromMain
Closes https://github.com/dart-lang/sdk/issues/63425

Change-Id: I4bffe8413c56e4d71ae48284c6960085abf33d2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505482
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-05-21 12:49:20 -07:00
Brian Wilkerson a16de199d7 Convert many lint tests to use markdown
This is a rediculously large CL, and if you want me to split it up I'm
willing to do so.

However, the changes were all made by running a script I wrote and then
running the formatter over the code, so hopefully a spot-check will be
sufficient.

Change-Id: Ifc59b2cc3bf9e4edf0229a130cd587dc73f95615
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505042
Reviewed-by: Samuel Rawlins <srawlins@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-20 11:27:11 -07:00
Sam Rawlins dffae54f02 linter: Treat index assignment as setter in many lint rules
Work towards https://github.com/dart-lang/sdk/issues/62621

Change-Id: Ic8669042da9b159698849a627f84a050751ffdcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504000
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-18 19:44:41 -07:00
Sam Rawlins d12a4095a4 linter: flutter_style_todos: add test for multiple series of slashes
Fixes https://github.com/dart-lang/sdk/issues/59342

Change-Id: Ia633769c51131ca1cb258826cc6cddbebc85253f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503961
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2026-05-15 18:25:40 -07:00
Sam Rawlins 8f07aef955 linter: always_specify_types: add test with type parameter with bound
Fixes https://github.com/dart-lang/sdk/issues/57665

Change-Id: Idced0de7de239de8f46712dc8d48025caa88a7a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503621
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-15 11:36:25 -07:00
Konstantin Shcheglov 56706b715d Augment. Report incomplete augmented executable declarations.
Report new diagnostics when an introductory function, member, or factory
constructor is still incomplete after applying all augmentations.

Keep the existing missing-body diagnostics for declarations that have no
augmentations, but report augmentation-specific diagnostics when an
augmentation chain exists and none of the fragments provides a body or
factory redirection.

Move the checks into error verification so that extension and extension
type members can participate in augmentation completion before reporting
the existing abstract-member diagnostics. Also suppress the
corresponding shared parser diagnostic when it is reported by the
verifier.

Consolidate body-related tests by declaration shape instead of by
individual diagnostic. This keeps missing bodies, external bodies,
augmentation completion, and already-complete checks side by side,
making the interaction between these rules easier to review and extend.

Move the constructorAlreadyComplete coverage from its dedicated test
file into constructor_body_test.dart, and add the factory body
completeness cases there as well. Add executable_body_test.dart for
function and member body coverage, including top-level declarations,
static members, extension members, and extension type members.

Add diagnostic definitions and fix-status entries for the new
diagnostics.

Change-Id: I9ee803c1e767ff47a608c86413ef7ffc71518cfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503540
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-14 15:08:39 -07:00
Sam Rawlins 433b4fa3c8 analyzer: Consider "Immutable" annotations the same as "immutable"
Fixes https://github.com/dart-lang/sdk/issues/57670

Change-Id: I5a9ecd153c4e4de21e00860a7743f946096b0849
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503680
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-05-14 13:36:58 -07:00
Sam Rawlins 57da93ad4f linter: collection_methods_unrelated_type: Null not related to non-nullable
Fixes https://github.com/dart-lang/sdk/issues/57101

This change affects collection_methods_unrelated_type and
unrelated_type_equality_checks. For example these are now reported:

```dart
void f(Set<String> p1, int p2) {
  p1.contains(null);
  p2 == null;
}
```

Change-Id: Ib58bad2beb6b9df8fe7c71f27213055e9b8d5cb9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489481
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-13 07:03:42 -07:00
Sam Rawlins 9b1e09357b linter: Use an extension type's representation type when calculating unrelated types
Fixes https://github.com/dart-lang/sdk/issues/58838
Fixes https://github.com/dart-lang/sdk/issues/59373
Fixes https://github.com/dart-lang/sdk/issues/59299

The change is based entirely on runtime behavior. We just use the
"extension type erasure." So two instances of two extension types are
related if the representation types of those extension types are
related.

Change-Id: I3c40e072433608146f00194359c3c312b319c913
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503120
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-12 14:27:55 -07:00
Brian Wilkerson 2b1ed6614e Add a fix for use_declaring_parameters
This is another step toward being able to maximally convert a body of
code to using the primary_constructors features.

This CL does two things:

- Changes `convert_to_declaring_parameter` to also be a fix and applies
  that fix to the `use_declaring_parameters` lint.

- Updated the `use_declaring_parameters` lint to also flag field formal
  parameters.

Change-Id: I8b584186658abc73c025b166c145efbab95acd8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502740
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-12 11:56:25 -07:00
Brian Wilkerson 2fa07c6488 Lint fields initialized in the initializer list instead of the field initializer
This CL adds a lint as part of the collection of lints used to automate
converting code to use the features under the primary constructors flag.
The lint flags initializers in a primary constructor body that
initialize a field in such a way that the initialization could be done
in the field declaration's initializer.

It only flags assignments to fields where the right-hand side of the
assignment includes a reference to one or more of the constructor's
parameters. Expressions that don't reference a parameter would have
been valid to move before primary constructors, so flagging them
wouldn't help find bugs in the impementation of the feature.

If we were going to ship this lint, then we might want to extend it to
find initializers that don't reference parameters, whether they are in
the primary constructor body's initializer list or in the initializer
list of a secondary constructor.

This doesn't include a fix. Once again, I wanted to make sure the lint
was covering all the important cases before implementing the lint.

Change-Id: Id4b1e02ec160af50af8f4fe7b8c675213e41abc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502202
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-12 10:47:20 -07:00
Konstantin Shcheglov eae9edeb2e Augment. Fix pre-existing cases when already complete declaration is augmented with a complete declaration.
Change-Id: Ie2ff45ec5801dee2bfbc115719ba1a6f85f8cbe3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502187
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-12 07:42:33 -07:00
Konstantin Shcheglov d675a04fd1 Augment. Report augmentationModifierExtra and augmentationModifierMissing.
Report augmentationModifierExtra and augmentationModifierMissing when an
augmenting class or mixin does not use the same modifiers as the
introductory declaration.

Check class augmentations for abstract, base, final, interface, sealed,
and mixin modifiers. Check mixin augmentations for the base modifier.

Keep the explicit syntactic abstract modifier on class fragments
separate from the semantic abstract state in the class. This lets sealed
declarations continue to produce abstract class elements without making
their fragments appear to have an explicit abstract modifier, so
augmentation modifier checks can distinguish sealed from abstract
sealed.

Change-Id: I169e16c7b7363802d91882759550264f1c96f026
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502183
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-08 16:50:09 -07:00
Brian Wilkerson f7c06eb180 Add a new lint to find container bodies that could be a semicolon
The purpose of this lint is to be used with other lints to maximally
convert code to using the new features introduced by the primary
contructors feature. This one is targeted at finding container bodies
the could be replaced by a semicolon.

This CL does not include a fix. That will be added in a separate CL.

We will need to decide whether this lint is worth supporting beyond
the testing period.

Change-Id: I5d2d05117c9f1efc8c71279d5cde549eb48b480c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502182
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-08 13:55:19 -07:00
Brian Wilkerson bec664e1e8 Add a lint to convert normal parameters to declaring parameters
This is another lint intended primarily for testing. It is intended to
flag every non-declaring formal parameter in a primary constructor that
could be converted to be a declaring parameter.

There is an existing assist to convert a non-declaring parameter to a
declaring parameter, but I want to make sure that this lint is catching
all of the right conditions before enhancing it to be a fix.

Change-Id: I10f8a4980bbc77d35a920a221ef26957f96d22d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501580
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-05-07 13:58:35 -07:00
Brian Wilkerson 4d93f4d586 Lint all cases in which a primary contructor could be used
The purpose of this lint is to help automate testing of the primary
constructors feature. It is unlikely to be shipped in its current form.

The goal is to flag all cases where a secondary constructor could be
converted to a primary constructor. This includes classes with a default
constructor.

There is an assist that should convert most of these cases, but it has
not yet been enhanced to work as a fix. That will be done in a future
CL. I want to implement the lint first so that I know all of the
conditions that the fix needs to handle.

The most important part of this review is to ensure that the tests are
reasonably complete. If there are any missing cases where the lint
should flag a constructor for conversion, or any missing cases where a
conversion should not be requested, please let me know.

Change-Id: Ib8256677a0659479ab341974b87bd03c953ff644
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500583
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-07 13:46:54 -07:00
Brian Wilkerson 687a5cb840 Stop reporting unnecessary_const_in_enum_constructor for constructors outside an enum
Closes https://github.com/dart-lang/sdk/issues/63338

Change-Id: I7b613e22df0eb563076d85ac7f46a7c22a4cb2d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501561
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-07 12:53:18 -07:00
Kallen Tu 8bfb683892 Enable 'primary-constructors' feature flag.
This CL enables the primary constructors feature by default in Dart 3.13.

The primary constructors feature is a brevity feature. There are no new semantics, but it allows us to express declarations in a less verbose way.

This feature allows one constructor and a set of instance variables to be specified in the header of a declaration.

Currently a declaration with a constructor and some fields is written as:

```dart
// Current syntax.
class Point {
  int x;
  int y;
  Point(this.x, this.y);
}
```

With a primary constructor, we would write the above as:

```
class Point(var int x, var int y);
```

If a primary constructor needs an initializer list or a body, they can be
specified inside the class using the `this` body syntax:

```dart
class Point(var int x, var int y) {
  this : assert(x >= 0) {
    print('Point created at $x, $y');
  }
}
```

As part of this feature, you can also use the `new` and `factory` keywords to
declare constructors in the class body without repeating the class name:
```dart
class Point {
  int x, y;

  // Equivalent to Point(this.x, this.y)
  new(this.x, this.y);

  // Equivalent to Point.origin()
  new origin() : x = 0, y = 0;

  // Equivalent to factory Point.clone(Point other)
  factory clone(Point other) => Point(other.x, other.y);
}
```

To learn more about the feature, check out the feature specification located here: https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md

Tested: Has existing language, CFE, analyzer, analysis server tests.
Bug: https://github.com/dart-lang/sdk/issues/61524
Change-Id: I296f2fcd918b87bf2a1dd00256340759866c2423
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489241
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2026-05-04 15:09:49 -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
Srujan Gaddam 672877606d [linter] Erase types to non-nullable and type bounds correctly
We used thisType in invalid_runtime_check_with_js_interop_types
to ignore nullability and generics when comparing two types for
checks and casts. This is erroneous when doing a subtype check
because the distinct instantiated type arguments in each type
will lead to the two types not being subtypes of each other.

When JSExportedDartFunction and JSFunction became generic, this
became an issue because now JSFunction<T> is not a supertype of
JSExportedDartFunction<T>.

So, instead, we should always initialize the params to their
bounds when comparing types if we want to ignore generics.

Change-Id: I8418d3b87123a658fbe8a0a9379f43cba738f063
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498241
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-04-27 20:32:55 -07:00
FMorschel f891d8f664 [linter] Fixes simplify_variable_pattern for typedefs and type parameters
Fixes: https://github.com/dart-lang/sdk/issues/63207
Change-Id: I9e62450ce01c9e38a923af639602007afb81e7ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496540
Auto-Submit: FMorschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-25 08:27:44 -07:00
Sam Rawlins c45dc162f6 linter: avoid_print: Do not report use in comment references
Work towards https://github.com/dart-lang/sdk/issues/60511

Change-Id: I45ebd3986f9c26dde8492f983fc9e165f4b7f95c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498022
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-24 11:52:47 -07:00
Sam Rawlins 95613f5d07 linter: Report unnecessary_async for dynamic- and Object-returning functions
Fixes https://github.com/dart-lang/sdk/issues/60416

There was discussion about expanding the purview of this lint rule, and
`Object`- or `dynamic`-returning functions do not need their return
type changed, so the fix does not change that behavior.

Change-Id: I835732d6ab25dd85142f8763624eda2d9293e003
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497840
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-04-24 11:50:21 -07:00
Sam Rawlins dd24a9c82a linter: cascade_invocations: fix reporting in switch statements
Fixes https://github.com/dart-lang/sdk/issues/59556

Change-Id: Ic397c7d8186ac5ffde79c5823f97f2964476bb9d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497781
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-04-24 11:30:20 -07:00
Kallen Tu 77cf3047a3 Dot Shorthands: Const selector chains.
I changed the parsing of const dot shorthands to parse the entire selector chain in `parsePrecedenceExpression` rather than parsing them in `parseConstExpression`. We were originally parsing the initial expression before the `.` and only flagging that as a dot shorthand which prevented any chaining on const constructors. Const expressions with chained methods/property accesses were not being flagged as a dot shorthand so we weren’t saving the context type properly which led to producing the “unknown context type” error.

Before:
```
class C {
  const new someConstCtor();
  C method() => this;
}

C c = const .someConstCtor.method();
// (const .someConstCtor) is parsed and handled as a const constructor
// (const .someConstCtor) is handled as a dot shorthand, context is
// saved on only this AST and not the outer chain.
// Then we parse the rest of the selector chain (.method())
//
// Error: No context type for (const .someConstCtor.method())
```

After:
```
class C {
  const new someConstCtor();
  C method() => this;
}

C c = const .someConstCtor.method();
// (const .someConstCtor) is parsed and handled as a const constructor.
// Then we parse the rest of the selector chain (.method())
// (const .someConstCtor.method()) is handled as a dot shorthand, context is saved for this outer node.
//
// OK. No error because we are able to retrieve the type for the
// entire dot shorthand chain.
```

Fixes: https://github.com/dart-lang/sdk/issues/63119
Change-Id: I3308d8eb7ce101466be257aba6b5448921bff136
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2026-04-24 10:40:26 -07:00
Brian Wilkerson 463b751717 Add new unnecessary_type_name_in_constructor lint
This adds a new lint to recommend removing the type name from secondary
constructors.

It also adds a new fix that can automate the removal.

Change-Id: Ib6bc46b4455c360732553eadea3451d7dfb874a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497120
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-04-21 15:12:35 -07:00
Sam Rawlins 2f9d570cac linter: use_late_for_private_fields_and_variables: count field formals as nullable assignments
Fixes https://github.com/dart-lang/sdk/issues/63212

I added many test cases that are related and were missing, but the
primary test case for the bug is
`test_instanceField_private_withFieldFormalParameter`.

Change-Id: I3e8951f63801333373459bb1b191579b8e1f2188
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497101
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-21 14:42:01 -07:00
Sam Rawlins 6053e3a2b3 linter: Fix false positive with parameter_assignments and negate operator
Fixes https://github.com/dart-lang/sdk/issues/61169

The test case is weird. The issue is that `!p` was reported _only after_ `p = true;` is called. So it manifested as a double report. The test case leaves the `p = true;` statement.

The code is otherwise simplified.

Change-Id: I34b6e4ce0f90dc2ab6005e4fe400ca7d608184f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496440
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-21 14:12:28 -07:00
Sam Rawlins 352bcf5489 linter: Do not report interpolated type variable as const literal
Fixes https://github.com/dart-lang/sdk/issues/57916

`computeConstantValue` gives you an
`AttemptedConstantEvaluationResult?`. That result has a
`DartObject? value`, so we need both the result and the `value` to be
non-null, to count the expression as a valid constant.

Change-Id: I7938be808d30b9734344e98dd966bb111d974fbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497060
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-04-21 10:34:59 -07:00
Brian Wilkerson 78412eaeb8 Add new unnecessary_const_in_enum_constructor lint
This adds a new lint that was requested in order to support the primary
constructors feature.

This also enables the existing fix to remove the keyword and adds some
tests for the new use of the fix.

Change-Id: Iae3c86ca87a2af6abb82488e218d839a06699778
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496741
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-04-21 09:27:51 -07:00
Sam Rawlins 5a97aee690 linter: Do not report cascade_invocations when assignee may be referenced in invocations
Fixes https://github.com/dart-lang/sdk/issues/57631

Change-Id: I04bd435ecf2db42cd0d704c28a266fa2b2e085bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496480
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-20 11:38:38 -07:00
Sam Rawlins 47a4c9a0ae linter: Fix false positive in cascade_invocations wrt const instantiations
Fixes https://github.com/dart-lang/sdk/issues/61150

Change-Id: Ia3813d31e5e486c3cd8367179ba8adcc72102b31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496403
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-04-20 08:52:11 -07:00
Sam Rawlins 4776cc311c linter: fix unreachable_from_main for operators
Fixes https://github.com/dart-lang/sdk/issues/61891

Change-Id: I740a252fca989a7ab18b8f584beded37d9610609
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496460
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-04-20 07:46:21 -07:00
FMorschel 4b89db909e [linter] Fixes join pattern variable case in prefer_final_locals
Fixes: https://github.com/dart-lang/sdk/issues/61673
Change-Id: I6e82395e64725dbd1821d874ced89154d8aca23c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453101
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-19 09:53:37 -07:00
Konstantin Shcheglov 6cd3938741 Breaking changes for analyzer 13.0.0
https://github.com/dart-lang/sdk/issues/62799
https://github.com/dart-lang/sdk/issues/62944
https://github.com/dart-lang/sdk/issues/63002
https://github.com/dart-lang/sdk/issues/62970

Looks mostly green in google3: https://fusion2.corp.google.com/presubmit/901021300/OCL:901021300:BASE:901308428:1776439417713:37cd1695

Change-Id: I44754a48f66a0b58851d7c20fcfa61f7fb1b555a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488624
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-17 23:06:25 -07:00
Sam Rawlins 93f0b191b1 linter: Report more use_super_parameters cases where named can be converted
https://github.com/dart-lang/sdk/issues/58729

Change-Id: I257b89580fb31fcd21f9a33d3094dc3cb25063d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477583
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-17 12:45:29 -07:00