【问题标题】:Different rubocop outputs不同的 rubocop 输出
【发布时间】:2015-10-23 17:16:02
【问题描述】:

现在 rubocop 为我的 rails 项目提供 3 种不同的输出,具体取决于我调用它的方式。

> rubocop # version: 0.34.2
88 files inspected, 5 offenses detected

>bundle exec rubocop # version: 0.30.1
87 files inspected, no offenses detected

>rake # with :rubocop in my task list
87 files inspected, 35 offenses detected

>bundle exec rake # with :rubocop in my task list
87 files inspected, 35 offenses detected

2 个变体是有意义的,因为我的系统 rubocop 版本与我的 Gemfile 中的不同。但是3?呜呜呜?

我假设第三个输出来自某个地方的第三个版本的 rubocop?它会在哪里?这是怎么回事?

更新:

任务列表:['ci:setup', :spec, :rubocop, :jshint, 'brakeman:run', 'bundler:audit', 'bundler:outdated']

更新 2:

根据一位同事的建议,我将其放入以尝试在 rake 期间获取正在运行的 rubocop 版本:

task :rubocop do
  require 'rubocop/rake_task'
  require 'rubocop/version'
  puts RuboCop::Version.version
  RuboCop::RakeTask.new do |task|
    task.patterns = ['--rails']
  end
end

打印出0.30.1,这是我期望的版本。仍然没有解释错误。

【问题讨论】:

  • 您的其他 rake 任务是什么?生成的东西是 RuboCop 可以接受的吗?
  • @Drenmi 我已经添加了可以运行的任务列表。如果在 rake 期间生成/更改了文件,我会假设 rubocop / bundle exec rubocop 的后续运行会捕获它们? (这不会发生。)

标签: ruby-on-rails rubocop


【解决方案1】:

这很悲伤和尴尬。

如果我更仔细地查看 rubocop 的 rake 任务,我会注意到:

task.patterns = ['--rails'] 

这增加了一些额外的警察。将该标志添加到 bundle exec rubocop --railsrake 运行的输出相匹配。

我希望这可以帮助其他人比我更快地注意到这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 2020-06-12
    相关资源
    最近更新 更多