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

Strange(wrong?) behavior with Exclude and inherit_from #3960

Closed
ghost opened this issue Jan 23, 2017 · 10 comments
Closed

Strange(wrong?) behavior with Exclude and inherit_from #3960

ghost opened this issue Jan 23, 2017 · 10 comments

Comments

@ghost
Copy link

ghost commented Jan 23, 2017

Setup

Make one "good behavior" setup.

  1. mkdir test && cd test
  2. Create a .rubocop.yml with:
    Style/CharacterLiteral:
      Exclude:
         - 'blargh/blah.rb'
    
  3. mkdir blargh && echo '?x' > blargh/blah.rb

Make one "bad behavior" setup.

  1. mkdir test-bad && cd test-bad
  2. Create a .rubocop.yml with:
    inherit_from:
      - .rubocop_rules.yml
    
  3. Create a .rubocop_rules.yml with:
    Style/CharacterLiteral:
      Exclude:
         - 'blargh/blah.rb'
    
  4. mkdir blargh && echo '?x' > blargh/blah.rb

Expected behavior

Running rubocop in test, test-bad, test/blargh, and test-bad/blargh should all show no violations.

Actual behavior

Running rubocop in test, test-bad, and test/blargh shows no violations. Running rubocop in test-bad/blargh shows violations.

RuboCop version

0.47.1 (using Parser 2.3.3.1, running on ruby 2.3.1 x86_64-linux)

Note

This is probably the root cause of rubocop/rubocop-emacs#24 (@johnfoley3 is my co-worker).

@ghost ghost changed the title Strange(wrong?) behavior with Exclude and inherit-from Strange(wrong?) behavior with Exclude and inherit_from Jan 23, 2017
@mikegee
Copy link
Contributor

mikegee commented Jan 23, 2017

Is this a dupe of #3744?

@ghost
Copy link
Author

ghost commented Jan 23, 2017 via email

@jonas054
Copy link
Collaborator

The behavior is intended, and the explanation can be found here: https://github.com/bbatsov/rubocop/blob/v0.47.1/lib/rubocop/config.rb#L266-L270

I can see how this might be confusing, but is there a better way?

@ghost
Copy link
Author

ghost commented Jan 23, 2017

@jonas054 Some special handling for files like default.yml instead of the current state would be less confusing to users for sure. Probably more confusing/painful for the developers though.

The problem is, is there any way currently to make the above scenario work? Or do you just have to not use inheritance? There should at least be some way to fix it IMO.

@jonas054
Copy link
Collaborator

@mordocai The workaround solution is to specify the paths relative to the project base, i.e. test-bad/blargh/blah.rb in test-bad/.rubocop_rules.yml.

I expect that people may want to use the feature of realtive-to-current-dir-paths in inherited files, but as you say, this is not always the wanted behavior.

I think we could let the paths be relative to the configuration file's directory in all files beginning with .rubocop and relative to the current directory in other files. This should be documented.

@ghost
Copy link
Author

ghost commented Jan 24, 2017

Thanks @jonas054! I tried the workaround and it isn't working for me. I imagine I'm doing it wrong.

I updated test-bad/.rubocop_rules.yml to be:

Style/CharacterLiteral:
  Exclude:
     - 'test-bad/blargh/blah.rb'

And now the exclude doesn't work at all. Running rubocop in test-bad or test-bad/blargh both show the cop failure.

@jonas054
Copy link
Collaborator

@mordocai The path test-bad/blargh/blah.rb is relative to the current directory, by which I mean the directory where you're running rubocop, so it's only if you're running in the test directory that this setting makes sense.

@ghost
Copy link
Author

ghost commented Jan 24, 2017

@jonas054 Right, that's the reason the issue was opened. So the workaround I was looking for was for there to be some way to have the path work from the project directory when inherited.

For our use case the only other things I can think to fix our specific issue are:

@jonas054
Copy link
Collaborator

Ah, it's flycheck. It's good that you have some ideas for solutions. I still think we should make a fix in RuboCop, as I proposed earlier:

I think we could let the paths be relative to the configuration file's directory in all files beginning with .rubocop and relative to the current directory in other files. This should be documented.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 25, 2017

Yeah, that sounds reasonable.

jonas054 added a commit to jonas054/rubocop that referenced this issue Mar 4, 2017
Before this change, Include and Exclude paths in .rubocop.yml
and .rubocop_todo.yml were taken as relative to the config
file's directory. This extends that behavior to any file
beginning with ".rubocop".
@bbatsov bbatsov closed this as completed in c52c7ea Mar 4, 2017
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

3 participants