Commit Graph

136 Commits

Author SHA1 Message Date
Parker Lougheed 3e2ac6721d [linter] Report deprecated_consistency only on constructor name
Before this fix the lint was being reported on the entire constructor definition.

Also moves all tests to be reflective.

Change-Id: I8e32600cd87a7f34f8e8aa701acf180c741b915a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-12-18 18:02:42 +00:00
Parker Lougheed 89381ea4db [linter] Simplify 'prefer_mixin' implementation
The allow-listed classes have all been migrated to be typedefs to mixin classes.

Keeps the tests for them there to ensure this is the case.

Change-Id: I322707fc6d6ff61a98f43824b5ca70f197064b22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342301
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-18 18:00:42 +00:00
pq b7aa9106a8 cleanup unneeded strictCast tracking
Follow-up from: https://dart-review.googlesource.com/c/sdk/+/341336

Change-Id: I09a142b00f10e44793b70b10b08920e1245770b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342088
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-12-15 20:29:48 +00:00
pq 40e5e46a54 migrate strict{Casts,Inference} from typeSystem
Another angle on removing tracking of `strictCasts` and `strictInference` from the type system, this time threading these configuration values individually to the functions that need them. (In contrast to the solution in https://dart-review.googlesource.com/c/sdk/+/341326).

See: https://github.com/dart-lang/sdk/issues/53873.

Change-Id: I63d73fd81401ac03121831af5e8d4ca43200bb7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341336
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-15 19:45:09 +00:00
Sam Rawlins 7320da0d19 linter: Add a PRESUBMIT check for example/all.yaml
Work towards https://github.com/dart-lang/sdk/issues/53578

Change-Id: Ia07d999abc2fcf4b8195c9f7688799bc099a1d88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341385
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-12-15 04:04:28 +00:00
Sam Rawlins e1bec8d7d6 linter: prefer_collection_literals; fix reports in ctor initializers, conditionals
Change-Id: Ie56201b717b3af482b22f8449b4eb9ae1a329669
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341394
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2023-12-14 22:05:40 +00:00
Sam Rawlins a2151474a5 linter: UBCS: require checking the correct 'mounted' property
Fixes https://github.com/dart-lang/linter/issues/4777

Change-Id: I0c50ab1a04b8f9c704a0cf787fcf414688cd61a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330561
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-12-12 01:34:11 +00:00
Brian Wilkerson 9b26f56309 Register a deprecated lint
Change-Id: Ic42c145df751386134caf4067e537198f8631056
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340582
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-08 19:28:22 +00:00
Brian Wilkerson a155e2b521 Remove the avoid_unstable_final_fields lint
Change-Id: I6835df32fc6c0d9a5f17b3b5344353ec061147d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340386
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-12-08 15:50:09 +00:00
Brian Wilkerson 8356cfeb8f Deprecate avoid_unstable_final_fields
Change-Id: I1d47dfcef9d910875833823aaf304f2945bb3254
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340285
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-12-07 21:55:18 +00:00
Parker Lougheed 844fd8deb0 [linter] Don't trigger avoid_classes_with_only_static_members on sealed classes
If someone is declaring a sealed class with subclasses, it's likely meant for exhaustiveness, and it should be okay to have just static members.

Change-Id: I4938794c3095ca295495ec6f421f8e6e3d3935ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340140
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-07 20:07:12 +00:00
Parker Lougheed 790657f1da [linter] Report public_member_api_docs on just constructor names or types
Without this change, the lint triggers on the entire definition, including the body. That makes it hard to visually identify the target of the lint.

Change-Id: I0071f56f68e73fdfbad28cfa74d71ea3979d7a2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340142
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-06 20:50:16 +00:00
Paul Berry a25eb56b70 Allow linter unit tests to be run from any directory.
I frequently run unit tests from the root directory of the SDK
package. Previous to this CL, that didn't work for the `linter`
package, because the test `validate_sdk_version_map.dart` contained a
hard-coded path that only worked if the test was invoked from the
`pkg/linter` subdirectory.

With this change, the test uses the `packageRoot` getter from the
`analyzer_utilities` package, which locates the SDK's `pkg` directory
using heuristics that work from a variety of different starting
directories, including the root of the SDK repo, anywhere within
`pkg/linter`, and in a Google3 bazel test.

Change-Id: I525ad21cb5228e670dadc98c05de18bddf3912e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339660
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-12-04 22:39:37 +00:00
Sam Rawlins eafce6ee6b linter: Remove unused integration test_data directory
Change-Id: Ib28387f88f3b74d3b5283513fb4995cafe4e6e16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339642
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2023-12-04 22:15:09 +00:00
Paul Berry 428cdffbc0 Linter: fix unnecessary_parenthesis handling of (a?[b]) : c
There are two possible meanings of `?` when it follows an expression:
it could introduce a null-aware index operation (`a?[b]`), or it could
introduce a conditional expression (`a?b:c`). The parser always favors
the second interpretation (see
https://github.com/dart-lang/language/blob/main/accepted/2.12/nnbd/feature-specification.md#null-aware-subscript).

Therefore, if the user wants to use a null-aware index operation in a
context where it is followed by a `:` and then another expression,
parentheses are required around the null-aware index operation, to
prevent the token sequence from being interpreted as a conditional
expression.

This can happen in two circumstances:

- In the "then" part of a conditional expression: `a ? (b?[c]) : d`

- In a map literal key: `{(a?[b]): c}`

The `unnecessary_parenthesis` lint already has a number of exceptions
to handle weirdnesses of the parser; we just need to add one more.

Fixes https://github.com/dart-lang/linter/issues/4812.

Bug: https://github.com/dart-lang/linter/issues/4812
Change-Id: I265103e257d45bfd228972aebba595097b429522
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339480
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-04 17:48:38 +00:00
Parker Lougheed 80ad96837c [linter] Add field and super parameter tests for comment_references lint
The core issue was solved in https://github.com/dart-lang/sdk/commit/c8b18439d48a3acd7a8c73b6539265708f4417dc.
This CL adds tests to verify the linter correctly finds the associated static elements and doesn't report a comment_references lint.

Closes https://github.com/dart-lang/linter/issues/3563

Bug: https://github.com/dart-lang/linter/issues/3563
Change-Id: Icf281faf1934b135b51e98271be461b527b83a14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339061
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-12-02 22:43:35 +00:00
Sam Rawlins 030fe115e2 linter: Allow dynamic calls on explicit dynamic- or Function-casts
Fixes https://github.com/dart-lang/linter/issues/4806

Change-Id: I6c900f9aa3d7c2cf8dc3547bfe035eab820e750b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339101
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-11-30 22:40:18 +00:00
Paul Berry a19ae4ee68 Enable the extension types language feature.
This language feature allows the user to declare a static type using
`extension type` syntax, for example:

    extension type IdNumber(int i) {
      operator <(IdNumber other) => i < other.i;
      bool isValid(Some parameters) => ...;
    }

This behaves similarly to a "wrapper" class:

    class IdNumber {
      final int i;
      IdNumber(this.i);
      operator <(IdNumber other) => i < other.i;
      bool isValid(Some parameters) => ...;
    }

However, at runtime, no wrapper objects are created; instead, an
instance of the extension type is represented directly by its
"representation type" (`int` in the above example), and methods like
`isValid` are resolved statically. This gives developers an
abstraction mechanism with the advantage of zero runtime performance
cost, since no extra heap space is required, and no extra instructions
are needed to convert between an extension type and its underlying
representation.

The disadvantage of using extension types as an abstraction mechanism
is that since no wrapper objects are created at runtime, the
abstraction can be bypassed using `dynamic`, runtime casts, or by
"laundering" the object through contravariant generic methods like
`List.add` (which are runtime checked in Dart). For example:

    main() {
      var id = IdNumber(1);
      var list1 = <int>[];
      List<Object> list2 = list1;
      list2.add(id); // OK at compile time because `IdNumber` is a
                     // subtype of `Object`. OK at runtime because
		     // at runtime, `IdNumber` and `int` are
		     // indistinguishable.
      int i = list1[0];
      print(i);
    }

Extension types are expected to be particularly useful for
low-overhead decoding of external data formats (such as JSON), and for
inter-operation with other languages (such as Javascript).

For additional information see the feature specification:
https://github.com/dart-lang/language/blob/main/accepted/future-releases/extension-types/feature-specification.md

Change-Id: I900a3a25dcfc38bfa9c9f9b5b9fa20f362883653
Tested: Standard trybots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335062
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-11-21 19:14:49 +00:00
Sam Rawlins dd6c961bf0 Remove all pre-NNBD support in the linter code
In this CL we "remove" 3 linter rules, and any subsequently unused quick fixes:

* `always_require_non_null_named_parameters`
* `avoid_returning_null`
* `avoid_returning_null_for_future`

We also delete any code that branched on pre-NNBD libraries; these are
no longer supported.

Change-Id: I3bad7a44de3563e5737919c878170213ad506b82
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336244
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-11-21 18:55:01 +00:00
pq 07c77f59a2 Final todo updated format fixes
This should tidy up the last ones. 🤞

Sorry for the noise!

Change-Id: I7104fc33282184acb0c843eae6e73f6fcc77d892
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336723
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-11-16 20:18:32 +00:00
pq bec6e82853 migration to driver.getAnalysisOptionsForFile (continued)
Change-Id: Ia22286786febe7e915df0d7e7b18b9657fef2b07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335063
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-11-14 22:41:28 +00:00
Devon Carew 6917656134 [pkg] remove duplicate config from the analysis options files
Change-Id: I149a97bbe260600a3de664b28c4d212dd9adb889
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335862
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2023-11-14 00:37:53 +00:00
Parker Lougheed 11762189a1 [linter] Fix avoid_unstable_final_fields release version
Fixes https://github.com/dart-lang/sdk/issues/53852

Change-Id: I957373bfd9f04014a3e307f54b7e3f8e27b88564
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331340
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-11-12 19:18:03 +00:00
pq 63118a139d handle more flutter_style_todos cases
Change-Id: Iadf85cc56193c16c041097ca33a2a819a204bc37
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335381
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-11-11 05:23:25 +00:00
Sam Rawlins f2a001d2fd Reland: Improve file structure of linter files.
There is much code in pkg/analyzer/lib/src/lint which is only used by
_tests_ and _tools_ in the linter package. This CL attempts to tidy up
the separation of linter lib code and non-lib code by moving some
files, and moving some source elements, which are only used in tests,
or in tools.

I originally dug into this because I saw `LinterOptions` has a public late field
(dangerous):

`late file_system.ResourceProvider resourceProvider;`

It turns out this field is only initialized in tests and tools, and
then it's read by multiple methods, and it just so happens those
methods are only called during tests or in tools.

Summary of changes:

* Mark LintDriver and DartLinter classes as only used for linter tools
  and tests.
* Remove CamelCaseString class.
* Mark `DartLinter.lintPubspecSource` as `@visibleForTesting`.
* LinterOptions: mark `enabledLints` and `analysisOptions` final, and remove
  `resourceProvider`.
* Remove SourceLinter; it was only used in a few `engine_test.dart` tests in
  linter, but all uses could be replaced with DartLinter.
* Remove linter's `bin/linter.dart`; it is not meant to be used as any sort of
  user entrypoint. The main method is moved to `cli.dart`.
* Move linter's `lib/src/cli.dart` to `tool/cli.dart`.
* analyzer's top-level function `lintFiles`, classes ErrorWatchingSink
  and FileGlobFilter are moved to linter's tool/ directory.
* Delete the engine_test.dart tests which only validate basics of
  linter's old entrypoint.

This reverts commit d1bc88de8f.

Change-Id: I1063aa72c640ad8ab62f76bf89f665cb8b9952dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334645
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-11-10 21:25:11 +00:00
Parker Lougheed 4830c96420 [linter] Add changelog entries for removed unrelated type lints
Change-Id: Ia55b403ef35e6ee252d36c9a86f797e0e39de1f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335540
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-11-10 19:06:42 +00:00
pq 4dcdfc57d6 enable flutter_style_todos
(The bulk of these fixes where auto-applied by `dart fix`)

Change-Id: I5476294ca63ee6584ee07af1ae448db7ba07760e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335324
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-11-09 22:01:47 +00:00
Sam Rawlins 7629e1e669 Modernize LinterContext APIs
Deprecate `LinterContext.analysisOptions` and
`LinterContext.declaredVariables`; these are unused anywhere in the
Dart SDK. I suppose they could be used in an analyzer plugin if there
is a supported way that an analyzer plugin can get access to a
LinterContext?

Deprecate `LinterContext.resolveNameInScope`, replaced by
`LinterContext.resolveNameInScope2`, with a named bool parameter. See
https://dart.dev/effective-dart/design#avoid-positional-boolean-parameters.

Use third-person verbs in doc comments. See
https://dart.dev/effective-dart/documentation#prefer-starting-function-or-method-comments-with-third-person-verbs

Change-Id: Ifb9a02f9f4399b88e67b55c0c1bbc1491f501999
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334082
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-11-09 18:25:02 +00:00
pq 2cce183a71 quick fix for flutter_style_todos
Handles:

* missing space before `TODO`
* missing colon
* lower case `todo`



Change-Id: Ib0e00e992d42c4d29fee87679c45dae10448653d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335024
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-11-09 18:08:21 +00:00
Sam Rawlins 93541c708c linter: Remove two deprecated linter rules
Fixes https://github.com/dart-lang/linter/issues/4800

Change-Id: I4eef17ca19ea7469fba372c28eef7618249c48dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334080
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-11-09 17:03:15 +00:00
Oleh Prypin d1bc88de8f Revert "Improve file structure of linter files."
This reverts commit 31eab937f6.

Reason for revert: No way to import "tool/formatter.dart" in g3

Original change's description:
> Improve file structure of linter files.
>
> There is much code in pkg/analyzer/lib/src/lint which is only used by
> _tests_ and _tools_ in the linter package. This CL attempts to tidy up
> the separation of linter lib code and non-lib code by moving some
> files, and moving some source elements, which are only used in tests,
> or in tools.
>
> I originally dug into this because I saw `LinterOptions` has a public late field (dangerous):
>
> `late file_system.ResourceProvider resourceProvider;`
>
> It turns out this field is only initialized in tests and tools, and
> then it's read by multiple methods, and it just so happens those
> methods are only called during tests or in tools.
>
> Summary of changes:
>
> * Mark LintDriver and DartLinter classes as only used for linter tools
>   and tests.
> * Remove CamelCaseString class.
> * Mark `DartLinter.lintPubspecSource` as `@visibleForTesting`.
> * LinterOptions: mark `enabledLints` and `analysisOptions` final, and remove `resourceProvider`.
> * Remove SourceLinter; it was only used in a few `engine_test.dart` tests in linter, but all uses could be replaced with DartLinter.
> * Remove linter's `bin/linter.dart`; it is not meant to be used as any sort of user entrypoint. The main method is moved to `cli.dart`.
> * Move linter's `lib/src/cli.dart` to `tool/cli.dart`.
> * analyzer's top-level function `lintFiles`, classes ErrorWatchingSink
>   and FileGlobFilter are moved to linter's tool/ directory.
> * Delete engine_test.dart tests which only validate basics of
>   linter's old entrypoint.
>
> Change-Id: Ifc0e70454ee2ac794bc816ef9c77d5519a93eb0a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333128
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>

Bug: b/309643288
Change-Id: I69a731ff31507f671277d0395f4ebfbb86d8f607
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334660
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Oleh Prypin <oprypin@google.com>
2023-11-07 19:30:53 +00:00
Sam Rawlins 31eab937f6 Improve file structure of linter files.
There is much code in pkg/analyzer/lib/src/lint which is only used by
_tests_ and _tools_ in the linter package. This CL attempts to tidy up
the separation of linter lib code and non-lib code by moving some
files, and moving some source elements, which are only used in tests,
or in tools.

I originally dug into this because I saw `LinterOptions` has a public late field (dangerous):

`late file_system.ResourceProvider resourceProvider;`

It turns out this field is only initialized in tests and tools, and
then it's read by multiple methods, and it just so happens those
methods are only called during tests or in tools.

Summary of changes:

* Mark LintDriver and DartLinter classes as only used for linter tools
  and tests.
* Remove CamelCaseString class.
* Mark `DartLinter.lintPubspecSource` as `@visibleForTesting`.
* LinterOptions: mark `enabledLints` and `analysisOptions` final, and remove `resourceProvider`.
* Remove SourceLinter; it was only used in a few `engine_test.dart` tests in linter, but all uses could be replaced with DartLinter.
* Remove linter's `bin/linter.dart`; it is not meant to be used as any sort of user entrypoint. The main method is moved to `cli.dart`.
* Move linter's `lib/src/cli.dart` to `tool/cli.dart`.
* analyzer's top-level function `lintFiles`, classes ErrorWatchingSink
  and FileGlobFilter are moved to linter's tool/ directory.
* Delete engine_test.dart tests which only validate basics of
  linter's old entrypoint.

Change-Id: Ifc0e70454ee2ac794bc816ef9c77d5519a93eb0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333128
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-11-07 16:47:21 +00:00
Sam Rawlins 5f24a631c7 linter: Add first three 'known limitation' texts to docs
Change-Id: Id6f1c95614e7de039866da40659ab7de7928faee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-11-02 16:22:01 +00:00
Sam Rawlins 716b127a1a linter: ubcs: account for when clauses in if-like nodes
Fixes https://github.com/dart-lang/linter/issues/4795

Change-Id: I4cce15ddaf8a669921646fa81dd0e455859e46e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332361
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-26 19:56:58 +00:00
pq d239b906e9 rule generation codegen tweaks
* removes stale generated TODO
* fixes test prefixing in the all tests test for cases where tests include `_test`
* adds a file ignore for test prefixes for the all tests test

Change-Id: Ie400e275300683b8f037bb6dae62aa85a3469cff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331201
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-19 16:42:25 +00:00
pq 2ae5b4f9eb add (internal) erase_dart_type_extension_types stub
Very much a WIP but hopefully provides enough scaffolding for some dev_compiler experimentation.



Change-Id: Ic0cfe3c30b189732ee10209ff8b4b6a88ef0d37d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330995
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-19 16:10:19 +00:00
pq d79fd1a269 remove inTestMode declaration
Change-Id: I7fa08195db75120df4377c7529d52ba47ff3dcbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331090
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-10-19 14:48:13 +00:00
pq a6674f7b7c remove stale test mode codegen support
Change-Id: Ie3d103404e64139caa9eb2f15a4688fc94ab8e49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331085
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-10-18 17:43:05 +00:00
pq 5b7f451360 avoid_type_to_string extension type tests
Fixes: https://github.com/dart-lang/linter/issues/4783

Change-Id: I1477048ea933cdc7f11706a9caab3f0769d66f86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331082
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-18 16:34:34 +00:00
pq 9266dd12ed add an "internal" rule state
Change-Id: I740d95c179005b820dab01b4cd0cd7b0976f288b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-18 16:27:22 +00:00
Sam Rawlins 20dae1a3f6 linter: catch fields referenced in a pattern field
Fixes https://github.com/dart-lang/sdk/issues/53674

Change-Id: I87effd3cc4b3d3227cd26c3fdeb68b7f7e2d0ca9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330880
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2023-10-17 19:54:48 +00:00
Sam Rawlins 06ab207091 linter: Move many unnecessary_statements tests
Not all of them; there are too many for one change.

Change-Id: I59f6a52c03ccbc4f5f81567b0f70c32fcf4b1f2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329569
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-10-13 03:51:23 +00:00
Sam Rawlins 7341ad214e Document unreachable_from_main for instance members
Change-Id: I37ea317ad0e1fc18d509e706a3cbc355f04005be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330380
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-13 03:39:23 +00:00
pq 532e4674c6 extension type support for prefer_const_constructors_in_immutables
Fixes: https://github.com/dart-lang/linter/issues/4720

Change-Id: Ia55289f53b6191e8511664cfa5b05ebcfe42ed6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330180
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-12 17:41:12 +00:00
pq 3f3def4654 verify prefer_asserts_in_initializer_lists for extension types
As it happens, `prefer_asserts_in_initializer_lists` works out of the box for constructors in extension types. (Yay!) This just adds a few tests for coverage.

Fixes: https://github.com/dart-lang/linter/issues/4779

Change-Id: I1f5ffbbc968b37723b5e6894227c154563b2803c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330031
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-12 16:01:28 +00:00
Erik Ernst cdc16e7d3d Create lint PR 3578 as Gerrit CL
This CL transfers the changes made by
https://github.com/dart-lang/linter/pull/3578
to Gerrit.

Change-Id: Ib1eae56d2112e25bcf9916abf27b05bd3de15735
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326342
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-12 10:09:10 +00:00
pq 0493c44a87 cleanup @immutable element checks
Having added a `hasImmutable` property in https://dart-review.googlesource.com/c/sdk/+/330048, we can do a bit of tidying up. 🎉

Change-Id: I2878a829aed1001dec90bc43859a547e8c0df3a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330049
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-12 00:52:28 +00:00
pq d9731acfda fix prefer_void_to_null false positive on extension type representations
Fixes: https://github.com/dart-lang/linter/issues/4720

Change-Id: Ie3a736cbd4d190135eb77932ec8ba9352683226e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-10-11 19:04:08 +00:00
Sam Rawlins ac7059a832 Support extension types in unreachable_from_main
Work towards https://github.com/dart-lang/linter/issues/3625

Change-Id: I41a28795f16eb19b41f864ef512cf10936c2e11f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327713
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-10-11 01:11:28 +00:00
Parker Lougheed 07bb4d1f82 [linter] Don't mark linter rule files as executable
As far as I can tell, these shouldn't be marked executable. The rest of the rules are not.

Change-Id: Iefcf85488f04cf44b2616f8cc5c98f99fd54c35c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329863
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-10 20:59:11 +00:00