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

[Fix #7849] Add ExplicitOperatorPrecedence cop #7912

Closed

Conversation

rahul404
Copy link

Fixes #7849

This cop checks if binary operators of different precedents are used without explicit parenthesis.

# bad
a && b || c
a * b + c
a ** b * c / d % e + f - g << h >> i & j | k ^ l

# good
(a && b) || c
(a * b) + c
(((((a**b) * c / d % e) + f - g) << h >> i) & j) | k ^ l

Rahul Ahuja added 2 commits April 27, 2020 02:35
Fixes rubocop#7849

This cop checks if binary operators of different precedents are
used without explicit use of parenthesis.

```ruby
a && b || c
a * b + c
a ** b * c / d % e + f - g << h >> i & j | k ^ l

(a && b) || c
(a * b) + c
(((((a**b) * c / d % e) + f - g) << h >> i) & j) | k ^ l
```
@bbatsov
Copy link
Collaborator

bbatsov commented May 10, 2020

@rahul404 I see the build is failing, so I assume this is still WIP. Let me know when it's ready for review.

@rahul404
Copy link
Author

@bbatsov, The build fails due to a test case I am not able to figure out.

Hi @bbatsov, I have made a PR for this feature. There is one issue I can fix in it.
The test case to fix a ** b * c / d % e + f - g << h >> i & j | k ^ l fails. Somehow the cop exercises the correction method only once.
#7849 (comment)

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 4, 2020

I'm closing this PR due to no recent activity. Feel free to re-open it if you ever come back to it.

@bbatsov bbatsov closed this Nov 4, 2020
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 Cop Idea: Explicit operator precedence
2 participants