NREL / OpenStudio-measure-tester-gem

Other
3 stars 0 forks source link

The way RuboCop is run ignores exclusions #76

Closed jmarrec closed 4 months ago

jmarrec commented 4 months ago

First off, I don't think you should be using RuboCop::Runner, but rather just use RuboCop::RakeTask directly, or RuboCop::CLI.

Anyways, that's not the point. The issue is that you do use RuboCop::Runner passing specific files here https://github.com/NREL/OpenStudio-measure-tester-gem/blob/14659ef904019789f651a890bc56d2324d725805/lib/openstudio_measure_tester/runner.rb#L158

But some of these may be excluded by the rubocop.yml. So you must pass force_exclusion: true

$ rubocop --help

        --force-exclusion            Force excluding files specified in the
                                     configuration `Exclude` even if they are
                                     explicitly passed as arguments.

Secondly, I don't get why you turn off color?


How to use the rake task directly, taking as an example how to only run it under a specific folder

namespace :openstudio do
  namespace :measures do
    desc 'Run RuboCop only for the measures'
    RuboCop::RakeTask.new :rubocop do |t|
      require 'rubocop/formatter/checkstyle_formatter'
      rubocop_results_file = "#{Rake.application.original_dir}/test_results/rubocop/rubocop-results.xml"
      t.formatters = ['progress', ['RuboCop::Formatter::CheckstyleFormatter', '-o', rubocop_results_file]]
      t.verbose = true
      t.patterns = ["#{Rake.application.original_dir}/lib/measures/**/*.rb"]
      t.options = ['--force-exclusion']
      t.fail_on_error = args[:fail_on_error]
    end
  end
end