Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update conditionalAssignment rule to support more complex lvalues #1647

Conversation

calda
Copy link
Collaborator

@calda calda commented Mar 18, 2024

This PR updates the conditionalAssignment rule to support more complex lvalues. Previously it required that the value being assigned was just a simple identifier like foo =. Now it supports more complex lvalues like foo?.bar =, foo["bar"] =, etc.

For example, this sample code was left as-is before:

switch condition {
case true:
    property?.foo!.bar["baaz"] = Foo("foo")
case false:
    property?.foo!.bar["baaz"] = Foo("bar")
}

Now it is updated as expected:

property?.foo!.bar["baaz"] =
    switch condition {
    case true:
        Foo("foo")
    case false:
        Foo("bar")
    }

I also added a new --condassignment after-property to let consumers disable the new functionality added in #1643. After running the updated rule on our codebase, I found too many of the changes weird and unusual. On the other hand I found the previous behavior (only applying the new syntax after a new property declaration) reasonable almost all of the time.

@calda calda force-pushed the cal--condititionalAssignment-lvalue-support branch from fdddd71 to 0e274ef Compare March 18, 2024 21:17
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.16%. Comparing base (9ce956c) to head (a11c38d).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1647      +/-   ##
===========================================
- Coverage    95.18%   95.16%   -0.03%     
===========================================
  Files           20       20              
  Lines        22498    22522      +24     
===========================================
+ Hits         21414    21432      +18     
- Misses        1084     1090       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nicklockwood nicklockwood merged commit 591bcec into nicklockwood:develop Mar 27, 2024
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants