dart-sdk/pkg/linter
Ilya Yanok cbdae14d2f Revert "linter: Refactor prefer_collection_literals to use context type more"
This reverts commit cd8a3370e7.

Reason for revert: lint starts barking at the wrong tree: b/298917960

Original change's description:
> linter: Refactor prefer_collection_literals to use context type more
>
> There is a basic premise in this rule which we cannot satisfy exactly:
> we need to disallow `LinkedHashSet()` unless the context type requires
> the developer to use `LinkedHashSet`. But the context type is long
> gone when the lint rule is run.
>
> This CL adds some logic to try to attempt figuring out the context
> type in the cases where users have filed bugs, but it will never be
> super accurate.
>
> Fixes https://github.com/dart-lang/linter/issues/4736
> Fixes https://github.com/dart-lang/linter/issues/3057
> Fixes https://github.com/dart-lang/linter/issues/1649
> Fixes https://github.com/dart-lang/linter/issues/2795
>
> Change-Id: I3e6c6de81084dca2825488c89830ab3e7ea63186
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323680
> Reviewed-by: Phil Quitslund <pquitslund@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Commit-Queue: Samuel Rawlins <srawlins@google.com>

Change-Id: I980053dd51ffd4447721e0ad7436b07ca704b554
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324021
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-09-04 10:43:54 +00:00
..
bin
doc
example
lib/src Revert "linter: Refactor prefer_collection_literals to use context type more" 2023-09-04 10:43:54 +00:00
test Revert "linter: Refactor prefer_collection_literals to use context type more" 2023-09-04 10:43:54 +00:00
test_data Revert "linter: Refactor prefer_collection_literals to use context type more" 2023-09-04 10:43:54 +00:00
tool Revert "linter: Refactor prefer_collection_literals to use context type more" 2023-09-04 10:43:54 +00:00
analysis_options.yaml
AUTHORS
CHANGELOG.md [linter] Account for new lints in 3.1.0 release 2023-08-23 20:36:05 +00:00
CONTRIBUTING.md README and contributing process updates 2023-08-23 22:09:24 +00:00
LICENSE
OWNERS Add analyzer team as owners of pkg/linter 2023-08-23 20:05:49 +00:00
pubspec.yaml Enable language 3.2 for analysis_server/ and linter/. 2023-08-31 17:38:39 +00:00
README.md README and contributing process updates 2023-08-23 22:09:24 +00:00

Linter for Dart

The Dart Linter package defines lint rules that identify and report on "lints" found in Dart code. Linting is performed by the Dart analysis server and the dart analyze command in the Dart command-line tool.

Installing

The linter is bundled with the Dart SDK; if you have an updated Dart SDK already, you're done!

Usage

The linter gives you feedback to help you catch potential errors and keep your code in line with the published Dart Style Guide. Enforceable lint rules (or "lints") are cataloged here and can be configured via an analysis options file. The linter is run from within the dart analyze command-line tool shipped with the Dart SDK. Assuming you have lints configured in an analysis_options.yaml file at the root of your project with these contents:

linter:
  rules:
    - annotate_overrides
    - hash_and_equals
    - prefer_is_not_empty

you could lint your package like this:

$ dart analyze .

and see any violations of the annotate_overrides, hash_and_equals, and prefer_is_not_empty rules in the console. To help you choose the rules you want to enable for your package, we have provided a complete list of rules with lints recommended by the Dart team collected in package:lints. Lints recommended for Flutter apps, packages, and plugins are documented in package:flutter_lints.

If a specific lint warning should be ignored, it can be flagged with a comment. For example,

   // ignore: camel_case_types
   class whyOhWhy { }

tells the Dart analyzer to ignore this instance of the camel_case_types warning.

End-of-line comments are supported as well. The following communicates the same thing:

   class whyOhWhy { // ignore: camel_case_types

To ignore a rule for an entire file, use the ignore_for_file comment flag. For example,

// ignore_for_file: camel_case_types

...

class whyOhWhy { }

tells the Dart analyzer to ignore all occurrences of the camel_case_types warning in this file.

As lints are treated the same as errors and warnings by the analyzer, their severity can similarly be configured in an options file. For example, an analysis options file that specifies

linter:
  rules:
    - camel_case_types
analyzer:
  errors:
    camel_case_types: error

tells the analyzer to treat camel_case_types lints as errors. For more on configuring analysis see the analysis option file docs.

Contributing

Feedback is greatly appreciated and contributions are welcome! Please read the contribution guidelines; mechanics of writing lints are covered here.

Features and bugs

Please file feature requests and bugs in the issue tracker.