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
Cannot lint arbitrary files #4245
Comments
I think you didn't understand me last time around. The problem has nothing to do with directories and everything to do with what happens when you do |
To quote myself from the other issue:
So given a directory ...
... if I run ...
... which expands to ...
... then of course rubocop should lint both files. My glob was wrong. But if I run ...
... then rubocop should only lint ruby files. From my perspective this behaviour is a good default and can be tweaked by command line flags of course (like Or am I still missing something? |
Well, I'm ok with an approach like this one, although I don't really know how everyone's using RuboCop so it might cause problems for some people. If someone wants to work in the direction of implementing your idea, that's fine by me. |
To give another example and perhaps provide a fuller picture for Rubocop's usage scenarios, consider slim-lint. In order to lint the Ruby parts of a slim template, slim-lint creates a temporary file which consists of just those Ruby parts, with all slim-templating removed. The resulting file is in no way a proper Ruby file, nevertheless one could argue that it should be processed by Rubocop, since it is passed explicitly. The workaround, of course, is to simply provide the Tempfiles with an *.rb extension (sds/slim-lint#55). I don't know how other linters (e.g. haml-lint) integrate Rubocop, but this might be worth a look. Finally, I found it rather surprising that Rubocop silently ignores such files. In slim-lint's case (with version <= 0.11), this meant that all of a sudden no Rubocop warnings whatsoever were displayed. Someone upgrading Rubocop from 0.47 to 0.48 without upgrading slim-lint to >= 0.12 will not receive Rubocop warnings in slim templates anymore (!). It might be helpful if Rubocop displayed a warning when ignoring files. |
It is possible to lint arbitrary files when they are included in a rubocop config. As a proof of concept, I have the following AllCops:
Include:
- 'dsl/**/*' I created a file module Foo
BAR = 'baz'
end This warns with
If I pass both files on the command line, the
I think adding the explicit configuration in |
I ended up here after banging my head against the wall based on the docs which led me to believe that you could pass arbitrary files at the command line. If this behavior isn't expected to work, I'll submit a PR to update the docs. I've noticed it won't even lint these files if I explicitly add them like so AllCops:
Include:
- '**/Envfile'
It will lint them if I add the magic comment |
@swrobel In recent versions the explicit As I said before the real problem is what to do with shell globbings and stuff. I agree that if some files are explicitly passed they should probably be linted, but if the files list was expanded or generated by some other command that expects RuboCop to do some filtering that'd be bad. Probably we need some command line flag to turn-on the built-in filtering on demand. A PR would be welcome! |
This is a follow up to #4242
Currently I cannot lint a custom file. For example, if I have a file named
bla
with the following content:"some string"
and I run rubocop
it does not lint it:
When I rename it to
bla.rb
, it lints it:When I pass file at command line, I am saying "lint this please". Rubocop should not ignore it.
This has nothing to do when I pass a directory to rubocop. Then it is OK it lints only ruby files (or better to say files it thinks are ruby files), because that is reasonable. But when I explicitly pass a file on the command line, then it is 100% clear that I want it to be linted by rubocop - or else I would not pass it.
Expected behavior
It should lint every file I pass in at command line explicitly.
Actual behavior
It ignores files.
RuboCop version
The text was updated successfully, but these errors were encountered: