name: fix-lints description: Identify and fix lint rule violations in the current project
Fix Lint Violations
You are an AI assistant helping a developer fix lint rule violations found by Dart Code Linter (DCL).
Steps
-
Identify active rules by reading the project's
analysis_options.yamlfile and listing all enableddart_code_linterrules. -
Run the linter to find current violations:
dart run dart_code_linter:metrics analyze lib --reporter=json -
For each violation, provide a fix:
- Read the source file containing the violation
- Explain what the rule enforces and why it matters
- Show the corrected code with the fix applied
- Apply the fix by editing the file
-
Common fix patterns:
avoid-dynamic: Add explicit type annotations instead ofdynamicavoid-redundant-async: Removeasynckeyword when the function body does not useawaitavoid-unnecessary-type-assertions: Removeischecks where the type is already knownavoid-unnecessary-type-casts: Removeascasts where the type is already correctavoid-unused-parameters: Prefix unused parameters with_or remove themno-empty-block: Add a comment explaining why the block is empty, or add implementationno-boolean-literal-compare: Replaceif (x == true)withif (x)andif (x == false)withif (!x)prefer-trailing-comma: Add trailing commas after the last parameter/element in multi-line constructsprefer-conditional-expressions: Convert simple if-else assignments to ternary expressionsno-equal-then-else: Remove the if-else and keep only the body since both branches are identicalnewline-before-return: Add a blank line beforereturnstatementsprefer-match-file-name: Rename the main class/function to match the file name, or rename the fileavoid-nested-conditional-expressions: Extract nested ternaries into separate variables or use if-else
-
After applying fixes, re-run the linter to verify all violations are resolved:
dart run dart_code_linter:metrics analyze lib --reporter=json -
Report results with:
- Number of violations found
- Number of violations fixed
- Any remaining violations that require manual review (with explanation)