Skip to content

Instantly share code, notes, and snippets.

@jshirley
Last active May 18, 2016 21:00
Show Gist options
  • Save jshirley/e1cdfd0e5dd04612d112e4675d038a91 to your computer and use it in GitHub Desktop.
Save jshirley/e1cdfd0e5dd04612d112e4675d038a91 to your computer and use it in GitHub Desktop.
rubocop Exclude relative path bug
Lint/EndAlignment:
Exclude:
- 'rel/path/broken.rb'
inherit_from:
- .rubocop-todo.yml
Documentation:
Enabled: false

The rubocop documentation states "Files and directories are specified relative to the .rubocop.yml file.", however that seems to be untrue based on from where you run rubocop from! Oh no!

To demonstrate the breakage, clone this gist and move the broken.rb to a subdirectory:

mkdir -p rel/path
mv broken.rb rel/path

From there, you can confirm that relative paths work from the same directory as .rubocop.yml:

bundle
bundle exec rubocop rel/path/broken.rb

All good! 1 files inspected, no offenses detected But if I rely on the behavior for rubocop to go upwards to find the .rubocop.yml (which it does) it loses the Excludes configuration.

bundle exec rubocop broken.rb
Inspecting 1 file
W

Offenses:

broken.rb:8:7: W: end at 8, 6 is not aligned with if at 4, 4.
      end
      ^^^

1 file inspected, 1 offense detected
class Broken
def foo
# I'm intentionally broken
if 1 == 0
puts "This isn't real code."
else
puts "For really real, it isn't"
end
end
end
source 'https://rubygems.org'
gem 'rubocop'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment