custom_lints_template is a developer tool, designed to help stop common issue and simplify repetetive tasks. It adds various warnings with quick fixes and refactoring options.
- Replace all usages of
custom_lints_templatewith your package name. - Rename custom_lints_template.dart to
<package-name>.dart. - Update pubspec.yaml with your package repository and issues links.
- Run
dart run build_runner build -dto generate the new dart_mappable classes. - Read the Contributing Guide.
- Delete this section from the README.
custom_lints_template is implemented using custom_lint. As such, it uses custom_lint's installation logic.
Long story short:
-
Add both
custom_lints_templateandcustom_lintto yourpubspec.yaml:dev_dependencies: custom_lint: custom_lints_template:
-
Enable
custom_lint's plugin in youranalysis_options.yaml:analyzer: plugins: - custom_lint
By default when installing custom_lints_template, 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 custom_lints_template.
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
- avoid_hardcoded_strings: falseNote 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
- avoid_hardcoded_strings
# Disable another
- custom_lint_example: falseInstead 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
- avoid_hardcoded_stringsSome of the lints have configuration options. These can be specified in analysis_options.yaml.
custom_lint:
rules:
- avoid_hardcoded_strings:
severity: infoCustom lint rules created by custom_lints_template 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 custom_lints_template), then you should be able to run:
dart run custom_lintAlternatively, 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
dart run custom_lintMost 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.
- Create a new file with the lint name in
lib/src/lints/{lint_name}/, typelintand use snippet to generate the boilerplate code. - Add the lint logic to the
OptionsLintRule.runmethod. - (Optional) Adding a fix for the lint
- Create a fix file in the
lib/src/lints/{lint_name}/models/fixes, typefixand use the snippet to generate the boilerplate code. - Add it to the lint's
OptionsLintRule.getFixesmethod.
- Create a fix file in the
- Add the lint to the lib/lints.dart
getAllLintsmethod. Typefixand use the lint to generate the boilerplate code. - (Optional) Adding configuration options. These options are available with the
config.parametersgetter in theOptionsLintRuleandOptionsFixclasses.- Create a new file for each key in
lib/src/lints/{lint_name}/models/, typeoptionsand use the snippet to generate the boilerplate code. - Add the new options class to the lint rule
paramsParserand the super classOptionsLintRulegeneric type parameter. - Run
dart run build_runner build -dto generate the new dart_mappable classes.
- Create a new file for each key in
- Update LINTS.md with the new lint and configuration options.
- Create a new file with the lint name in lib/src/assists,
type
assistand use snippet to generate the boilerplate code. - Add the assist to the lib/custom_lints_template.dart
getAllAssistsmethod.
Follow the custom_lint debugging/testing docs.