Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

feat: add prefer-immediate-return rule #736

Merged
merged 1 commit into from
Mar 16, 2022
Merged

feat: add prefer-immediate-return rule #736

merged 1 commit into from
Mar 16, 2022

Conversation

roman-petrov
Copy link
Contributor

@roman-petrov roman-petrov commented Mar 11, 2022

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix
[x] New rule
[ ] Changes an existing rule
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

#474

Is there anything you'd like reviewers to focus on?

The fixer implemented is something like "semi-automatic" fixer, it does only half of the work required :) It replaces only expression in the problematic return statement and code contains unused variable after that.

For example,

int calculateSum(int a, int b) {
   final sum = a + b; 
   return sum;
}

will be fixed as

int calculateSum(int a, int b) {
   final sum = a + b; 
   return a + b;
}

and sum variable should be manually removed. I think that this shoud be acceptable - it's not a huge amount of work to manually remove unused variable (linters should warn about it too).

Implementing fully automatic fixer seems to be a bit hard: we have to replace multiple nodes/statements, but currently (as I see) we have only nodeLocation utility method which can create location only from single node.

@codecov
Copy link

codecov bot commented Mar 11, 2022

Codecov Report

Merging #736 (ef802a8) into master (f290337) will increase coverage by 0.03%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #736      +/-   ##
==========================================
+ Coverage   86.84%   86.87%   +0.03%     
==========================================
  Files         269      271       +2     
  Lines        5730     5762      +32     
==========================================
+ Hits         4976     5006      +30     
- Misses        754      756       +2     
Impacted Files Coverage Δ
...c/analyzers/lint_analyzer/rules/rules_factory.dart 90.36% <0.00%> (-2.24%) ⬇️
...immediate_return/prefer_immediate_return_rule.dart 100.00% <100.00%> (ø)
...es/rules_list/prefer_immediate_return/visitor.dart 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff611af...ef802a8. Read the comment docs.

Copy link
Member

@incendial incendial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@incendial incendial added type: enhancement New feature or request area-rules labels Mar 15, 2022
@dkrutskikh dkrutskikh merged commit b83c5f1 into dart-code-checker:master Mar 16, 2022
@roman-petrov roman-petrov deleted the prefer-immediate-return-rule branch March 25, 2022 08:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-rules type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants