-
Notifications
You must be signed in to change notification settings - Fork 267
feat: add use-setstate-synchronously rule #1120
feat: add use-setstate-synchronously rule #1120
Conversation
8fd91e1
to
3c6e2a2
Compare
3c6e2a2
to
f97a9ea
Compare
@Desdaemon could you please update the changelog?
The most important that the rule shouldn't produce false-positives. So, if I'm not mistaken, covering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great result! Left a few comments. Haven't seen @pragma('vm:prefer-inline')
in action before 🙂
lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_async_setstate/visitor.dart
Outdated
Show resolved
Hide resolved
lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_async_setstate/helpers.dart
Outdated
Show resolved
Hide resolved
...analyzers/lint_analyzer/rules/rules_list/avoid_async_setstate/avoid_async_setstate_rule.dart
Outdated
Show resolved
Hide resolved
0606a41
to
4f1389f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! The only question I have - will ||
create false positives? I'll later run this rule on the Flutter codebase (or you can, if you want to) to know for sure, but it'd be better if we avoid as many false positives as possible
...alyzer/rules/rules_list/use_setstate_synchronously/use_setstate_synchronously_rule_test.dart
Outdated
Show resolved
Hide resolved
There's one I haven't found a way to cleanly implement: if (!mounted || foo) return;
setState(); // should be mounted here
if (!mounted && bar || foo) return;
setState(); // LINT When the first or-chain diverges, it should also have the effect of guaranteeing the widget is mounted, but currently it does not do so. If there are other false positives I'll prioritize fixing them as well. |
4f1389f
to
42893bd
Compare
Codecov Report
@@ Coverage Diff @@
## master #1120 +/- ##
==========================================
+ Coverage 85.19% 85.37% +0.17%
==========================================
Files 342 347 +5
Lines 7540 7673 +133
==========================================
+ Hits 6424 6551 +127
- Misses 1116 1122 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I ran this on the Flutter package on the stable branch, the only violation it detected was this situation: I think this is too specific for this rule to handle, but otherwise no false positives yet. I'll run this on other codebases as well to cover as many edge cases as possible. |
0054192
to
667d125
Compare
Yeah, looks questionable, tbh (I mean, the code).
I've noticed a fix for a false positive, if you can also add tests - that'd be great. And after that I'm ready to merge, so tell me when you're ready. |
fb1170e
to
75d8762
Compare
@incendial That should be my last batch of changes, should be ready to review and merge. |
@Desdaemon please add tests for the config (example) and I'll merge |
And please check the failing tests |
Kudos, SonarCloud Quality Gate passed!
|
@Desdaemon thank you for the contribution! 🚀 |
What is the purpose of this pull request? (put an "X" next to an item)
#1117
What changes did you make? (Give an overview)
if
checkswhile
checksTernariesmounted && ..
)!mounted || ..
)Is there anything you'd like reviewers to focus on?
Should this rule try to be as comprehensive as possible and check for all cases, or should the current heuristics for determining mounted-ness be sufficient?