简体   繁体   中英

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?

我改变watch(%r{^spec/(.*)/(.*)\\.rb$}) ,然后它通过了。

Rubocop tells you that the extended regex notation %r{} should only be used if the regex itself contains more than 1 / character. Otherwise you should use // notation and escape the / symbol

You can rewrite the line to watch(/^spec\\/.+_spec\\.rb$/) to get rid of the warning without changing the regex itself

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM