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

When running rubocop on a file that .rubocop.yml excludes, have option to skip it #893

Closed
osdiab opened this issue Mar 17, 2014 · 13 comments · Fixed by #922
Closed

When running rubocop on a file that .rubocop.yml excludes, have option to skip it #893

osdiab opened this issue Mar 17, 2014 · 13 comments · Fixed by #922

Comments

@osdiab
Copy link

osdiab commented Mar 17, 2014

My rubocop.yml in a Rails project has the following lines:

# rubocop.yml
# ...
AllCops:
  Excludes:
    db/**
# ...
  • Running rubocop db/ will produce no errors, as expected.
  • Running rubocop db/schema.rb does produce errors.

This is not inherently bad—in fact, that's nice behavior because it lets you check things regardless of general project configuration.

But my git pre-commit script searches for all Ruby files currently staged for committing, and runs rubocop on them (as opposed to also checking files that aren't staged for commit). I want to be able to enforce that because those files are excluded in configuration, skip them, even though the rubocop invocation explicitly refers to that filename. A flag for that would be nice.

@Rakoth
Copy link

Rakoth commented Mar 25, 2014

+1 on this

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 25, 2014

Sounds reasonable. @jonas054 @yujinakayama Your thoughts?

@yujinakayama
Copy link
Collaborator

As I mentioned in yujinakayama/atom-lint#25, 👍 for this.

@jonas054
Copy link
Collaborator

👍 I can see a need for this feature when RuboCop is run from a tool.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 25, 2014

OK, so I guess we'll implement this. @yujinakayama @jonas054 Would one of you like to do it, since my personal RuboCop pipeline is full of tasks.

@yujinakayama
Copy link
Collaborator

Then I'll do.

@maksimf
Copy link

maksimf commented Apr 20, 2015

In my project's .rubocop.yml file I have:

AllCops:
  Excludes:
    - config/unicorn.rb
    - db/schema.rb
  RunRailsCops: true

When i run rubocop db/schema.rb it still finds offences, but if I run rubocop db/ or rubocop --force-exclusion db/schema.rb I get no offences.

Looks like a bug, am I wrong?

@jonas054
Copy link
Collaborator

Yes you are. 😄 The --force-exclusion option was added just so that files given on the command line could be excluded by configuration. See discussion above.

@maksimf
Copy link

maksimf commented Apr 23, 2015

@jonas054 Nevermind --force-exclusion for a minute. If I have the above config, why rubocop still inspects db/schema.rb when I call rubocop db/schema.rb?

@jonas054
Copy link
Collaborator

Because command line arguments override configuration. It's convenient to be able to inspect excluded files by naming them explicitly without having to edit the configuration.

@maksimf
Copy link

maksimf commented Apr 23, 2015

But it is resulting to unexpected behaviour in linters (I'm using sublime linter). I ignore schema.rb in my .rubocop.yml, but editor's linter invokes rubocop for the specific file, which is being edited. So, there is actually no way to make linter work as expected in this case?

@jonas054
Copy link
Collaborator

The sublime linter should use the --force-exclusion option.

@maksimf
Copy link

maksimf commented Apr 23, 2015

Yes, you are right. From the console it work ok, then it's linter's issue, because it won't work from sublime, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants