如何整合rubocop与Rake? [英] How to integrate rubocop with Rake?

查看:88
本文介绍了如何整合rubocop与Rake?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rubocop 是Ruby的代码风格检查工具。 rubocop类似的工具Cane,可以与Rake 集成。我喜欢rubocop到Cane,因为rubocop根据 Ruby风格指南进行检查,似乎发现更多问题。要自动化样式检查的过程,我想整合rubocop与Rake,如果缺乏代码质量,构建失败。

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 Style Guide and it seems to spot more problems. To automate the process of style checking I would like to integrate rubocop with Rake so that the build fails if code quality is lacking.

Gem已经支持通过Rake向包添加测试。我想对样式检查做同样的事情,以便样式检查与测试一起运行。

Gem already supports adding tests to packages via Rake. I would like to do the same with style checks so that style checks are run along with the tests. How can I do this?

如果它有助于开始使用Rakefile,那么这里是一个:

If it helps to start with a Rakefile here is one:

# -*- coding: utf-8; mode: ruby -*-

require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new do |t|
  t.libs << 'test'
  t.test_files = FileList['test/unit/test*.rb']
end

desc 'Run tests'
task default: :test


推荐答案

我会建议shelling到rubocop程序。这是最简单的解决方案。只需将它添加到您的Rakefile:

I would recommend shelling out to the rubocop program. It's the simplest solution. Just add this to your Rakefile:

task test: :rubocop

task :rubocop do
  sh 'rubocop'
end

这篇关于如何整合rubocop与Rake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆