rubocop / guard-rubocop

Guard plugin for RuboCop
MIT License
262 stars 55 forks source link

Rubocop doesn't show the cop name in guard-rubocop but it does on the CLI #42

Open coaxial opened 4 years ago

coaxial commented 4 years ago

Compare:

$ bundle exec rubocop
Inspecting 14 files
............W.

Offenses:

spec/my_spec.rb:42:1: W: Lint/MissingCopEnableDirective: Re-enable Lint/HandleExceptions cop with # rubocop:enable after disabling it.
        # rescue SystemExit # rubocop:disable Lint/HandleExceptions
^
spec/my_spec.rb:43:26: C: Layout/TrailingWhitespace: Trailing whitespace detected.
        rescue SystemExit
                         ^

14 files inspected, 2 offenses detected

with

$ bundle exec guard
08:02:31 - INFO - Guard::RSpec is running
08:02:31 - INFO - Inspecting Ruby code style of all files
Inspecting 14 files
............W.

Offenses:

spec/my_spec.rb:42:1: W: Re-enable Lint/HandleExceptions cop with # rubocop:enable after disabling it.
        # rescue SystemExit # rubocop:disable Lint/HandleExceptions
^
spec/my_spec.rb:43:26: C: Trailing whitespace detected.
        rescue SystemExit
                         ^

When running guard-rubocop, the name of the cop that matches the lint error isn't written. But it is when running rubocop directly. I have no options set on my guard:

guard :rubocop do
  watch('Gemfile')
  watch('Rakefile')
  watch(/.+\.rb$/)
  watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
end
griley commented 4 years ago

@coaxial , try

guard :rubocop, cli: ['--display-cop-names']`  do
  ...
end
barelyknown commented 1 year ago

Does anyone know why the command line option is required instead of the .rubocop.yml (AllCops/DisplayCopNames: true)?

kassi commented 2 months ago

@barelyknown One thing is that guard-rubocop does not run rubocop with bundler and you can't simply add cmd: "bundle exec rubocop" to Guardfile nor cmd: %w[bundle exec rubocop] without a change in the gem (see #55). In addition, it then only works if you pass cli: "--config .rubocop.yml" to the guard. Couldn't figure out yet, why this is the case.

edit: at least it did it after I changed that. Now it's kinda back to where it was before.