What is Lint?
Lint is the computer science term for a static code analysis tool used to flag programming errors, bugs, stylistic errors and suspicious constructs.
The linter checks your source code against a list of rules and warnings about issues that might lead to problems (potential errors, deviations from recommended coding practices, code that might be hard to read or maintain), and ensures adherence to these rules.
Setting Up Lints
- New Projects: For Newer Flutter projects (Flutter version 2.3.0) typically come with the
flutter_lints
package pre-configured. - Existing Projects: For older projects, add the
flutter_lints
package as a dev dependency in yourpubspec.yaml
file:
https://pub.dev/packages/flutter_lints
YAML
dev_dependencies:
flutter_lints: ^3.0.1
- Run
flutter pub get
to download the package.
Enabling Lints:
- Flutter analyzes your code by default, and you can see lint warnings in your IDE.
- To run lints manually, use the command:
Bash
flutter analyze
Customizing Lints
By default,
flutter_lints
activates a set of recommended lints.You can further customize the lints using the
analysis_options.yaml
file:- Create this file in your project’s root directory if it doesn’t exist.
- Include the
flutter_lints
configuration:
YAMLinclude: package:flutter_lints/flutter.yaml
Optional: To enable or disable specific lints, add them under the linter section:
YAML
linter:
# Enable a specific rule (previously disabled)
rules:
avoid_return_types_on_setters: true
# Disable a specific rule (previously enabled)
rules:
unnecessary_brace_closure: false
Visit my youtube channel