flutter_semantic_lints 0.1.0
flutter_semantic_lints: ^0.1.0 copied to clipboard
Custom lint rules that detect meaningless, conflicting, or no-effect Flutter code.
flutter_semantic_lints #
Not style. Not formatting.
This package detects meaningless Flutter code.
Why this exists #
Most lint packages focus on:
- style
- naming
- best practices
But they miss something critical:
Code that works but makes no sense.
This package detects:
- conflicting parameters
- useless parameters
- no-effect widgets
Rules #
box_decoration_color_gradient #
Bad:
BoxDecoration(
color: Colors.red,
gradient: LinearGradient(...),
)
color is ignored.
Good:
BoxDecoration(
color: Colors.red,
)
Good:
BoxDecoration(
gradient: LinearGradient(...),
)
Use either color or gradient, not both.
container_color_decoration #
Bad:
Container(
color: Colors.red,
decoration: BoxDecoration(...),
)
color conflicts with decoration.
Good:
Container(
color: Colors.red,
)
Good:
Container(
decoration: BoxDecoration(
color: Colors.red,
),
)
Move the color into decoration when using decoration.
expanded_flex_one #
Bad:
Expanded(flex: 1)
Default value is already 1.
Good:
Expanded(
child: child,
)
Good:
Expanded(
flex: 2,
child: child,
)
Omit flex when the value is 1.
opacity_one #
Bad:
Opacity(
opacity: 1.0,
child: ...,
)
No visual effect. Adds cost only.
Good:
child
Good:
Opacity(
opacity: 0.5,
child: child,
)
Remove Opacity when the value is 1.0.
Installation #
dev_dependencies:
custom_lint:
flutter_semantic_lints:
Setup #
analyzer:
plugins:
- custom_lint
Run #
dart run custom_lint
Philosophy #
- correctness over style
- semantics over formatting
- signal over noise
Rule Categories #
conflicting_parameter #
box_decoration_color_gradientcontainer_color_decoration
useless_parameter #
expanded_flex_one
no_effect_widget #
opacity_one
Testing #
The example project doubles as integration coverage.
cd example
dart run custom_lint
Positive cases use // expect_lint: comments. Negative and edge cases live in
separate example files and should stay quiet.
Non-goals #
- style lint
- naming rules
- formatting
- architecture opinions
Status #
MVP
Implemented rules:
- BoxDecoration conflict
- Container conflict
- Expanded(flex: 1)
- Opacity(1.0)
Contributing #
Only submit rules that:
- are objectively correct
- have near-zero false positives
- are explainable in one sentence
License #
MIT