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

Auto-correct not correcting AndOr offences #800

Closed
AlexVPopov opened this issue Feb 7, 2014 · 7 comments
Closed

Auto-correct not correcting AndOr offences #800

AlexVPopov opened this issue Feb 7, 2014 · 7 comments
Assignees

Comments

@AlexVPopov
Copy link

0.18.1 (using Parser 2.1.4, running on ruby 2.0.0 x86_64-darwin13.0.0)

I want to correct a single offence, so I run rubocop like that:

rubocop --only AndOr -a

I get the output:

Offences:

xxx/xxxxxx/xxxxxxx_xxxxxxxx.rb:48:26: C: [Corrected] Use && instead of and.
      leader_user != nil and leader_user != User.deactivated_user
                         ^^^

464 files inspected, 1 offence detected, 1 offence corrected

But the file does not get changed. Do I need to reload something to see the change? I also tried running:

rubocop --auto-correct --only AndOr
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 7, 2014

Works for me when I tried it with the code you've posted.

@AlexVPopov
Copy link
Author

Hm, I tried it on a second machine with the same result. Perhaps I use it incorrectly. Will get back to you later on that. Thank you.

@Hampei
Copy link

Hampei commented Mar 19, 2014

@AlexVPopov did you figure out what you did wrong?
I'm running into the same problem on both 0.18 and 0.19.1.
It says it fixed them, but it only fixed a few.

@AlexVPopov
Copy link
Author

Yes, I had some wrong settings in .rubocop.yml. Make sure you have not disabled the cop there. Also check if you have any other .rubocop.yml files below the root directory.

@Hampei
Copy link

Hampei commented Mar 19, 2014

It's not that it's not enabled. It sees the error and says it fixed it, but it hasn't. It fixed it for some the first run, but nothing after that.
Also no other .rubocops.yml
Just removed all rubocop settings and it still isn't fixing them.

Will try to figure out the difference between the ones in did fix and the ones it didn't later.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 19, 2014

Your problem is actually caused by a limitation in RuboCop with regard to this particular check. We cannot replace all and and or nodes, since the replacements might yield a different AST, so we replace only the once that are safe. On the other hand RuboCop always reports auto-correctable offences as corrected. @jonas054 @yujinakayama Maybe we should address this?

@jonas054
Copy link
Collaborator

Yes! RuboCop should not say [Corrected] if it decided that it couldn't change he code. I'm reopening this issue.

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

No branches or pull requests

4 participants