rubycritic
rubycritic copied to clipboard
Ignores Ruby files without a .rb extension
Rubycritic won't analyze files which don't have the .rb
suffix even if the file has a shebang line like:
#!/usr/bin/env ruby
which indicates it it is a Ruby file. This is true even if the file is explicitly specified either as a trailing argument on the CLI:
rubycritic exe/my-bin
or by using the paths
argument in the Rake task:
RubyCritic::RakeTask.new do |task|
task.paths = FileList["exe/my-bin"]
task.verbose = true
end
The problem seems to be that the code checks to see if the file has the '.rb' extension: https://github.com/whitesmith/rubycritic/blob/a6ddc92235adb2f4353dfec1286850ebbe48a800/lib/rubycritic/source_locator.rb#L42
This is unnecessarily restrictive. When creating a gem which provides a command the user will run from the CLI, the convention is to provide the Ruby script in the exe
directory (which the gem
will use to put the script into a bin
directory in the user's PATH
), add a shebang to run the Ruby interpreter, and set the executable permission on the file (i.e., chmod +x exe/my-bin
). Rubycritic doesn't provide any means to analyze such a script.
As an ugly workaround, I have to create a symlink (with the .rb
suffix) for each Ruby script in the exe
directory and make sure the .gemspec
file excludes the symlinked files.
A good solution would be to analyze all files specified explicitly (on the CLI or via the paths
argument of the Rake task) and to look at the shebang line of the files which were globbed. Rubocop does this already so you can look at the signatures they look for in the shebang to decide if the file is a Ruby file or not.
@cvoltz Thanks for reporting this! I like your solution, I think we need to improve the way we detect whether it is a file with Ruby code or not.
In terms of implementing a patch, I would recommend we go with a solution like this:
- First check for the extension. If the extension is .rb then it is a Ruby file -- This already works
- Then check for the first line in the file, if it has the ruby shebang, then it is a Ruby file. -- This needs to be implemented.
If you want to take a stab at it, I'd be happy to review your PR. 👍
@etagwerker If no one else is working on this yet, can I work on it? I plan to work on this issue using rubocop's FileFinder module as a reference.
@NerdyBoyCool as far as I know nobody is actively working on this issue so I'd say go for it. 👍
@etagwerker Thank you!!! I'll do it! 😆
@etagwerker looks like this was solved here I think issue can be closed then