Search code examples
ruby-on-railsrubyrspecguardrubocop

How to ignore rubocop check when using guard-rspec?


When I add a guard-rspec gem and set the Guardfile as this:

guard :rspec, cmd: 'bundle exec rspec' do
  watch('spec/spec_helper.rb')                        { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  watch(%r{^spec/.+_spec\.rb$})
end

Then run rubocop to check:

rake rubocop:rubocop

It showed:

Guardfile:5:9: C: Use %r only for regular expressions matching more than 1 '/' character.
watch(%r{^spec/.+_spec\.rb$})
      ^^^^^^^^^^^^^^^^^^^^^^

Should I try to find a way to rewrite the regular code or write a ignore code to .rubocop.yml file?


Solution

  • I changed to watch(%r{^spec/(.*)/(.*)\.rb$}), then it passed.