rubocop是一个用于Ruby的代码样式检查器。一个类似于rubocop的工具,Cane,可以是integrated with Rake。我更喜欢rubocop而不是Cane,因为rubocop会根据Ruby Style Guide进行检查,而且它似乎是spot more problems。为了自动化样式检查的过程,我想将rubocop与Rake集成在一起,这样如果代码质量不足,构建就会失败。
Gem已经通过Rake支持adding tests to packages。我想对样式检查做同样的事情,以便样式检查与测试一起运行。我该怎么做呢?
如果从Rakefile开始会有帮助,这里有一个:
# -*- 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
发布于 2013-02-25 05:52:38
我建议把钱花在rubocop计划上。这是最简单的解决方案。只需将此代码添加到您的Rakefile中:
task test: :rubocop
task :rubocop do
sh 'rubocop'
end
发布于 2013-11-26 04:53:49
从0.10.0
版本开始,rubocop包含了一个您可以使用的自定义rake任务。只需在您的Rakefile
中添加以下内容
require 'rubocop/rake_task'
RuboCop::RakeTask.new
确保使用大写的“R”和“C”,否则会得到一个NameError。
发布于 2016-11-12 01:17:49
我强烈推荐,
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = ['--display-cop-names']
end
这将使用rubocop自己的rake任务,并允许您根据需要传递选项。
https://stackoverflow.com/questions/15008751
复制相似问题