- Notifications
You must be signed in to change notification settings - Fork166
dart-archive/linter
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The Dart linter is now developed within theDart SDK repository,and can be found athttps://github.com/dart-lang/sdk/tree/main/pkg/linter.
To contribute changes, check out theSDK contribution guide.
The Dart Linter package defines lint rules that identify and report on "lints" found in Dart code. Linting is performed by the Dartanalysis server and thedart analyze
command in theDart command-line tool.
The linter is bundled with the DartSDK; if you have an updated Dart SDK already, you're done!
Alternatively, if you want to contribute to the linter or examine the source, clone thelinter
repo like this:
$ git clone https://github.com/dart-lang/linter.git
The linter gives you feedback to help you catch potential errors and keep your code in line with the publishedDart Style Guide. Enforceable lint rules (or "lints") are catalogedhere and can be configured via ananalysis options file. The linter is run from within thedart analyze
command-line tool shipped with theDart SDK. Assuming you have lints configured in ananalysis_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 theannotate_overrides
,hash_and_equals
, andprefer_is_not_empty
rules in the console.To help you choose the rules you want to enable for your package, we have provided acomplete list of ruleswith lints recommended by the Dart team collected inpackage:lints
. Lints recommended for Flutter apps, packages,and plugins are documented inpackage:flutter_lints
.
If a specific lint warning should be ignored, it can be flagged with a comment. For example,
// ignore: camel_case_typesclass whyOhWhy { }
tells the Dart analyzer to ignore this instance of thecamel_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 theignore_for_file
comment flag. For example,
// ignore_for_file: camel_case_types...class whyOhWhy { }
tells the Dart analyzer to ignore all occurrences of thecamel_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. Forexample, an analysis options file that specifies
linter:rules: -camel_case_typesanalyzer:errors:camel_case_types:error
tells the analyzer to treatcamel_case_types
lints as errors. For more on configuring analysis see the analysis option filedocs.
Feedback is greatly appreciated and contributions are welcome! Please read thecontribution guidelines; mechanics of writing lints are coveredhere.
Please file feature requests and bugs in theissue tracker.
About
Linter for Dart.