如何使用"格式化程序"从一个RuboCop :: RakeTask生成多种输出格式?

时间:2018-03-02 12:43:03

标签: ruby rake rubocop

为了将我们的Rubocop报告整合到Jenkins中,我想一次性生成Checkstyles - XML输出和HTML输出。

我可以直接运行Rubocop来实现这一目标:

$ rubocop -r rubocop/formatter/checkstyle_formatter \
    --format html --out reports/html/index.html \
    --format RuboCop::Formatter::CheckstyleFormatter --out reports/checkstyle-result.xml

但是,我无法弄清楚如何使用RuboCop::RakeTaskformatters数组获得相同的结果。

以下是我的尝试:

在选项中使用多个--out条目

RuboCop::RakeTask.new(:rubocop_ci) do |t|
   t.formatters = ['html', 'RuboCop::Formatter::CheckstyleFormatter']
   t.options = ['--out', 'reports/checkstyle-result.xml',
                '--out', 'reports/html/index.html']
end

这会生成reports/checkstyle-result.xml,但会将HTML输出打印到STDOUT(可能是Rubocop会忽略第二个--out参数)。

将所有内容放入选项中,并完全忽略格式化程序

RuboCop::RakeTask.new(:rubocop_ci2) do |t|
    t.options = ['--format', 'RuboCop::Formatter::CheckstyleFormatter', 
                 '--out', 'reports/checkstyle-result.xml',
                 '--format', 'html',
                 '--out', 'reports/html/index.html']
end

这很有效,但很难看;是否可以在formatters中使用具有不同输出文件的多个条目?

0 个答案:

没有答案