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

Add new Lint/AmbiguousAssignment cop #9226

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

fatkodima
Copy link
Contributor

Closes #9223

@dvandersluis
Copy link
Member

Maybe AmbiguousAssignment would be a better name?

@dvandersluis
Copy link
Member

dvandersluis commented Dec 14, 2020

Also, I think we need to ensure that x = -y (for example) is allowed, since it'll parse to the same AST as x =- y, and is valid. The offense message should probably suggest that x =- y could be either x -= y or x = -y since both are valid and we can't know what they were going for.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 14, 2020

I think that's why there's no auto-correct for the cop - it's hard to tell if that's a bug or poorly formatted code. That being said it seems to me the code simply checks in the source if the operator is right after the =, so it wouldn't result in a false positive for x = -y. That being said, some tests to cover this and +/*y would be useful.

@fatkodima
Copy link
Contributor Author

For me both names (current and AmbiguousAssignment) are good enough, not sure which is better.
Expanded tests.

@dvandersluis
Copy link
Member

AmbiguousAssignment would be parallel with the other Lint cops (AmbiguousOperator, AmbiguousBlockAssociation, AmbiguousRegexpLiteral), but I'd leave it up to @bbatsov

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 15, 2020

Let's go with Ambiguous. Consistent naming is a good thing.

@fatkodima fatkodima changed the title Add new Lint/SuspiciousAssignment cop Add new Lint/AmbiguousAssignment cop Dec 15, 2020
@fatkodima
Copy link
Contributor Author

Changed the name.

@bbatsov bbatsov merged commit d45ccf5 into rubocop:master Dec 15, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 15, 2020

Thanks!

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.

New lint cop to check mistypes in += or -=
3 participants