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

fix: correctly handle prefixed enums and static instance fields for prefer-moving-to-variable #1123

Merged
merged 4 commits into from
Jan 11, 2023

Conversation

incendial
Copy link
Member

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

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

@incendial incendial self-assigned this Dec 26, 2022
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@github-actions
Copy link

Dart Code Metrics unused files report of dart_code_metrics. ✅

Summary

  • Scanned package folders: bin, example, lib
  • No unused files found! ✅

@github-actions
Copy link

Dart Code Metrics analyze report of dart_code_metrics. ✅

Summary

  • Scanned folders: bin, example, lib, test

  • Total scanned files: 541

  • Total lines of source code: 9567

  • Total classes: 409

  • Average Cyclomatic Number per line of code: 0.37 / 2

  • Average Source Lines of Code per method: 6

  • Total tech debt: 2040.0 hours

  • Found issues: 5 ⚠

@codecov
Copy link

codecov bot commented Dec 26, 2022

Codecov Report

Merging #1123 (d9fbf65) into master (29e6181) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1123   +/-   ##
=======================================
  Coverage   85.54%   85.54%           
=======================================
  Files         349      349           
  Lines        7870     7873    +3     
=======================================
+ Hits         6732     6735    +3     
  Misses       1138     1138           
Impacted Files Coverage Δ
...ng_to_variable/prefer_moving_to_variable_rule.dart 81.25% <ø> (ø)
.../rules_list/prefer_moving_to_variable/visitor.dart 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

AnotherEnum.anotherValue;
AnotherEnum.firstValue;

prefix.SomeValue.firstValue;
Copy link

Choose a reason for hiding this comment

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

try referencing prefix.SomeValue.firstValue
repeatedly
I believe that would match the case where I was seeing false positives.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's it! Thank you!

Copy link
Member Author

@incendial incendial Jan 4, 2023

Choose a reason for hiding this comment

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

Hm, actually, if I duplicate the line 5 AnotherEnum.anotherValue; the rule will also trigger. So it's not connected to prefixes, maybe you remember other cases?

Copy link

Choose a reason for hiding this comment

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

The strange thing is removing the prefixes did seem to fix the issue in DevTools. That said, I wouldn't want the rule to trigger for duplicated AnotherEnum.anotherValue case either. Specifying the enum value name twice seems more idiomatic than defining an unneeded local variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. And maybe the same should work for the class level static variables. You probably wouldn't want to assign this type of calls to a variable.

Copy link

Choose a reason for hiding this comment

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

Agree that I wouldn't want this firing for class to class level static variables either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for misleading, it was a problem exactly with the prefixes 🤦
Now fixed, thank you!

@incendial incendial changed the title test: add test cases fix: correctly handle prefixed enums and static instance fields for prefer-moving-to-variable Jan 10, 2023
@incendial incendial marked this pull request as ready for review January 10, 2023 15:35
@incendial incendial requested a review from dkrutskikh January 10, 2023 15:36
@incendial incendial added this to the 5.5.0 milestone Jan 10, 2023
Copy link

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

@dkrutskikh dkrutskikh merged commit b4d5cbc into master Jan 11, 2023
@dkrutskikh dkrutskikh deleted the fix-prefix-prefer-moving-to-variable branch January 11, 2023 10:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants