diff --git a/Gemfile b/Gemfile index 56223f92d..95e5b3c10 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ end # but our runtime dep is still 3.9+ gem "rspec", ">= 3.10" +# checks code offenses with inspec check gem "cookstyle" group :omnibus do diff --git a/lib/inspec/profile.rb b/lib/inspec/profile.rb index 23d1deb58..99af1a3f2 100644 --- a/lib/inspec/profile.rb +++ b/lib/inspec/profile.rb @@ -389,7 +389,7 @@ module Inspec def cookstyle_linting_check msgs = [] output = cookstyle_rake_output.split("Offenses:").last - msgs = output.split("\n").select { |x| (x.include? "R:") || (x.include? "C:") } unless output.nil? + msgs = output.split("\n").select { |x| x =~ /[A-Z]:/ } unless output.nil? msgs end @@ -399,7 +399,11 @@ module Inspec require "rubocop/rake_task" begin RuboCop::RakeTask.new(:cookstyle_lint) do |spec| - spec.options += ["--display-cop-names", "--parallel"] + spec.options += [ + "--display-cop-names", + "--parallel", + "--only=InSpec/Deprecations,InSpec/Deprecations/AttributeHelper,InSpec/Deprecations/AttributeDefault", + ] spec.patterns += Dir.glob("#{@target}/**/*").reject { |f| File.directory?(f) || (f.include? "inspec.lock") } spec.fail_on_error = false end diff --git a/test/functional/inspec_check_test.rb b/test/functional/inspec_check_test.rb index 26058747d..90e358e6b 100644 --- a/test/functional/inspec_check_test.rb +++ b/test/functional/inspec_check_test.rb @@ -126,8 +126,8 @@ describe "inspec check" do end it "fails and returns offenses in a profile" do - out = inspec("check #{profile_path}/control-tags") - _(out.stdout).must_match(/29 offenses/) + out = inspec("check #{profile_path}/inputs/metadata-basic") + _(out.stdout).must_match(/1 offenses/) assert_exit_code 1, out end end