使用 guard-rspec 时如何忽略 rubocop 检查?
How to ignore rubocop check when using guard-rspec?
当我添加 guard-rspec
gem 并将 Guardfile
设置为:
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
然后运行rubocop
检查:
rake rubocop:rubocop
显示:
Guardfile:5:9: C: Use %r only for regular expressions matching more than 1 '/' character.
watch(%r{^spec/.+_spec\.rb$})
^^^^^^^^^^^^^^^^^^^^^^
我应该想办法重写常规代码还是将忽略代码写入 .rubocop.yml
文件?
我改成watch(%r{^spec/(.*)/(.*)\.rb$})
,然后就过去了
Rubocop 告诉您只有当正则表达式本身包含超过 1 个 /
字符时才应使用扩展的正则表达式符号 %r{}
。否则你应该使用 //
符号并转义 /
符号
您可以将行重写为 watch(/^spec\/.+_spec\.rb$/)
以在不更改正则表达式本身的情况下消除警告
当我添加 guard-rspec
gem 并将 Guardfile
设置为:
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
然后运行rubocop
检查:
rake rubocop:rubocop
显示:
Guardfile:5:9: C: Use %r only for regular expressions matching more than 1 '/' character.
watch(%r{^spec/.+_spec\.rb$})
^^^^^^^^^^^^^^^^^^^^^^
我应该想办法重写常规代码还是将忽略代码写入 .rubocop.yml
文件?
我改成watch(%r{^spec/(.*)/(.*)\.rb$})
,然后就过去了
Rubocop 告诉您只有当正则表达式本身包含超过 1 个 /
字符时才应使用扩展的正则表达式符号 %r{}
。否则你应该使用 //
符号并转义 /
符号
您可以将行重写为 watch(/^spec\/.+_spec\.rb$/)
以在不更改正则表达式本身的情况下消除警告