Use only inspec cops of cookstyle gem

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2021-08-18 15:33:36 +05:30
parent bedde88849
commit ab1d423a35
3 changed files with 9 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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