Merge pull request #5724 from inspec/cw/disable-cookstyle-on-windows

Disable CookStyle integration on Windows
This commit is contained in:
Clinton Wolfe 2021-11-16 02:16:23 -05:00 committed by GitHub
commit baa6331203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View file

@ -122,8 +122,13 @@ class Inspec::InspecCLI < Inspec::BaseCLI
end
puts
enable_offenses = !Inspec.locally_windows? # See 5723
if result[:errors].empty? && result[:warnings].empty? && result[:offenses].empty?
ui.plain_line("No errors, warnings, or offenses")
if enable_offenses
ui.plain_line("No errors, warnings, or offenses")
else
ui.plain_line("No errors or warnings")
end
else
item_msg = lambda { |item|
pos = [item[:file], item[:line], item[:column]].compact.join(":")
@ -135,7 +140,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
puts
unless result[:offenses].empty?
if enable_offenses && !result[:offenses].empty?
puts "Offenses:\n"
result[:offenses].each { |item| ui.cyan(" #{Inspec::UI::GLYPHS[:script_x]} #{item_msg.call(item)}\n\n") }
end
@ -143,7 +148,11 @@ class Inspec::InspecCLI < Inspec::BaseCLI
offenses = ui.cyan("#{result[:offenses].length} offenses", print: false)
errors = ui.red("#{result[:errors].length} errors", print: false)
warnings = ui.yellow("#{result[:warnings].length} warnings", print: false)
ui.plain_line("Summary: #{errors}, #{warnings}, #{offenses}")
if enable_offenses
ui.plain_line("Summary: #{errors}, #{warnings}, #{offenses}")
else
ui.plain_line("Summary: #{errors}, #{warnings}")
end
end
end

View file

@ -18,4 +18,9 @@ module Inspec
require "etc" unless defined?(Etc)
Etc.getpwuid.dir
end
def self.locally_windows?
require "rbconfig" unless defined?(RbConfig)
RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
end
end

View file

@ -450,6 +450,8 @@ module Inspec
def cookstyle_linting_check
msgs = []
return msgs if Inspec.locally_windows? # See #5723
output = cookstyle_rake_output.split("Offenses:").last
msgs = output.split("\n").select { |x| x =~ /[A-Z]:/ } unless output.nil?
msgs

View file

@ -120,12 +120,14 @@ describe "inspec check" do
describe "inspec check also check for cookstyle offenses" do
it "finds no offenses in a complete profile" do
skip if windows? # see #5723
out = inspec("check #{profile_path}/complete-profile")
_(out.stdout).must_match(/No errors, warnings, or offenses/)
assert_exit_code 0, out
end
it "fails and returns offenses in a profile" do
skip if windows? # see #5723
out = inspec("check #{profile_path}/inputs/metadata-basic")
_(out.stdout).must_match(/1 offenses/)
assert_exit_code 1, out