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+ # but our runtime dep is still 3.9+
gem "rspec", ">= 3.10" gem "rspec", ">= 3.10"
# checks code offenses with inspec check
gem "cookstyle" gem "cookstyle"
group :omnibus do group :omnibus do

View file

@ -389,7 +389,7 @@ module Inspec
def cookstyle_linting_check def cookstyle_linting_check
msgs = [] msgs = []
output = cookstyle_rake_output.split("Offenses:").last 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 msgs
end end
@ -399,7 +399,11 @@ module Inspec
require "rubocop/rake_task" require "rubocop/rake_task"
begin begin
RuboCop::RakeTask.new(:cookstyle_lint) do |spec| 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.patterns += Dir.glob("#{@target}/**/*").reject { |f| File.directory?(f) || (f.include? "inspec.lock") }
spec.fail_on_error = false spec.fail_on_error = false
end end

View file

@ -126,8 +126,8 @@ describe "inspec check" do
end end
it "fails and returns offenses in a profile" do it "fails and returns offenses in a profile" do
out = inspec("check #{profile_path}/control-tags") out = inspec("check #{profile_path}/inputs/metadata-basic")
_(out.stdout).must_match(/29 offenses/) _(out.stdout).must_match(/1 offenses/)
assert_exit_code 1, out assert_exit_code 1, out
end end
end end