How to integrate rubocop with Rake?

前端 未结 5 1421
一整个雨季
一整个雨季 2021-02-06 22:46

rubocop is a code style checker for Ruby. A similar tool to rubocop, Cane, can be integrated with Rake. I prefer rubocop to Cane since rubocop makes checks based on the Ruby Sty

5条回答
  •  旧巷少年郎
    2021-02-06 23:36

    You can shell out via Rake with the options you prefer:

      desc 'Run Rubocop with options'
      task rubocop: :environment do
        sh 'bundle exec rubocop -D --format offenses --format progress || true'
      end
    

    I then recommend modifying the default task to include the output. The trick is to clear the task and then add back what you want. Note the need to end with || true so that an error from Rubocop will not prevent the next task from running. Here's what I do, which also uses parallel tests:

    task(:default).clear.enhance ['parallel:parallel_prepare', 'parallel:spec',
                                  'parallel:features', 'lint:rubocop',
                                  'lint:rails_best_practices']
    

提交回复
热议问题