awesome_lints 2.2.0
awesome_lints: ^2.2.0 copied to clipboard
Comprehensive custom lint rules for Dart and Flutter.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
2.2.0 - 2025-12-24 #
Bug Fixes #
- dispose_fields: Now correctly skips externally-owned resources (e.g., resources provided via constructor parameters that should not be disposed by the class)
- avoid_collection_equality_checks: Now properly skips null comparison checks (
== nullor!= null) - TypeCompatibilityChecker: Improved to support subtype relationship checks for more accurate type analysis
- newline_before_ rules*: Auto-fixes now correctly preserve code indentation
- Test fixtures: Corrected Provider API usage in
dispose_fieldstest cases
Documentation #
- COMMON_LINTS.md: Added comprehensive code examples for additional rules, improving developer guidance
- README.md: Added new "Enabling Individual Rules" section with clear examples of three approaches for configuring rules
Maintenance #
- Removed unused test files
- Code formatting improvements
2.1.0 - 2025-12-22 #
BREAKING CHANGES #
Rules are now disabled by default (opt-in model)
Previous versions (v2.0.0 and earlier) enabled all 128 rules automatically. Starting with v2.1.0, rules must be explicitly enabled or configured via presets.
Migration Required:
To maintain v2.0.0 behavior (all rules enabled):
# analysis_options.yaml
include: package:awesome_lints/presets/strict.yaml
To adopt the recommended preset (recommended for most projects):
# analysis_options.yaml
include: package:awesome_lints/presets/recommended.yaml
For gradual adoption (core essential rules only):
# analysis_options.yaml
include: package:awesome_lints/presets/core.yaml
See Migration Guide for detailed instructions.
Features #
New Preset Configurations:
-
core.yaml- Essential rules only (~15 rules)- Critical bug prevention
- Null safety issues
- Flutter lifecycle errors
- Recommended for new projects
-
recommended.yaml- Balanced rule set (~40 rules)- Includes all core rules
- Code quality improvements
- Common mistake prevention
- Recommended for most projects
-
strict.yaml- All rules enabled (128 rules)- Maintains v2.0.0 behavior
- Comprehensive analysis
- Recommended for very strict projects
-
Category-specific presets:
flutter.yaml- All 32 Flutter rulescommon.yaml- All 65 common Dart rulesprovider.yaml- All 8 Provider rulesbloc.yaml- All 22 Bloc rulesfake_async.yaml- All FakeAsync rules
Documentation #
- Added comprehensive Migration Guide
- Updated README with preset usage examples
- Updated all category documentation files
- Added preset comparison guide
Migration Examples #
Before (v2.0.0):
# All rules enabled by default
custom_lint:
rules:
- avoid_non_null_assertion: false # Must disable unwanted
- no_magic_number: false # Must disable unwanted
After (v2.1.0):
# Use preset or enable specific rules
include: package:awesome_lints/presets/recommended.yaml
# Or enable specific rules only
custom_lint:
enable_all_lint_rules: false
rules:
- avoid_late_context
- prefer_early_return
2.0.0 - 2025-12-19 #
Major Release - Framework-Specific Lints #
🎉 Major expansion with 42 new lint rules across three new categories: Bloc, Provider, and FakeAsync, plus 11 new common lint rules!
New Categories
Bloc Lints (22 rules)
Framework-specific lints for the Bloc state management library:
avoid-bloc-public-fields- Warns when a Bloc or Cubit has public fieldsavoid-bloc-public-methods- Warns when a Bloc has public methods except overridden onesavoid-cubits- Warns when a Cubit is usedavoid-duplicate-bloc-event-handlers- Detects multiple handlers for the same eventavoid-empty-build-when- Requires buildWhen condition in BlocBuilder/BlocConsumeravoid-existing-instances-in-bloc-provider- Prevents reusing instances in BlocProvideravoid-instantiating-in-bloc-value-provider- Prevents new instances in BlocProvider.valueavoid-passing-bloc-to-bloc- Prevents Bloc dependencies on other Blocsavoid-passing-build-context-to-blocs- Prevents BuildContext in Bloc events/methodsavoid-returning-value-from-cubit-methods- Ensures Cubits communicate via statecheck-is-not-closed-after-async-gap- Requires isClosed checks in async handlersemit-new-bloc-state-instances- Prevents emitting existing state instanceshandle-bloc-event-subclasses- Ensures all event subclasses are handledprefer-bloc-event-suffix- Enforces "Event" suffix for event classesprefer-bloc-extensions- Suggests context.read()/watch() over BlocProvider.of()prefer-bloc-state-suffix- Enforces "State" suffix for state classesprefer-correct-bloc-provider- Ensures BlocProvider is used for Blocsprefer-immutable-bloc-events- Requires @immutable on Bloc eventsprefer-immutable-bloc-state- Requires @immutable on Bloc stateprefer-multi-bloc-provider- Suggests MultiBlocProvider for nested providersprefer-sealed-bloc-events- Requires sealed/final modifiers on event classesprefer-sealed-bloc-state- Requires sealed/final modifiers on state classes
Provider Lints (8 rules)
Framework-specific lints for the Provider state management library:
avoid-instantiating-in-value-provider- Prevents new instances in Provider.valueavoid-read-inside-build- Warns about read() usage in build methodsavoid-watch-outside-build- Warns about watch()/select() outside builddispose-providers- Ensures proper disposal of provided resourcesprefer-immutable-selector-value- Requires immutable values in Selectorprefer-multi-provider- Suggests MultiProvider for nested providersprefer-nullable-provider-types- Recommends nullable provider typesprefer-provider-extensions- Suggests context extensions over Provider.of()
FakeAsync Lints (1 rule)
Testing-focused lints for the fake_async package:
avoid-async-callback-in-fake-async- Prevents async callbacks in FakeAsync
New Common Lints (11 rules)
Enhanced common lints with new best practice rules:
prefer-async-await- Suggests async/await over Future APIprefer-contains- Suggests contains() over indexOf() != -1prefer-correct-for-loop-increment- Validates for-loop increment expressionsprefer-correct-json-casts- Ensures proper JSON type castingprefer-early-return- Recommends early returns to reduce nestingprefer-first- Suggests first over [0] or elementAt(0)prefer-iterable-of- Suggests Iterable.of() over manual iterationprefer-last- Suggests last over [length - 1]prefer-named-boolean-parameters- Requires named parameters for booleansprefer-return-await- Suggests explicit return await in try blocksprefer-switch-expression- Recommends switch expressions over statements
Documentation #
- Added BLOC_LINTS.md with comprehensive Bloc lint documentation
- Added PROVIDER_LINTS.md with comprehensive Provider lint documentation
- Added FAKE_ASYNC_LINTS.md with FakeAsync lint documentation
- Updated test fixtures and configuration for new rules
Summary #
Version 2.0.0 introduces:
- 42 new lint rules (22 Bloc + 8 Provider + 1 FakeAsync + 11 Common)
- 3 new framework-specific categories (Bloc, Provider, FakeAsync)
- Total of 128 lint rules across all categories
- Enhanced coverage for popular Flutter state management solutions
- Improved testing practices with FakeAsync support
1.0.0 - 2025-12-19 #
Initial Release #
🎉 First stable release of Awesome Lints - a comprehensive collection of custom lint rules for Dart and Flutter applications.
Flutter-Specific Lints (32 rules)
Widget Lifecycle & State Management:
avoid-empty-setstate- Warns when setState is called with an empty callbackavoid-late-context- Prevents context access in late field initializersavoid-mounted-in-setstate- Ensures mounted checks occur before setState callsavoid-stateless-widget-initialized-fields- Warns about non-constant field initialization in StatelessWidgetavoid-unnecessary-overrides-in-state- Detects unnecessary method overrides in State classesavoid-unnecessary-stateful-widgets- Warns when StatefulWidget doesn't use statedispose-fields- Ensures proper disposal of disposable fieldsproper-super-calls- Validates lifecycle method super calls
Widget Building & Performance:
avoid-missing-controller- Warns when text fields lack controllers or callbacksavoid-single-child-column-or-row- Detects unnecessary Column/Row with single childavoid-undisposed-instances- Warns about undisposed Disposable instancesavoid-unnecessary-gesture-detector- Suggests lighter alternatives to GestureDetectoravoid-wrapping-in-padding- Prevents unnecessary Padding wrapperspass-existing-future-to-future-builder- Prevents inline future creation in FutureBuilderpass-existing-stream-to-stream-builder- Prevents inline stream creation in StreamBuilderprefer-single-setstate- Recommends consolidating multiple setState calls
Widget Optimization:
prefer-align-over-container- Suggests Align instead of Container for alignment-onlyprefer-center-over-align- Suggests Center instead of Align(alignment: Alignment.center)prefer-constrained-box-over-container- Suggests ConstrainedBox for constraints-only scenariosprefer-container- Suggests Container to replace nested containerizable widgetsprefer-padding-over-container- Suggests Padding instead of Container for padding-only
Widget Best Practices:
prefer-action-button-tooltip- Recommends tooltips for action buttonsprefer-async-callback- Suggests AsyncCallback instead of Futureprefer-compute-over-isolate-run- Recommends compute over Isolate.runprefer-dedicated-media-query-methods- Suggests specific MediaQuery methodsprefer-for-loop-in-children- Suggests for-loops over .map().toList() in childrenprefer-sized-box-square- Suggests SizedBox.square() for square boxesprefer-sliver-prefix- Enforces "Sliver" prefix for sliver widgetsprefer-spacing- Suggests spacing parameter over SizedBox (Flutter 3.27+)prefer-text-rich- Suggests Text.rich() over RichTextprefer-void-callback- Suggests VoidCallback over void Function()prefer-widget-private-members- Recommends private members for widget internals
Common Dart Lints (54 rules)
Code Quality & Logic:
arguments-ordering- Enforces named arguments in declaration orderavoid-collapsible-if- Suggests combining nested if statementsavoid-complex-arithmetic-expressions- Warns about overly complex arithmeticavoid-complex-conditions- Warns about complex conditional expressionsavoid-complex-loop-conditions- Warns about complex loop conditionsavoid-contradictory-expressions- Detects logical contradictionsavoid-constant-assert-conditions- Warns about constant assert conditionsavoid-constant-conditions- Warns about constant if/while conditionsavoid-constant-switches- Warns about constant switch expressionsbinary-expression-operand-order- Enforces consistent operand ordering
Anti-Patterns & Potential Bugs:
avoid-accessing-collections-by-constant-index- Suggests first/last over [0]/[length-1]avoid-accessing-other-classes-private-members- Prevents accessing private membersavoid-always-null-parameters- Warns about parameters always passed as nullavoid-assigning-to-static-field- Warns about static field mutationavoid-assignments-as-conditions- Prevents assignments in conditionsavoid-async-call-in-sync-function- Warns about unawaited async callsavoid-bitwise-operators-with-booleans- Prevents & and | with booleansavoid-cascade-after-if-null- Warns about cascades after ?.avoid-collection-equality-checks- Warns about == on collectionsavoid-collection-methods-with-unrelated-types- Detects type mismatches in collection methodsavoid-collection-mutating-methods- Warns about mutating immutable collectionsavoid-continue- Suggests alternatives to continue statementsavoid-declaring-call-method- Warns about call method declarationsavoid-non-null-assertion- Warns about ! operator usage
Type Safety:
avoid-bottom-type-in-patterns- Prevents Never in patternsavoid-bottom-type-in-records- Prevents Never in recordsavoid-casting-to-extension-type- Warns about extension type castsno-object-declaration- Prevents Object type usage
Code Duplication & Redundancy:
avoid-adjacent-strings- Warns about adjacent string literalsavoid-conditions-with-boolean-literals- Prevents comparing with true/falseavoid-duplicate-cascades- Detects duplicate cascade operationsavoid-duplicate-collection-elements- Warns about duplicate collection elementsno-boolean-literal-compare- Prevents explicit true/false comparisonsno-equal-arguments- Detects identical arguments to different parametersno-equal-conditions- Warns about duplicate conditions in if-else chainsno-equal-nested-conditions- Warns about redundant nested conditionsno-equal-switch-case- Detects switch cases with identical bodiesno-equal-switch-expression-cases- Warns about switch cases returning same valueno-equal-then-else- Detects identical if-else branches
Code Style & Formatting:
double-literal-format- Enforces consistent double literal formattingnewline-before-case- Enforces blank lines before case clausesnewline-before-constructor- Enforces blank lines before constructorsnewline-before-method- Enforces blank lines before methodsnewline-before-return- Enforces blank lines before return statements
Code Cleanliness:
avoid-barrel-files- Warns about barrel file patternavoid-commented-out-code- Detects commented-out codeavoid-default-tostring- Warns about default toString() usageavoid-deprecated-usage- Warns about deprecated API usageavoid-double-slash-imports- Prevents // in import pathsno-empty-block- Warns about empty code blocksno-empty-string- Warns about empty string usage
Resource Management:
dispose-class-fields- Ensures disposal of disposable class fields
Magic Values:
no-magic-number- Requires named constants for numeric literalsno-magic-string- Requires named constants for repeated strings
Documentation #
- Added comprehensive README.md with quick start guide
- Created FLUTTER_LINTS.md with detailed documentation for all Flutter rules
- Created COMMON_LINTS.md with detailed documentation for all common rules
- Each lint includes "Why?", "Bad", and "Good" examples
Features #
- All lints enabled by default
- Support for custom_lint configuration
- Compatible with Dart 3.10.0+
- Compatible with Flutter 3.0.0+
- IDE integration (VS Code, Android Studio, IntelliJ)
- Watch mode support for continuous analysis
Future Releases #
Future releases will be documented here. We follow semantic versioning:
- MAJOR version for incompatible API changes
- MINOR version for new functionality in a backward compatible manner
- PATCH version for backward compatible bug fixes