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

New Universal.CodeAnalysis.ForeachUniqueAssignment sniff #110

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 30, 2022

Inspired by a tweet from @dseguy, this new sniff will detect foreach control structures which use the same variable for both the key as well as the value assignment as this will lead to unexpected - and most likely unintended - behaviour.

The sniff includes a fixer which will remove the key assignment when the issue is detected as the value is required and the key optional.

The fixer maintains the existing behaviour for the code, though that behaviour may not be the desired behaviour, so any autogenerated fixes should be carefully reviewed (as always).

Refs:

Includes fixer.
Includes unit tests.
Includes documentation.

Inspired by a tweet from dseguy, this new sniff will detect foreach control structures which use the same variable for both the _key_ as well as the _value_ assignment as this will lead to unexpected - and most likely unintended - behaviour.

The sniff includes a fixer which will remove the key assignment when the issue is detected as the value is required and the key optional.

The fixer maintains the existing behaviour for the code, though that behaviour may not be the desired behaviour, so any autogenerated fixes should be carefully reviewed (as always).

Refs:
* https://twitter.com/exakat/status/1509103728934203397
* https://3v4l.org/DdddX

Includes fixer.
Includes unit tests.
Includes documentation.
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Mar 30, 2022
@jrfnl jrfnl merged commit c2c7498 into develop Mar 30, 2022
@jrfnl jrfnl deleted the universal/new-foreachuniqueassignments-sniff branch March 30, 2022 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant