navi_light
is a developer tool, designed to help stop common issues and simplify repetitive tasks. It adds various warnings with quick fixes and refactoring options.
navi_light
is implemented using custom_lint. As such, it uses custom_lint
's installation logic.
Long story short:
-
Add both
navi_light
andcustom_lint
to yourpubspec.yaml
:dev_dependencies: custom_lint: navi_light:
-
Enable
custom_lint
's plugin in youranalysis_options.yaml
:analyzer: plugins: - custom_lint
By default when installing navi_light
, most of the lints will be enabled.
To change this, you have a few options.
You may dislike one of the various lint rules offered by navi_light
.
In that event, you can explicitly disable this lint rule for your project
by modifying the analysis_options.yaml
analyzer:
plugins:
- custom_lint
custom_lint:
rules:
# Explicitly disable one lint rule
- lines_longer_than_maximum_chars: false
Note that you can both enable and disable lint rules at once.
This can be useful if your analysis_options.yaml
includes another one:
include: path/to/another/analysis_options.yaml
analyzer:
plugins:
- custom_lint
custom_lint:
rules:
# Enable one rule
- lines_longer_than_maximum_chars
# Disable another
- prefer_named_parameters: false
Instead of having all lints on by default and manually disabling lints of your choice,
you can switch to the opposite logic:
Have lints off by default, and manually enable lints.
This can be done in your analysis_options.yaml
with the following:
analyzer:
plugins:
- custom_lint
custom_lint:
# Forcibly disable lint rules by default
enable_all_lint_rules: false
rules:
# You can now enable one specific rule in the "rules" list
- prefer_named_parameters
Some of the lints have configurations. These can be specified in the analysis_options.yaml
or the pubspec.yaml
file under the top level key navi_light:
.
All lints have the following options:
severity
: This can be set tonone
,info
,warning
orerror
.include
: Only lint files matching these regular expressions.exclude
: Skip linting files matching these regular expressions.
navi_light:
rules_exclude:
- "test/.*\\.dart"
rules:
lines_longer_than_maximum_chars:
maximum_chars: 100
severity: info
include:
- "lib/.*\\.dart"
exclude:
- "lib/.*_temp\\.dart"
prefer_named_parameters:
threshold: 2
severity: warning
incorrect_todo_comment:
severity: error
Custom lint rules created by navi_light may not show-up in dart analyze
.
To fix this, you can run a custom command line: custom_lint
.
Since your project should already have custom_lint installed (cf installing navi_light), then you should be able to run:
dart run custom_lint
Alternatively, you can globally install custom_lint
:
# Install custom_lint for all projects
dart pub global activate custom_lint
# run custom_lint's command line in a project
custom_lint
Most lints have configuration options. These can be specified in the analysis_options.yaml
or the pubspec.yaml
.
See LINTS.md for a list of implemented lint rules and their configuration options.