diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb index 2b750fe9e..10db18739 100644 --- a/lib/inspec/cli.rb +++ b/lib/inspec/cli.rb @@ -95,6 +95,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI desc "check PATH", "verify all tests at the specified PATH" option :format, type: :string, desc: "The output format to use doc (default), json. If valid format is not provided then it will use the default." + option :with_cookstyle, type: :boolean, + desc: "Enable or disable cookstyle checks.", default: false profile_options def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength o = config diff --git a/lib/inspec/profile.rb b/lib/inspec/profile.rb index 81dc54cff..27613021b 100644 --- a/lib/inspec/profile.rb +++ b/lib/inspec/profile.rb @@ -105,6 +105,7 @@ module Inspec @check_mode = options[:check_mode] || false @parent_profile = options[:parent_profile] @legacy_profile_path = options[:profiles_path] || false + @check_cookstyle = options[:with_cookstyle] Metadata.finalize(@source_reader.metadata, @profile_id, options) # if a backend has already been created, clone it so each profile has its own unique backend object @@ -655,12 +656,13 @@ module Inspec end # Running cookstyle to check for code offenses - cookstyle_linting_check.each do |lint_output| - data = lint_output.split(":") - msg = "#{data[-2]}:#{data[-1]}" - offense.call(data[0], data[1], data[2], nil, msg) + if @check_cookstyle + cookstyle_linting_check.each do |lint_output| + data = lint_output.split(":") + msg = "#{data[-2]}:#{data[-1]}" + offense.call(data[0], data[1], data[2], nil, msg) + end end - # profile is valid if we could not find any error & offenses result[:summary][:valid] = result[:errors].empty? && result[:offenses].empty? diff --git a/test/functional/inspec_check_test.rb b/test/functional/inspec_check_test.rb index e5ceaaa82..fe413950d 100644 --- a/test/functional/inspec_check_test.rb +++ b/test/functional/inspec_check_test.rb @@ -118,16 +118,16 @@ describe "inspec check" do end describe "inspec check also check for cookstyle offenses" do - it "finds no offenses in a complete profile" do + it "finds no offenses in a complete profile when --with-cookstyle option is provided" do skip if windows? # see #5723 - out = inspec("check #{profile_path}/complete-profile") + out = inspec("check #{profile_path}/complete-profile --with-cookstyle") _(out.stdout).must_match(/No errors, warnings, or offenses/) assert_exit_code 0, out end - it "fails and returns offenses in a profile" do + it "fails and returns offenses in a profile when --with-cookstyle option is provided" do skip if windows? # see #5723 - out = inspec("check #{profile_path}/inputs/metadata-basic") + out = inspec("check #{profile_path}/inputs/metadata-basic --with-cookstyle") _(out.stdout).must_match(/1 offenses/) assert_exit_code 1, out end