From bbbbd6e7fcc6e98bbbc9a18c63340e897533dbe9 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:19:39 +0100 Subject: [PATCH 01/56] (CONT-811) Correct initial cops --- lib/puppet-lint.rb | 2 +- lib/puppet-lint/bin.rb | 6 ++---- lib/puppet-lint/checks.rb | 8 +++----- lib/puppet-lint/configuration.rb | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/puppet-lint.rb b/lib/puppet-lint.rb index 2ce571d2..b5fda9da 100644 --- a/lib/puppet-lint.rb +++ b/lib/puppet-lint.rb @@ -251,7 +251,7 @@ def print_problems def self.new_check(name, &block) class_name = name.to_s.split('_').map(&:capitalize).join klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin)) - klass.const_set('NAME', name) + klass.const_set(:NAME, name) klass.class_exec(&block) PuppetLint.configuration.add_check(name, klass) PuppetLint::Data.ignore_overrides[name] ||= {} diff --git a/lib/puppet-lint/bin.rb b/lib/puppet-lint/bin.rb index 7ae04d8d..7b2fff4a 100644 --- a/lib/puppet-lint/bin.rb +++ b/lib/puppet-lint/bin.rb @@ -49,7 +49,7 @@ def run begin path = @args[0] - full_path = File.expand_path(path, ENV['PWD']) + full_path = File.expand_path(path, ENV.fetch('PWD', nil)) full_base_path = if File.directory?(full_path) full_path else @@ -89,9 +89,7 @@ def run end next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax } - File.open(f, 'wb') do |fd| - fd.write(l.manifest) - end + File.binwrite(f, l.manifest) end if PuppetLint.configuration.sarif diff --git a/lib/puppet-lint/checks.rb b/lib/puppet-lint/checks.rb index ebef7366..c68ded07 100644 --- a/lib/puppet-lint/checks.rb +++ b/lib/puppet-lint/checks.rb @@ -76,7 +76,7 @@ def run(fileinfo, data) kind: :error, check: :syntax, message: 'Syntax error', - fullpath: File.expand_path(fileinfo, ENV['PWD']), + fullpath: File.expand_path(fileinfo, ENV.fetch('PWD', nil)), filename: File.basename(fileinfo), path: fileinfo, line: e.token.line, @@ -120,10 +120,8 @@ def run(fileinfo, data) # # Returns an Array of String check names. def enabled_checks - @enabled_checks ||= begin - PuppetLint.configuration.checks.select do |check| - PuppetLint.configuration.send("#{check}_enabled?") - end + @enabled_checks ||= PuppetLint.configuration.checks.select do |check| + PuppetLint.configuration.send("#{check}_enabled?") end end diff --git a/lib/puppet-lint/configuration.rb b/lib/puppet-lint/configuration.rb index 041d50ab..067999ac 100644 --- a/lib/puppet-lint/configuration.rb +++ b/lib/puppet-lint/configuration.rb @@ -18,7 +18,7 @@ def self.add_check(check) # # Returns true if the check is enabled, otherwise return false. define_method("#{check}_enabled?") do - settings["#{check}_disabled"] == true ? false : true + (settings["#{check}_disabled"] == true) ? false : true end # Public: Disable the named check. @@ -153,6 +153,6 @@ def defaults self.show_ignored = false self.ignore_paths = ['vendor/**/*.pp'] self.github_actions = ENV.key?('GITHUB_ACTION') - self.codeclimate_report_file = ENV['CODECLIMATE_REPORT_FILE'] + self.codeclimate_report_file = ENV.fetch('CODECLIMATE_REPORT_FILE', nil) end end From 03ec6ff4f1a028fe8d5a641b64ac3f503c8890cc Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:22:43 +0100 Subject: [PATCH 02/56] (CONT-811) Correct Gemspec/RequireMFA --- puppet-lint.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/puppet-lint.gemspec b/puppet-lint.gemspec index bbc3dcfb..23b420ef 100644 --- a/puppet-lint.gemspec +++ b/puppet-lint.gemspec @@ -33,4 +33,5 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.required_ruby_version = Gem::Requirement.new('>= 2.5'.freeze) + spec.metadata['rubygems_mfa_required'] = 'true' end From 61c10fe1c681f82ee00eef584b5ff0c7e573bf7a Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:26:44 +0100 Subject: [PATCH 03/56] (CONT-811) Correct Layout/IndentationConsistency --- lib/puppet-lint/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/configuration.rb b/lib/puppet-lint/configuration.rb index 067999ac..c3539ed5 100644 --- a/lib/puppet-lint/configuration.rb +++ b/lib/puppet-lint/configuration.rb @@ -18,7 +18,7 @@ def self.add_check(check) # # Returns true if the check is enabled, otherwise return false. define_method("#{check}_enabled?") do - (settings["#{check}_disabled"] == true) ? false : true + settings["#{check}_disabled"] != true end # Public: Disable the named check. From bdf1d465ff154ccccd4f3c2200faea72b57e1f44 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:28:25 +0100 Subject: [PATCH 04/56] (CONT-811) Correct Layout/LineContinuationSpacing --- lib/puppet-lint/plugins/check_classes/parameter_order.rb | 2 +- lib/puppet-lint/plugins/check_documentation/documentation.rb | 4 ++-- lib/puppet-lint/plugins/check_resources/ensure_first_param.rb | 2 +- .../plugins/check_resources/ensure_not_symlink_target.rb | 2 +- lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb | 2 +- .../plugins/check_strings/double_quoted_strings.rb | 2 +- .../check_strings/single_quote_string_with_variables.rb | 2 +- lib/puppet-lint/plugins/check_whitespace/line_length.rb | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/puppet-lint/plugins/check_classes/parameter_order.rb b/lib/puppet-lint/plugins/check_classes/parameter_order.rb index 7ebe06d7..78fc435d 100644 --- a/lib/puppet-lint/plugins/check_classes/parameter_order.rb +++ b/lib/puppet-lint/plugins/check_classes/parameter_order.rb @@ -34,7 +34,7 @@ def check message: msg, line: token.line, column: token.column, - description: 'Test the manifest tokens for any parameterised classes or defined types that take '\ + description: 'Test the manifest tokens for any parameterised classes or defined types that take ' \ 'parameters and record a warning if there are any optional parameters listed before required parameters.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#display-order-of-parameters', ) diff --git a/lib/puppet-lint/plugins/check_documentation/documentation.rb b/lib/puppet-lint/plugins/check_documentation/documentation.rb index 0bcb51b6..51a3c6fe 100644 --- a/lib/puppet-lint/plugins/check_documentation/documentation.rb +++ b/lib/puppet-lint/plugins/check_documentation/documentation.rb @@ -25,8 +25,8 @@ def check message: "#{type} not documented", line: first_token.line, column: first_token.column, - description: 'Check the manifest tokens for any class or defined type that does not '\ - 'have a comment directly above it (hopefully, explaining the usage of it) and record '\ + description: 'Check the manifest tokens for any class or defined type that does not ' \ + 'have a comment directly above it (hopefully, explaining the usage of it) and record ' \ 'a warning for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private', ) diff --git a/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb b/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb index a5eff9de..32a54e6b 100644 --- a/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +++ b/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb @@ -21,7 +21,7 @@ def check line: ensure_token.line, column: ensure_token.column, resource: resource, - description: 'Check the tokens of each resource instance for an ensure parameter and if '\ + description: 'Check the tokens of each resource instance for an ensure parameter and if ' \ 'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#attribute-ordering', ) diff --git a/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb b/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb index 66868abc..a82d45e7 100644 --- a/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +++ b/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb @@ -21,7 +21,7 @@ def check column: value_token.column, param_token: ensure_token, value_token: value_token, - description: 'Check the tokens of each File resource instance for an ensure parameter and '\ + description: 'Check the tokens of each File resource instance for an ensure parameter and ' \ 'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#symbolic-links', ) diff --git a/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb b/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb index 9a0add99..e2a04822 100644 --- a/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +++ b/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb @@ -23,7 +23,7 @@ def check line: value_token.line, column: value_token.column, token: value_token, - description: 'Check the tokens of each File resource instance for a mode parameter '\ + description: 'Check the tokens of each File resource instance for a mode parameter ' \ 'and if found, record a warning if the value of that parameter is not a quoted string.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes', ) diff --git a/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb b/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb index ddcbd059..63c40535 100644 --- a/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +++ b/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb @@ -19,7 +19,7 @@ def check line: token.line, column: token.column, token: token, - description: 'Check the manifest tokens for any double quoted strings that don\'t '\ + description: 'Check the manifest tokens for any double quoted strings that don\'t ' \ 'contain any variables or common escape characters and record a warning for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting', ) diff --git a/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb b/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb index 63da996b..69bbc3cf 100644 --- a/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +++ b/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb @@ -14,7 +14,7 @@ def check message: 'single quoted string containing a variable found', line: token.line, column: token.column, - description: 'Check the manifest tokens for any single quoted strings containing '\ + description: 'Check the manifest tokens for any single quoted strings containing ' \ 'a enclosed variable and record an error for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting', ) diff --git a/lib/puppet-lint/plugins/check_whitespace/line_length.rb b/lib/puppet-lint/plugins/check_whitespace/line_length.rb index 57d14de4..c3ea70fa 100644 --- a/lib/puppet-lint/plugins/check_whitespace/line_length.rb +++ b/lib/puppet-lint/plugins/check_whitespace/line_length.rb @@ -21,7 +21,7 @@ def self.check(line_number, content, character_count) message: "line has more than #{character_count} characters", line: line_number, column: character_count, - description: 'Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. '\ + description: 'Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. ' \ 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace', ] From cf3edb9eda2aae7f795500e81dfdec76c3158a4f Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:31:54 +0100 Subject: [PATCH 05/56] (CONT-811) Correct Performance/StringIdentifierArgument --- lib/puppet-lint/checkplugin.rb | 2 +- lib/puppet-lint/monkeypatches.rb | 2 +- .../plugins/check_classes/class_inherits_from_params_class.rb | 2 +- lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb | 2 +- lib/puppet-lint/plugins/check_classes/parameter_order.rb | 2 +- lib/puppet-lint/plugins/check_classes/variable_scope.rb | 4 ++-- lib/puppet-lint/plugins/check_documentation/documentation.rb | 4 ++-- lib/puppet-lint/plugins/check_resources/ensure_first_param.rb | 2 +- .../plugins/check_resources/ensure_not_symlink_target.rb | 2 +- lib/puppet-lint/plugins/check_resources/file_mode.rb | 2 +- lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb | 2 +- .../plugins/check_strings/double_quoted_strings.rb | 2 +- lib/puppet-lint/plugins/check_strings/quoted_booleans.rb | 2 +- .../check_strings/single_quote_string_with_variables.rb | 2 +- lib/puppet-lint/plugins/check_whitespace/80chars.rb | 2 +- lib/puppet-lint/plugins/check_whitespace/line_length.rb | 2 +- spec/unit/puppet-lint/lexer_spec.rb | 4 ++-- .../unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/puppet-lint/checkplugin.rb b/lib/puppet-lint/checkplugin.rb index 0069476d..e8a31ff3 100644 --- a/lib/puppet-lint/checkplugin.rb +++ b/lib/puppet-lint/checkplugin.rb @@ -179,7 +179,7 @@ def manifest_lines # Returns a Hash of default problem information. def default_info @default_info ||= { - check: self.class.const_get('NAME'), + check: self.class.const_get(:NAME), fullpath: fullpath, path: path, filename: filename, diff --git a/lib/puppet-lint/monkeypatches.rb b/lib/puppet-lint/monkeypatches.rb index 9c2784eb..a986f58d 100644 --- a/lib/puppet-lint/monkeypatches.rb +++ b/lib/puppet-lint/monkeypatches.rb @@ -3,7 +3,7 @@ rescue # monkeypatch String#% into Ruby 1.8.7 class String - Percent = instance_method('%') unless defined?(Percent) + Percent = instance_method(:%) unless defined?(Percent) def %(*a, &b) a.flatten! diff --git a/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb b/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb index 574f4e1e..e249a96e 100644 --- a/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +++ b/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb @@ -18,4 +18,4 @@ def check end end end -PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send(:disable_class_inherits_from_params_class) diff --git a/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb b/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb index 53e41121..44259392 100644 --- a/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +++ b/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb @@ -20,4 +20,4 @@ def check end end end -PuppetLint.configuration.send('disable_code_on_top_scope') +PuppetLint.configuration.send(:disable_code_on_top_scope) diff --git a/lib/puppet-lint/plugins/check_classes/parameter_order.rb b/lib/puppet-lint/plugins/check_classes/parameter_order.rb index 78fc435d..d91a080a 100644 --- a/lib/puppet-lint/plugins/check_classes/parameter_order.rb +++ b/lib/puppet-lint/plugins/check_classes/parameter_order.rb @@ -35,7 +35,7 @@ def check line: token.line, column: token.column, description: 'Test the manifest tokens for any parameterised classes or defined types that take ' \ - 'parameters and record a warning if there are any optional parameters listed before required parameters.', + 'parameters and record a warning if there are any optional parameters listed before required parameters.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#display-order-of-parameters', ) end diff --git a/lib/puppet-lint/plugins/check_classes/variable_scope.rb b/lib/puppet-lint/plugins/check_classes/variable_scope.rb index bb4ef23a..9e67a2e9 100644 --- a/lib/puppet-lint/plugins/check_classes/variable_scope.rb +++ b/lib/puppet-lint/plugins/check_classes/variable_scope.rb @@ -132,8 +132,8 @@ def check line: token.line, column: token.column, description: 'Test the manifest tokens for any variables that are referenced in the manifest. ' \ - 'If the variables are not fully qualified or one of the variables automatically created in the scope, ' \ - 'check that they have been defined in the local scope and record a warning for each variable that has not.', + 'If the variables are not fully qualified or one of the variables automatically created in the scope, ' \ + 'check that they have been defined in the local scope and record a warning for each variable that has not.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables', ) end diff --git a/lib/puppet-lint/plugins/check_documentation/documentation.rb b/lib/puppet-lint/plugins/check_documentation/documentation.rb index 51a3c6fe..71d8bd01 100644 --- a/lib/puppet-lint/plugins/check_documentation/documentation.rb +++ b/lib/puppet-lint/plugins/check_documentation/documentation.rb @@ -26,8 +26,8 @@ def check line: first_token.line, column: first_token.column, description: 'Check the manifest tokens for any class or defined type that does not ' \ - 'have a comment directly above it (hopefully, explaining the usage of it) and record ' \ - 'a warning for each instance found.', + 'have a comment directly above it (hopefully, explaining the usage of it) and record ' \ + 'a warning for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private', ) end diff --git a/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb b/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb index 32a54e6b..edb8af34 100644 --- a/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +++ b/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb @@ -22,7 +22,7 @@ def check column: ensure_token.column, resource: resource, description: 'Check the tokens of each resource instance for an ensure parameter and if ' \ - 'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.', + 'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#attribute-ordering', ) end diff --git a/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb b/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb index a82d45e7..9d21b7fd 100644 --- a/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +++ b/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb @@ -22,7 +22,7 @@ def check param_token: ensure_token, value_token: value_token, description: 'Check the tokens of each File resource instance for an ensure parameter and ' \ - 'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').', + 'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#symbolic-links', ) end diff --git a/lib/puppet-lint/plugins/check_resources/file_mode.rb b/lib/puppet-lint/plugins/check_resources/file_mode.rb index 93f15dc9..156b645c 100644 --- a/lib/puppet-lint/plugins/check_resources/file_mode.rb +++ b/lib/puppet-lint/plugins/check_resources/file_mode.rb @@ -30,7 +30,7 @@ def check column: value_token.column, token: value_token, description: 'Check the tokens of each File resource instance for a mode parameter and if found, ' \ - 'record a warning if the value of that parameter is not a 4 digit octal value (0755) or a symbolic mode (\'o=rwx,g\+r\').', + 'record a warning if the value of that parameter is not a 4 digit octal value (0755) or a symbolic mode (\'o=rwx,g\+r\').', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes', ) end diff --git a/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb b/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb index e2a04822..e634f28c 100644 --- a/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +++ b/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb @@ -24,7 +24,7 @@ def check column: value_token.column, token: value_token, description: 'Check the tokens of each File resource instance for a mode parameter ' \ - 'and if found, record a warning if the value of that parameter is not a quoted string.', + 'and if found, record a warning if the value of that parameter is not a quoted string.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes', ) end diff --git a/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb b/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb index 63c40535..f79553db 100644 --- a/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +++ b/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb @@ -20,7 +20,7 @@ def check column: token.column, token: token, description: 'Check the manifest tokens for any double quoted strings that don\'t ' \ - 'contain any variables or common escape characters and record a warning for each instance found.', + 'contain any variables or common escape characters and record a warning for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting', ) end diff --git a/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb b/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb index 4d14338e..04a69183 100644 --- a/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +++ b/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb @@ -29,4 +29,4 @@ def fix(problem) problem[:token].type = problem[:token].value.upcase.to_sym end end -PuppetLint.configuration.send('disable_quoted_booleans') +PuppetLint.configuration.send(:disable_quoted_booleans) diff --git a/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb b/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb index 69bbc3cf..aa269255 100644 --- a/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +++ b/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb @@ -15,7 +15,7 @@ def check line: token.line, column: token.column, description: 'Check the manifest tokens for any single quoted strings containing ' \ - 'a enclosed variable and record an error for each instance found.', + 'a enclosed variable and record an error for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting', ) end diff --git a/lib/puppet-lint/plugins/check_whitespace/80chars.rb b/lib/puppet-lint/plugins/check_whitespace/80chars.rb index 87321b64..ad1e6d91 100644 --- a/lib/puppet-lint/plugins/check_whitespace/80chars.rb +++ b/lib/puppet-lint/plugins/check_whitespace/80chars.rb @@ -13,4 +13,4 @@ def check end end end -PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send(:disable_80chars) diff --git a/lib/puppet-lint/plugins/check_whitespace/line_length.rb b/lib/puppet-lint/plugins/check_whitespace/line_length.rb index c3ea70fa..dafe700a 100644 --- a/lib/puppet-lint/plugins/check_whitespace/line_length.rb +++ b/lib/puppet-lint/plugins/check_whitespace/line_length.rb @@ -22,7 +22,7 @@ def self.check(line_number, content, character_count) line: line_number, column: character_count, description: 'Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. ' \ - 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', + 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace', ] end diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index a648a9bf..28f77f7c 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -55,8 +55,8 @@ end it 'calculates the column number for a multi line string' do - lexer.instance_variable_set('@line_no', 4) - lexer.instance_variable_set('@column', 5) + lexer.instance_variable_set(:@line_no, 4) + lexer.instance_variable_set(:@column, 5) lexer.new_token(:SSTRING, "test\ntest") token = lexer.new_token(:TEST, 'test') expect(token.column).to eq(6) diff --git a/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb b/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb index db820b2d..4717755b 100644 --- a/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb @@ -4,7 +4,7 @@ describe '80chars' do before(:each) do - PuppetLint.configuration.send('enable_80chars') + PuppetLint.configuration.send(:enable_80chars) end let(:msg) { 'line has more than 80 characters' } From 9f3d8c4b5e0455b561401879c9c2fdbf226c1768 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:33:11 +0100 Subject: [PATCH 06/56] (CONT-811) Correct Performance/StringInclude --- .../plugins/check_variables/variable_contains_dash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb b/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb index 32625f73..da839ef1 100644 --- a/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +++ b/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb @@ -11,7 +11,7 @@ def check end invalid_tokens.each do |token| - next unless %r{-}.match?(token.value.gsub(%r{\[.+?\]}, '')) + next unless token.value.gsub(%r{\[.+?\]}, '').include?('-') notify( :warning, From 1399d01db83c013719213a2753bcb8959202a14d Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:34:38 +0100 Subject: [PATCH 07/56] (CONT-811) Correct RSpec/BeEq --- spec/unit/puppet-lint/configuration_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet-lint/configuration_spec.rb b/spec/unit/puppet-lint/configuration_spec.rb index 3dbcc4d6..9925b11a 100644 --- a/spec/unit/puppet-lint/configuration_spec.rb +++ b/spec/unit/puppet-lint/configuration_spec.rb @@ -41,7 +41,7 @@ end it 'is able to add options on the fly' do - expect(config.test_option).to eq(nil) + expect(config.test_option).to be_nil config.test_option = 'test' From 02757e95fbeec8300a9c93ea45213dbc0a5f6f04 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:35:35 +0100 Subject: [PATCH 08/56] (CONT-811) Correct RSpec/ExcessiveDocstringSpacing --- spec/unit/puppet-lint/bin_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet-lint/bin_spec.rb b/spec/unit/puppet-lint/bin_spec.rb index ad841d2f..3374f3e3 100644 --- a/spec/unit/puppet-lint/bin_spec.rb +++ b/spec/unit/puppet-lint/bin_spec.rb @@ -168,7 +168,7 @@ def initialize(args) end end - context 'when asked to display filenames ' do + context 'when asked to display filenames' do let(:args) do [ '--with-filename', From 184ca8aa83a88cb095b35487545e95ca7b6814ed Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 11:36:44 +0100 Subject: [PATCH 09/56] (CONT-811) Correct Security/IoMethods --- lib/puppet-lint/tasks/puppet-lint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/tasks/puppet-lint.rb b/lib/puppet-lint/tasks/puppet-lint.rb index cd0e2524..852fd4ad 100644 --- a/lib/puppet-lint/tasks/puppet-lint.rb +++ b/lib/puppet-lint/tasks/puppet-lint.rb @@ -102,7 +102,7 @@ def define(args, &task_block) all_problems << linter.print_problems if PuppetLint.configuration.fix && linter.problems.none? { |e| e[:check] == :syntax } - IO.write(puppet_file, linter.manifest) + File.write(puppet_file, linter.manifest) end end From 377b3507ad2ec6c0891e2ff5bcc30798fa7a92ae Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 15:51:39 +0100 Subject: [PATCH 10/56] (CONT-811) disabling Style/ClassAndModuleChildren issues --- lib/puppet-lint/lexer/string_slurper.rb | 1 + lib/puppet-lint/lexer/token.rb | 1 + lib/puppet-lint/report/codeclimate.rb | 1 + lib/puppet-lint/report/github.rb | 1 + 4 files changed, 4 insertions(+) diff --git a/lib/puppet-lint/lexer/string_slurper.rb b/lib/puppet-lint/lexer/string_slurper.rb index c1426be9..403af9c8 100644 --- a/lib/puppet-lint/lexer/string_slurper.rb +++ b/lib/puppet-lint/lexer/string_slurper.rb @@ -1,5 +1,6 @@ require 'strscan' +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Lexer # Internal: A class for slurping strings from a Puppet manifest. class StringSlurper diff --git a/lib/puppet-lint/lexer/token.rb b/lib/puppet-lint/lexer/token.rb index 72720432..03fafce1 100644 --- a/lib/puppet-lint/lexer/token.rb +++ b/lib/puppet-lint/lexer/token.rb @@ -1,3 +1,4 @@ +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Lexer # Public: Stores a fragment of the manifest and the information about its # location in the manifest. diff --git a/lib/puppet-lint/report/codeclimate.rb b/lib/puppet-lint/report/codeclimate.rb index 56f31bb3..205010c4 100644 --- a/lib/puppet-lint/report/codeclimate.rb +++ b/lib/puppet-lint/report/codeclimate.rb @@ -3,6 +3,7 @@ require 'digest' require 'json' +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Report # Formats problems and writes them to a file as a code climate compatible report. class CodeClimateReporter diff --git a/lib/puppet-lint/report/github.rb b/lib/puppet-lint/report/github.rb index b6964c48..c7afc07c 100644 --- a/lib/puppet-lint/report/github.rb +++ b/lib/puppet-lint/report/github.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Report # This formatter formats report data as GitHub Workflow commands resulting # in GitHub check annotations when run within GitHub Actions. From ac3782153fae7ceee67d5d5cdb004c89595519df Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 15:53:52 +0100 Subject: [PATCH 11/56] (CONT-811) Correcting Style/EnvHome --- lib/puppet-lint/optparser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/optparser.rb b/lib/puppet-lint/optparser.rb index 22b0014f..6351ed21 100644 --- a/lib/puppet-lint/optparser.rb +++ b/lib/puppet-lint/optparser.rb @@ -143,7 +143,7 @@ def self.build(args = []) unless args.include?('--no-config') opt_parser.load('/etc/puppet-lint.rc') - if ENV.key?('HOME') && File.readable?(ENV['HOME']) + if ENV.key?('HOME') && File.readable?(Dir.home) home_dotfile_path = File.expand_path('~/.puppet-lint.rc') opt_parser.load(home_dotfile_path) if File.readable?(home_dotfile_path) end From fbb2e5f26b4af042d8741f0b650c97c94760e9f8 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 15:56:53 +0100 Subject: [PATCH 12/56] (CONT-811) Correct Style/FetchEnvVar --- lib/puppet-lint/data.rb | 2 +- lib/puppet-lint/tasks/release_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index 09707f04..ed4b9cb1 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -123,7 +123,7 @@ def path=(val) @fullpath = nil @filename = nil else - @fullpath = File.expand_path(val, ENV['PWD']) + @fullpath = File.expand_path(val, ENV.fetch('PWD', nil)) @filename = File.basename(val) end end diff --git a/lib/puppet-lint/tasks/release_test.rb b/lib/puppet-lint/tasks/release_test.rb index b908fd72..9ddc357b 100644 --- a/lib/puppet-lint/tasks/release_test.rb +++ b/lib/puppet-lint/tasks/release_test.rb @@ -58,9 +58,9 @@ def with_puppet_lint_head branch = if ENV['GITHUB_REF'] ENV['GITHUB_REF'] elsif ENV['APPVEYOR'] - ENV['APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH'] + ENV.fetch('APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH', nil) elsif ENV['TRAVIS'] - ENV['TRAVIS_PULL_REQUEST_BRANCH'] + ENV.fetch('TRAVIS_PULL_REQUEST_BRANCH', nil) else false end From 24ae53292ccc1ecf092d09deba0d81a08af9038e Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 15:58:01 +0100 Subject: [PATCH 13/56] (CONT-811) Correct Style/RedundantConstantBase --- lib/puppet-lint/tasks/puppet-lint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/tasks/puppet-lint.rb b/lib/puppet-lint/tasks/puppet-lint.rb index 852fd4ad..dda3ad0a 100644 --- a/lib/puppet-lint/tasks/puppet-lint.rb +++ b/lib/puppet-lint/tasks/puppet-lint.rb @@ -12,7 +12,7 @@ # # require 'puppet-lint' # PuppetLint::RakeTask.new -class PuppetLint::RakeTask < ::Rake::TaskLib +class PuppetLint::RakeTask < Rake::TaskLib include ::Rake::DSL if defined?(::Rake::DSL) DEFAULT_PATTERN = '**/*.pp'.freeze From e5b7577fb90053ff2aa3c61dd927d0e15b965592 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 15:59:16 +0100 Subject: [PATCH 14/56] (CONT-811) Correcting Style/RedundantStringEscape --- .../check_conditionals/case_without_default_spec.rb | 10 +++++----- .../check_strings/double_quoted_strings_spec.rb | 2 +- .../plugins/check_strings/only_variable_string_spec.rb | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb b/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb index e8b75f1c..d278129d 100644 --- a/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb @@ -87,15 +87,15 @@ let(:code) do <<-END $mem = inline_template('<% - mem,unit = scope.lookupvar(\'::memorysize\').split + mem,unit = scope.lookupvar('::memorysize').split mem = mem.to_f # Normalize mem to bytes case unit when nil: mem *= (1<<0) - when \'kB\': mem *= (1<<10) - when \'MB\': mem *= (1<<20) - when \'GB\': mem *= (1<<30) - when \'TB\': mem *= (1<<40) + when 'kB': mem *= (1<<10) + when 'MB': mem *= (1<<20) + when 'GB': mem *= (1<<30) + when 'TB': mem *= (1<<40) end %><%= mem.to_i %>') END diff --git a/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb b/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb index 0ac5ebcb..a71f4fae 100644 --- a/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb @@ -98,7 +98,7 @@ class puppet::master::maintenance ( <<-END $string1 = "this string contains \n newline" $string2 = "this string contains \t tab" - $string3 = "this string contains \${escaped} var" + $string3 = "this string contains ${escaped} var" $string4 = "this string contains \\"escaped \\" double quotes" $string5 = "this string contains \\'escaped \\' single quotes" $string6 = "this string contains \r carriage return" diff --git a/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb b/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb index 800ddc3c..4cef4c1a 100644 --- a/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb @@ -45,7 +45,7 @@ <<-END $bar = 'key' $foo = { - \"$bar\" => 1, + "$bar" => 1, } END end From e7912bfd4b3c5bd4a586fd37297c07d2f1b5fc12 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 16:00:53 +0100 Subject: [PATCH 15/56] (CONT-811) Correct Style/SafeNavigation --- .../plugins/check_classes/class_inherits_from_params_class.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb b/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb index e249a96e..56bdb63f 100644 --- a/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +++ b/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb @@ -5,7 +5,7 @@ PuppetLint.new_check(:class_inherits_from_params_class) do def check class_indexes.each do |class_idx| - next unless class_idx[:inherited_token] && class_idx[:inherited_token]&.value&.end_with?('::params') + next unless class_idx[:inherited_token]&.value&.end_with?('::params') notify( :warning, From 9adc84282b868a4aa611a57ca338e4ea08c7ee21 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 16:03:46 +0100 Subject: [PATCH 16/56] (CONT-811) Correct Style/TernaryParentheses --- lib/puppet-lint/lexer.rb | 6 +++--- lib/puppet-lint/lexer/token.rb | 4 ++-- .../plugins/check_classes/nested_classes_or_defines.rb | 2 +- .../plugins/check_classes/parameter_order_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index dc1eb85f..57e7f9a4 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -112,7 +112,7 @@ def heredoc_queue # \v == vertical tab # \f == form feed # \p{Zs} == ASCII + Unicode non-linebreaking whitespace - WHITESPACE_RE = RUBY_VERSION == '1.8.7' ? %r{[\t\v\f ]} : %r{[\t\v\f\p{Zs}]} + WHITESPACE_RE = (RUBY_VERSION == '1.8.7') ? %r{[\t\v\f ]} : %r{[\t\v\f\p{Zs}]} LINE_END_RE = %r{(?:\r\n|\r|\n)}.freeze @@ -419,7 +419,7 @@ def process_string_segments(segments) lexer = PuppetLint::Lexer.new lexer.tokenise(segment[1]) lexer.tokens.each_with_index do |t, i| - type = i.zero? && t.interpolated_variable? ? :VARIABLE : t.type + type = (i.zero? && t.interpolated_variable?) ? :VARIABLE : t.type tokens << new_token(type, t.value, raw: t.raw) end when :UNENC_VAR @@ -451,7 +451,7 @@ def process_heredoc_segments(segments) lexer = PuppetLint::Lexer.new lexer.tokenise(segment[1]) lexer.tokens.each_with_index do |t, i| - type = i.zero? && t.interpolated_variable? ? :VARIABLE : t.type + type = (i.zero? && t.interpolated_variable?) ? :VARIABLE : t.type tokens << new_token(type, t.value, raw: t.raw) end when :UNENC_VAR diff --git a/lib/puppet-lint/lexer/token.rb b/lib/puppet-lint/lexer/token.rb index 03fafce1..4f97ddd4 100644 --- a/lib/puppet-lint/lexer/token.rb +++ b/lib/puppet-lint/lexer/token.rb @@ -180,8 +180,8 @@ def find_token_of(direction, type, opts = {}) return token_iter if opts[:value].nil? || token_iter.value == opts[:value] end - opening_token = direction == :next ? 'L' : 'R' - closing_token = direction == :next ? 'R' : 'L' + opening_token = (direction == :next) ? 'L' : 'R' + closing_token = (direction == :next) ? 'R' : 'L' if opts[:skip_blocks] case token_iter.type diff --git a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb index a93712c5..b235bb18 100644 --- a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +++ b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb @@ -13,7 +13,7 @@ def check class_tokens.each do |token| next unless TOKENS.include?(token.type) next if token.next_code_token.type == :LBRACE - type = token.type == :CLASS ? 'class' : 'defined type' + type = (token.type == :CLASS) ? 'class' : 'defined type' notify( :warning, diff --git a/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb b/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb index c4bef2c9..52be7bcd 100644 --- a/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb @@ -27,7 +27,7 @@ expect(problems).to have(1).problem end - col = (type == 'class' ? 23 : 24) + col = ((type == 'class') ? 23 : 24) it 'creates a warning' do expect(problems).to contain_warning(msg).on_line(1).in_column(col) end @@ -58,7 +58,7 @@ expect(problems).to have(1).problem end - col = (type == 'class' ? 35 : 36) + col = ((type == 'class') ? 35 : 36) it 'creates a warning' do expect(problems).to contain_warning(msg).on_line(1).in_column(col) end From 2a292f692035881ab7a8f599b9cd0c330834c4cf Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 28 Mar 2023 16:08:18 +0100 Subject: [PATCH 17/56] (CONT-811) Updating rubocop and associated gems versions --- Gemfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index e52713ed..f172fbbc 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,7 @@ group :development do end group :rubocop do - gem 'rubocop', '~> 1.6.1', require: false - gem 'rubocop-rspec', '~> 2.0.1', require: false - gem 'rubocop-performance', '~> 1.9.1', require: false + gem 'rubocop', '~> 1.48.1', require: false + gem 'rubocop-rspec', '~> 2.19', require: false + gem 'rubocop-performance', '~> 1.16', require: false end From c8d98efaa68e8fdb1ee8516f7262116aa986145d Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 09:23:36 +0100 Subject: [PATCH 18/56] (CONT-811) Adding ruby 3.2 to workflow test matrices --- .github/workflows/ci.yml | 2 ++ .github/workflows/nightly.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9981a989..64541e92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: ruby_version: - '2.5' - '2.7' + - '3.2' name: "spec (ruby ${{ matrix.ruby_version }})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" @@ -28,6 +29,7 @@ jobs: ruby_version: - '2.5' - '2.7' + - '3.2' name: "acceptance (ruby ${{ matrix.ruby_version }})" needs: "spec" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 3674ba43..aab79f45 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -14,6 +14,7 @@ jobs: ruby_version: - '2.5' - '2.7' + - '3.2' name: "spec (ruby ${{ matrix.ruby_version }})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" @@ -27,6 +28,7 @@ jobs: ruby_version: - '2.5' - '2.7' + - '3.2' name: "acceptance (ruby ${{ matrix.ruby_version }})" needs: "spec" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" From 1c19e5e99cad45bb95e4146f2d646337c51fc5ce Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 13:47:57 +0100 Subject: [PATCH 19/56] (CONT-811) Enabling all cops. Removing all unconfigured cops. Including rubocop_todo for now until all cop conflicts are sorted. --- .rubocop.yml | 4 +- rubocop_baseline.yml | 443 +------------------------------------------ 2 files changed, 6 insertions(+), 441 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 903a5414..a52a34e8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,3 @@ -inherit_from: rubocop_baseline.yml +inherit_from: + - rubocop_baseline.yml + - .rubocop_todo.yml diff --git a/rubocop_baseline.yml b/rubocop_baseline.yml index e47cbcb1..4cf2aa0f 100644 --- a/rubocop_baseline.yml +++ b/rubocop_baseline.yml @@ -3,6 +3,9 @@ require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable + ExtraDetails: true + DisplayStyleGuide: true TargetRubyVersion: '2.7' DisplayCopNames: true SuggestExtensions: false @@ -78,443 +81,3 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false -RSpec/FilePath: - Enabled: false From 2111c6d7cc97d5ea0a2ab3e3c96b206abfa0cf5a Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 13:54:07 +0100 Subject: [PATCH 20/56] (CONT-811) Adding rubocop_todo --- .rubocop_todo.yml | 416 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 416 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..e22a0938 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,416 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-03-29 10:44:50 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 20 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterGuardClause: + Enabled: false + +# Offense count: 100 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'lib/puppet-lint/bin.rb' + - 'lib/puppet-lint/lexer.rb' + - 'lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb' + - 'spec/unit/puppet-lint/configuration_spec.rb' + +# Offense count: 25 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb' + - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' + - 'lib/puppet-lint/plugins/check_documentation/documentation.rb' + - 'lib/puppet-lint/plugins/check_resources/file_mode.rb' + - 'lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb' + - 'lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb' + - 'lib/puppet-lint/plugins/check_strings/only_variable_string.rb' + - 'lib/puppet-lint/plugins/check_strings/quoted_booleans.rb' + - 'lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb' + - 'lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb' + - 'lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb' + - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' + - 'lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb' + - 'lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb' + - 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb' + +# Offense count: 4 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'lib/puppet-lint/lexer/string_slurper.rb' + - 'lib/puppet-lint/lexer/token.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/InterpolationCheck: + Exclude: + - 'lib/puppet-lint/plugins/check_whitespace/line_length.rb' + +# Offense count: 9 +# Configuration parameters: MaximumRangeSize. +Lint/MissingCopEnableDirective: + Exclude: + - 'lib/puppet-lint.rb' + - 'lib/puppet-lint/lexer.rb' + - 'lib/puppet-lint/lexer/string_slurper.rb' + - 'lib/puppet-lint/lexer/token.rb' + - 'lib/puppet-lint/report/codeclimate.rb' + - 'lib/puppet-lint/report/github.rb' + - 'lib/puppet-lint/tasks/puppet-lint.rb' + - 'spec/unit/puppet-lint/puppet-lint_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/NonDeterministicRequireOrder: + Exclude: + - 'lib/puppet-lint/plugins.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantRequireStatement: + Exclude: + - 'lib/puppet-lint/lexer.rb' + +# Offense count: 58 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 142 + +# Offense count: 35 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 145 + +# Offense count: 2 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 5 + +# Offense count: 7 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 393 + +# Offense count: 33 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 33 + +# Offense count: 81 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 108 + +# Offense count: 26 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 32 + +# Offense count: 182 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Enabled: false + +# Offense count: 2 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/puppet-lint/monkeypatches.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Performance/BindCall: + Exclude: + - 'lib/puppet-lint/monkeypatches.rb' + +# Offense count: 7 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'lib/puppet-lint/bin.rb' + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb' + - 'lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SafeMultiline. +Performance/DeletePrefix: + Exclude: + - 'lib/puppet-lint/lexer.rb' + - 'spec/spec_helper.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +RSpec/ContextMethod: + Exclude: + - 'spec/unit/puppet-lint/lexer_spec.rb' + +# Offense count: 408 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Enabled: false + +# Offense count: 41 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Enabled: false + +# Offense count: 17 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterExample: + Exclude: + - 'spec/unit/puppet-lint/bin_spec.rb' + - 'spec/unit/puppet-lint/lexer_spec.rb' + - 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb' + +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +RSpec/EmptyLineAfterExampleGroup: + Exclude: + - 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb' + - 'spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb' + +# Offense count: 50 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 148 + +# Offense count: 8 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Exclude: + - 'spec/unit/puppet-lint/bin_spec.rb' + - 'spec/unit/puppet-lint/checks_spec.rb' + - 'spec/unit/puppet-lint/configuration_spec.rb' + - 'spec/unit/puppet-lint/data_spec.rb' + - 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb' + - 'spec/unit/puppet-lint/lexer/token_spec.rb' + - 'spec/unit/puppet-lint/lexer_spec.rb' + - 'spec/unit/puppet-lint/puppet-lint_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit +RSpec/ImplicitSubject: + Exclude: + - 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb' + +# Offense count: 138 +RSpec/MultipleExpectations: + Max: 137 + +# Offense count: 3 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 13 + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +RSpec/MultipleSubjects: + Exclude: + - 'spec/unit/puppet-lint/lexer_spec.rb' + +# Offense count: 52 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 5 + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. +# SupportedStyles: inflected, explicit +RSpec/PredicateMatcher: + Exclude: + - 'spec/unit/puppet-lint/configuration_spec.rb' + +# Offense count: 8 +RSpec/RepeatedExampleGroupDescription: + Exclude: + - 'spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb' + - 'spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb' + - 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb' + +# Offense count: 16 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: separated, grouped +Style/AccessorGrouping: + Exclude: + - 'lib/puppet-lint/lexer/string_slurper.rb' + - 'lib/puppet-lint/tasks/puppet-lint.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: MinBranchesCount. +Style/CaseLikeIf: + Exclude: + - 'lib/puppet-lint/plugins/check_classes/parameter_order.rb' + - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' + +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +Style/Encoding: + Exclude: + - 'lib/puppet-lint/lexer.rb' + - 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb' + - 'spec/unit/puppet-lint/lexer_spec.rb' + - 'spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb' + - 'spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/ExpandPathArguments: + Exclude: + - 'puppet-lint.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/ExplicitBlockArgument: + Exclude: + - 'lib/puppet-lint/tasks/release_test.rb' + +# Offense count: 106 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: braces, no_braces +Style/HashAsLastArrayItem: + Exclude: + - 'lib/puppet-lint/plugins/check_whitespace/line_length.rb' + +# Offense count: 16 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'lib/puppet-lint/bin.rb' + - 'lib/puppet-lint/checkplugin.rb' + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/plugins.rb' + - 'lib/puppet-lint/plugins/check_classes/autoloader_layout.rb' + - 'lib/puppet-lint/plugins/check_classes/parameter_order.rb' + - 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb' + - 'lib/puppet-lint/plugins/check_strings/only_variable_string.rb' + - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' + - 'lib/puppet-lint/tasks/puppet-lint.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' + +# Offense count: 4 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Methods. +Style/RedundantArgument: + Exclude: + - 'lib/puppet-lint/checks.rb' + - 'spec/unit/puppet-lint/lexer_spec.rb' + +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpEscape: + Exclude: + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/monkeypatches.rb' + - 'spec/unit/puppet-lint/bin_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/puppet-lint/checks.rb' + - 'lib/puppet-lint/monkeypatches.rb' + +# Offense count: 22 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/SlicingWithRange: + Exclude: + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/lexer.rb' + - 'lib/puppet-lint/plugins/check_classes/autoloader_layout.rb' + - 'lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb' + - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' + - 'lib/puppet-lint/plugins/check_conditionals/case_without_default.rb' + - 'lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/lexer/token.rb' + - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +Style/StderrPuts: + Exclude: + - 'lib/puppet-lint.rb' + - 'lib/puppet-lint/data.rb' + +# Offense count: 9 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/puppet-lint/bin.rb' + - 'lib/puppet-lint/plugins.rb' + - 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb' + - 'spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb' + +# Offense count: 21 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'lib/puppet-lint/bin.rb' + - 'lib/puppet-lint/checkplugin.rb' + - 'lib/puppet-lint/checks.rb' + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/lexer.rb' + - 'lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb' + - 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb' + - 'lib/puppet-lint/report/codeclimate.rb' + - 'spec/spec_helper.rb' + - 'spec/spec_helper_acceptance_local.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/UnpackFirst: + Exclude: + - 'lib/puppet-lint.rb' From 8de3c98406c803629a10411016e04a02f488e2d9 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 13:54:33 +0100 Subject: [PATCH 21/56] (CONT-811) Dropping Ruby 2.5 from tests as Puppet 6 will not be supported --- .github/workflows/ci.yml | 2 -- .github/workflows/nightly.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64541e92..92293f1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,6 @@ jobs: fail-fast: false matrix: ruby_version: - - '2.5' - '2.7' - '3.2' name: "spec (ruby ${{ matrix.ruby_version }})" @@ -27,7 +26,6 @@ jobs: fail-fast: false matrix: ruby_version: - - '2.5' - '2.7' - '3.2' name: "acceptance (ruby ${{ matrix.ruby_version }})" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index aab79f45..75df5b7b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -12,7 +12,6 @@ jobs: fail-fast: false matrix: ruby_version: - - '2.5' - '2.7' - '3.2' name: "spec (ruby ${{ matrix.ruby_version }})" @@ -26,7 +25,6 @@ jobs: fail-fast: false matrix: ruby_version: - - '2.5' - '2.7' - '3.2' name: "acceptance (ruby ${{ matrix.ruby_version }})" From 8a90792a6b12e20be6224519be640a2e8ba089ed Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 14:20:57 +0100 Subject: [PATCH 22/56] (CONT-811) Raising minimum required ruby version in gemspec --- puppet-lint.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet-lint.gemspec b/puppet-lint.gemspec index 23b420ef..57a008ad 100644 --- a/puppet-lint.gemspec +++ b/puppet-lint.gemspec @@ -32,6 +32,6 @@ Gem::Specification.new do |spec| ] spec.license = 'MIT' - spec.required_ruby_version = Gem::Requirement.new('>= 2.5'.freeze) + spec.required_ruby_version = Gem::Requirement.new('>= 2.7'.freeze) spec.metadata['rubygems_mfa_required'] = 'true' end From d39a1d0846d1a029a3a1203abb4cdb5f400e2b45 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 15:47:52 +0100 Subject: [PATCH 23/56] (CONT-811) Correct Layout/EmptyLineAfterGuardClause --- lib/puppet-lint.rb | 2 ++ lib/puppet-lint/bin.rb | 2 ++ lib/puppet-lint/data.rb | 2 ++ lib/puppet-lint/lexer/token.rb | 2 ++ lib/puppet-lint/plugins.rb | 1 + .../plugins/check_classes/arrow_on_right_operand_line.rb | 1 + .../plugins/check_classes/nested_classes_or_defines.rb | 1 + lib/puppet-lint/plugins/check_documentation/documentation.rb | 1 + lib/puppet-lint/plugins/check_strings/only_variable_string.rb | 1 + lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb | 1 + lib/puppet-lint/plugins/check_whitespace/140chars.rb | 1 + lib/puppet-lint/plugins/check_whitespace/80chars.rb | 1 + lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb | 1 + lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb | 1 + lib/puppet-lint/tasks/puppet-lint.rb | 1 + spec/spec_helper.rb | 1 + 16 files changed, 20 insertions(+) diff --git a/lib/puppet-lint.rb b/lib/puppet-lint.rb index b5fda9da..6ef82944 100644 --- a/lib/puppet-lint.rb +++ b/lib/puppet-lint.rb @@ -155,8 +155,10 @@ def get_context(message) def print_context(message) return if message[:check] == 'documentation' return if message[:kind] == :fixed + line = message[:context] return unless line + offset = line.index(%r{\S}) || 1 puts "\n #{line.strip}" printf("%#{message[:column] + 2 - offset}s\n\n", '^') diff --git a/lib/puppet-lint/bin.rb b/lib/puppet-lint/bin.rb index 7b2fff4a..70f453e2 100644 --- a/lib/puppet-lint/bin.rb +++ b/lib/puppet-lint/bin.rb @@ -79,6 +79,7 @@ def run path.each do |f| next if ignore_paths.any? { |p| File.fnmatch(p, f) } + l = PuppetLint.new l.file = f l.run @@ -89,6 +90,7 @@ def run end next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax } + File.binwrite(f, l.manifest) end diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index ed4b9cb1..900cd950 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -186,10 +186,12 @@ def resource_indexes rel_start_idx = tokens[marker..-1].index(colon_token) break if rel_start_idx.nil? + start_idx = rel_start_idx + marker end_token = colon_token.next_token_of([:SEMIC, :RBRACE]) rel_end_idx = tokens[start_idx..-1].index(end_token) raise PuppetLint::SyntaxError, colon_token if rel_end_idx.nil? + marker = rel_end_idx + start_idx result << { diff --git a/lib/puppet-lint/lexer/token.rb b/lib/puppet-lint/lexer/token.rb index 4f97ddd4..1b4d509b 100644 --- a/lib/puppet-lint/lexer/token.rb +++ b/lib/puppet-lint/lexer/token.rb @@ -195,6 +195,7 @@ def find_token_of(direction, type, opts = {}) end return nil if token_iter.nil? + token_iter = token_iter.send("#{direction}_token".to_sym) end nil @@ -203,6 +204,7 @@ def find_token_of(direction, type, opts = {}) def interpolated_variable? return false if type == :TYPE && value != 'type' return true if type == :NAME + PuppetLint::Lexer::KEYWORDS.include?(type.to_s.downcase) end end diff --git a/lib/puppet-lint/plugins.rb b/lib/puppet-lint/plugins.rb index 49168723..cc5cb13c 100644 --- a/lib/puppet-lint/plugins.rb +++ b/lib/puppet-lint/plugins.rb @@ -58,6 +58,7 @@ def load_prerelease_plugins? if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'] return ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase) end + false end diff --git a/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb b/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb index e338a598..a891c410 100644 --- a/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +++ b/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb @@ -35,6 +35,7 @@ def fix(problem) # Remove trailing whitespace after left operand (if it exists) return unless left_operand_token.next_token.type == :WHITESPACE + trailing_whitespace_token = left_operand_token.next_token remove_token(trailing_whitespace_token) if [:NEWLINE, :WHITESPACE].include?(trailing_whitespace_token.next_token.type) end diff --git a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb index b235bb18..2e041176 100644 --- a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +++ b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb @@ -13,6 +13,7 @@ def check class_tokens.each do |token| next unless TOKENS.include?(token.type) next if token.next_code_token.type == :LBRACE + type = (token.type == :CLASS) ? 'class' : 'defined type' notify( diff --git a/lib/puppet-lint/plugins/check_documentation/documentation.rb b/lib/puppet-lint/plugins/check_documentation/documentation.rb index 71d8bd01..02a37f49 100644 --- a/lib/puppet-lint/plugins/check_documentation/documentation.rb +++ b/lib/puppet-lint/plugins/check_documentation/documentation.rb @@ -40,6 +40,7 @@ def find_comment_token(start_token) while !prev_token.nil? && WHITESPACE_TOKENS.include?(prev_token.type) newlines += 1 if prev_token.type == :NEWLINE break if newlines > 1 + prev_token = prev_token.prev_token end diff --git a/lib/puppet-lint/plugins/check_strings/only_variable_string.rb b/lib/puppet-lint/plugins/check_strings/only_variable_string.rb index d74fddc1..be80be71 100644 --- a/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +++ b/lib/puppet-lint/plugins/check_strings/only_variable_string.rb @@ -23,6 +23,7 @@ def check if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW break end + notify( :warning, message: 'string containing only a variable', diff --git a/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb b/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb index ac1faeb4..251b5598 100644 --- a/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +++ b/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb @@ -74,6 +74,7 @@ def handle_variable_containing_dash(var_token) var_token.value = var_name return if str_token.nil? + str_token.value = "-#{text}#{str_token.value}" end diff --git a/lib/puppet-lint/plugins/check_whitespace/140chars.rb b/lib/puppet-lint/plugins/check_whitespace/140chars.rb index 5f21cd17..bc63d095 100644 --- a/lib/puppet-lint/plugins/check_whitespace/140chars.rb +++ b/lib/puppet-lint/plugins/check_whitespace/140chars.rb @@ -10,6 +10,7 @@ def check result = PuppetLint::LineLengthCheck.check(idx + 1, line, 140) next if result.nil? + notify(*result) end end diff --git a/lib/puppet-lint/plugins/check_whitespace/80chars.rb b/lib/puppet-lint/plugins/check_whitespace/80chars.rb index ad1e6d91..e1f143fe 100644 --- a/lib/puppet-lint/plugins/check_whitespace/80chars.rb +++ b/lib/puppet-lint/plugins/check_whitespace/80chars.rb @@ -9,6 +9,7 @@ def check result = PuppetLint::LineLengthCheck.check(idx + 1, line, 80) next if result.nil? + notify(*result) end end diff --git a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb index cbaa42d5..75cfa478 100644 --- a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +++ b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb @@ -118,6 +118,7 @@ def fix(problem) end raise PuppetLint::NoFix if new_ws_len < 0 + new_ws = ' ' * new_ws_len if problem[:token].prev_token.type == :WHITESPACE diff --git a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb index 6fad162e..013305b3 100644 --- a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +++ b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb @@ -137,6 +137,7 @@ def check end next unless EASY_FACTS.include?(fact_name) || UNCONVERTIBLE_FACTS.include?(fact_name) || fact_name.match(Regexp.union(REGEX_FACTS)) + notify :warning, { message: "legacy fact '#{fact_name}'", line: token.line, diff --git a/lib/puppet-lint/tasks/puppet-lint.rb b/lib/puppet-lint/tasks/puppet-lint.rb index dda3ad0a..fe37d642 100644 --- a/lib/puppet-lint/tasks/puppet-lint.rb +++ b/lib/puppet-lint/tasks/puppet-lint.rb @@ -97,6 +97,7 @@ def define(args, &task_block) matched_files.to_a.each do |puppet_file| next unless File.file?(puppet_file) + linter.file = puppet_file linter.run all_problems << linter.print_problems diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 695e35f7..d54c5ece 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -100,6 +100,7 @@ def failure_message_when_negated def method_missing(method, *args, &block) return HaveProblem.new(method, args.first) if method.to_s.start_with?('contain_') + super end From 5fe25d19e444a9686292a47dc71e7405b2f9f56a Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Wed, 29 Mar 2023 15:50:51 +0100 Subject: [PATCH 24/56] (CONT-811) Correct Layout/HashAlignment --- lib/puppet-lint/bin.rb | 2 +- lib/puppet-lint/lexer.rb | 44 +++--- .../plugins/legacy_facts/legacy_facts.rb | 132 +++++++++--------- spec/unit/puppet-lint/configuration_spec.rb | 22 +-- 4 files changed, 100 insertions(+), 100 deletions(-) diff --git a/lib/puppet-lint/bin.rb b/lib/puppet-lint/bin.rb index 70f453e2..9e3edeb4 100644 --- a/lib/puppet-lint/bin.rb +++ b/lib/puppet-lint/bin.rb @@ -148,7 +148,7 @@ def report_sarif(problems, base_path, base_path_uri) 'ruleIndex' => rule_index, 'message' => { 'text' => message[:message] }, 'locations' => [{ 'physicalLocation' => { 'artifactLocation' => { 'uri' => relative_path, 'uriBaseId' => 'ROOTPATH' }, -'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }], + 'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }], } results << result end diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index 57e7f9a4..90b36853 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -56,27 +56,27 @@ def heredoc_queue # From https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/parser/lexer2.rb#L116-L137 # or thereabouts KEYWORDS = { - 'case' => true, - 'class' => true, - 'default' => true, - 'define' => true, - 'import' => true, - 'if' => true, - 'elsif' => true, - 'else' => true, + 'case' => true, + 'class' => true, + 'default' => true, + 'define' => true, + 'import' => true, + 'if' => true, + 'elsif' => true, + 'else' => true, 'inherits' => true, - 'node' => true, - 'and' => true, - 'or' => true, - 'undef' => true, - 'false' => true, - 'true' => true, - 'in' => true, - 'unless' => true, + 'node' => true, + 'and' => true, + 'or' => true, + 'undef' => true, + 'false' => true, + 'true' => true, + 'in' => true, + 'unless' => true, 'function' => true, - 'type' => true, - 'attr' => true, - 'private' => true, + 'type' => true, + 'attr' => true, + 'private' => true, }.freeze # Internal: A Hash whose keys are Strings representing reserved keywords in @@ -86,9 +86,9 @@ def heredoc_queue # Currently unused APP_MANAGEMENT_TOKENS = { 'application' => true, - 'consumes' => true, - 'produces' => true, - 'site' => true, + 'consumes' => true, + 'produces' => true, + 'site' => true, }.freeze # Internal: A Hash whose keys are Symbols representing token types which diff --git a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb index 013305b3..50ce5f6c 100644 --- a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +++ b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb @@ -34,74 +34,74 @@ # These facts have a one to one correlation between a legacy fact and a new # structured fact. EASY_FACTS = { - 'architecture' => "facts['os']['architecture']", - 'augeasversion' => "facts['augeas']['version']", - 'bios_release_date' => "facts['dmi']['bios']['release_date']", - 'bios_vendor' => "facts['dmi']['bios']['vendor']", - 'bios_version' => "facts['dmi']['bios']['version']", - 'boardassettag' => "facts['dmi']['board']['asset_tag']", - 'boardmanufacturer' => "facts['dmi']['board']['manufacturer']", - 'boardproductname' => "facts['dmi']['board']['product']", - 'boardserialnumber' => "facts['dmi']['board']['serial_number']", - 'chassisassettag' => "facts['dmi']['chassis']['asset_tag']", - 'chassistype' => "facts['dmi']['chassis']['type']", - 'domain' => "facts['networking']['domain']", - 'fqdn' => "facts['networking']['fqdn']", - 'gid' => "facts['identity']['group']", - 'hardwareisa' => "facts['processors']['isa']", - 'hardwaremodel' => "facts['os']['hardware']", - 'hostname' => "facts['networking']['hostname']", - 'id' => "facts['identity']['user']", - 'ipaddress' => "facts['networking']['ip']", - 'ipaddress6' => "facts['networking']['ip6']", - 'lsbdistcodename' => "facts['os']['distro']['codename']", - 'lsbdistdescription' => "facts['os']['distro']['description']", - 'lsbdistid' => "facts['os']['distro']['id']", - 'lsbdistrelease' => "facts['os']['distro']['release']['full']", - 'lsbmajdistrelease' => "facts['os']['distro']['release']['major']", - 'lsbminordistrelease' => "facts['os']['distro']['release']['minor']", - 'lsbrelease' => "facts['os']['distro']['release']['specification']", - 'macaddress' => "facts['networking']['mac']", - 'macosx_buildversion' => "facts['os']['macosx']['build']", - 'macosx_productname' => "facts['os']['macosx']['product']", - 'macosx_productversion' => "facts['os']['macosx']['version']['full']", + 'architecture' => "facts['os']['architecture']", + 'augeasversion' => "facts['augeas']['version']", + 'bios_release_date' => "facts['dmi']['bios']['release_date']", + 'bios_vendor' => "facts['dmi']['bios']['vendor']", + 'bios_version' => "facts['dmi']['bios']['version']", + 'boardassettag' => "facts['dmi']['board']['asset_tag']", + 'boardmanufacturer' => "facts['dmi']['board']['manufacturer']", + 'boardproductname' => "facts['dmi']['board']['product']", + 'boardserialnumber' => "facts['dmi']['board']['serial_number']", + 'chassisassettag' => "facts['dmi']['chassis']['asset_tag']", + 'chassistype' => "facts['dmi']['chassis']['type']", + 'domain' => "facts['networking']['domain']", + 'fqdn' => "facts['networking']['fqdn']", + 'gid' => "facts['identity']['group']", + 'hardwareisa' => "facts['processors']['isa']", + 'hardwaremodel' => "facts['os']['hardware']", + 'hostname' => "facts['networking']['hostname']", + 'id' => "facts['identity']['user']", + 'ipaddress' => "facts['networking']['ip']", + 'ipaddress6' => "facts['networking']['ip6']", + 'lsbdistcodename' => "facts['os']['distro']['codename']", + 'lsbdistdescription' => "facts['os']['distro']['description']", + 'lsbdistid' => "facts['os']['distro']['id']", + 'lsbdistrelease' => "facts['os']['distro']['release']['full']", + 'lsbmajdistrelease' => "facts['os']['distro']['release']['major']", + 'lsbminordistrelease' => "facts['os']['distro']['release']['minor']", + 'lsbrelease' => "facts['os']['distro']['release']['specification']", + 'macaddress' => "facts['networking']['mac']", + 'macosx_buildversion' => "facts['os']['macosx']['build']", + 'macosx_productname' => "facts['os']['macosx']['product']", + 'macosx_productversion' => "facts['os']['macosx']['version']['full']", 'macosx_productversion_major' => "facts['os']['macosx']['version']['major']", 'macosx_productversion_minor' => "facts['os']['macosx']['version']['minor']", - 'manufacturer' => "facts['dmi']['manufacturer']", - 'memoryfree' => "facts['memory']['system']['available']", - 'memorysize' => "facts['memory']['system']['total']", - 'netmask' => "facts['networking']['netmask']", - 'netmask6' => "facts['networking']['netmask6']", - 'network' => "facts['networking']['network']", - 'network6' => "facts['networking']['network6']", - 'operatingsystem' => "facts['os']['name']", - 'operatingsystemmajrelease' => "facts['os']['release']['major']", - 'operatingsystemrelease' => "facts['os']['release']['full']", - 'osfamily' => "facts['os']['family']", - 'physicalprocessorcount' => "facts['processors']['physicalcount']", - 'processorcount' => "facts['processors']['count']", - 'productname' => "facts['dmi']['product']['name']", - 'rubyplatform' => "facts['ruby']['platform']", - 'rubysitedir' => "facts['ruby']['sitedir']", - 'rubyversion' => "facts['ruby']['version']", - 'selinux' => "facts['os']['selinux']['enabled']", - 'selinux_config_mode' => "facts['os']['selinux']['config_mode']", - 'selinux_config_policy' => "facts['os']['selinux']['config_policy']", - 'selinux_current_mode' => "facts['os']['selinux']['current_mode']", - 'selinux_enforced' => "facts['os']['selinux']['enforced']", - 'selinux_policyversion' => "facts['os']['selinux']['policy_version']", - 'serialnumber' => "facts['dmi']['product']['serial_number']", - 'swapencrypted' => "facts['memory']['swap']['encrypted']", - 'swapfree' => "facts['memory']['swap']['available']", - 'swapsize' => "facts['memory']['swap']['total']", - 'system32' => "facts['os']['windows']['system32']", - 'uptime' => "facts['system_uptime']['uptime']", - 'uptime_days' => "facts['system_uptime']['days']", - 'uptime_hours' => "facts['system_uptime']['hours']", - 'uptime_seconds' => "facts['system_uptime']['seconds']", - 'uuid' => "facts['dmi']['product']['uuid']", - 'xendomains' => "facts['xen']['domains']", - 'zonename' => "facts['solaris_zones']['current']", + 'manufacturer' => "facts['dmi']['manufacturer']", + 'memoryfree' => "facts['memory']['system']['available']", + 'memorysize' => "facts['memory']['system']['total']", + 'netmask' => "facts['networking']['netmask']", + 'netmask6' => "facts['networking']['netmask6']", + 'network' => "facts['networking']['network']", + 'network6' => "facts['networking']['network6']", + 'operatingsystem' => "facts['os']['name']", + 'operatingsystemmajrelease' => "facts['os']['release']['major']", + 'operatingsystemrelease' => "facts['os']['release']['full']", + 'osfamily' => "facts['os']['family']", + 'physicalprocessorcount' => "facts['processors']['physicalcount']", + 'processorcount' => "facts['processors']['count']", + 'productname' => "facts['dmi']['product']['name']", + 'rubyplatform' => "facts['ruby']['platform']", + 'rubysitedir' => "facts['ruby']['sitedir']", + 'rubyversion' => "facts['ruby']['version']", + 'selinux' => "facts['os']['selinux']['enabled']", + 'selinux_config_mode' => "facts['os']['selinux']['config_mode']", + 'selinux_config_policy' => "facts['os']['selinux']['config_policy']", + 'selinux_current_mode' => "facts['os']['selinux']['current_mode']", + 'selinux_enforced' => "facts['os']['selinux']['enforced']", + 'selinux_policyversion' => "facts['os']['selinux']['policy_version']", + 'serialnumber' => "facts['dmi']['product']['serial_number']", + 'swapencrypted' => "facts['memory']['swap']['encrypted']", + 'swapfree' => "facts['memory']['swap']['available']", + 'swapsize' => "facts['memory']['swap']['total']", + 'system32' => "facts['os']['windows']['system32']", + 'uptime' => "facts['system_uptime']['uptime']", + 'uptime_days' => "facts['system_uptime']['days']", + 'uptime_hours' => "facts['system_uptime']['hours']", + 'uptime_seconds' => "facts['system_uptime']['seconds']", + 'uuid' => "facts['dmi']['product']['uuid']", + 'xendomains' => "facts['xen']['domains']", + 'zonename' => "facts['solaris_zones']['current']", }.freeze # A list of valid hash key token types diff --git a/spec/unit/puppet-lint/configuration_spec.rb b/spec/unit/puppet-lint/configuration_spec.rb index 9925b11a..0dc50503 100644 --- a/spec/unit/puppet-lint/configuration_spec.rb +++ b/spec/unit/puppet-lint/configuration_spec.rb @@ -55,18 +55,18 @@ end expect(config.settings).to eq( - 'with_filename' => false, - 'fail_on_warnings' => false, + 'with_filename' => false, + 'fail_on_warnings' => false, 'codeclimate_report_file' => nil, - 'error_level' => :all, - 'log_format' => '', - 'sarif' => false, - 'with_context' => false, - 'fix' => false, - 'github_actions' => false, - 'show_ignored' => false, - 'json' => false, - 'ignore_paths' => ['vendor/**/*.pp'], + 'error_level' => :all, + 'log_format' => '', + 'sarif' => false, + 'with_context' => false, + 'fix' => false, + 'github_actions' => false, + 'show_ignored' => false, + 'json' => false, + 'ignore_paths' => ['vendor/**/*.pp'], ) end From efd1526816be2e4d3f1e5194ad46e2ec9b1f0ffb Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Thu, 30 Mar 2023 10:18:39 +0100 Subject: [PATCH 25/56] (CONT-811) Correct Lint/ConstantDefinitionInBlock --- .../nested_classes_or_defines.rb | 5 +- .../plugins/check_classes/variable_scope.rb | 56 ++--- .../check_documentation/documentation.rb | 6 +- .../plugins/check_resources/file_mode.rb | 10 +- .../check_resources/unquoted_file_mode.rb | 4 +- .../check_strings/double_quoted_strings.rb | 4 +- .../check_strings/only_variable_string.rb | 4 +- .../plugins/check_strings/quoted_booleans.rb | 6 +- .../check_strings/variables_not_enclosed.rb | 14 +- .../check_variables/variable_contains_dash.rb | 4 +- .../check_variables/variable_is_lowercase.rb | 4 +- .../check_whitespace/arrow_alignment.rb | 4 +- .../plugins/check_whitespace/hard_tabs.rb | 4 +- .../plugins/legacy_facts/legacy_facts.rb | 208 +++++++++--------- .../top_scope_facts/top_scope_facts.rb | 3 +- 15 files changed, 168 insertions(+), 168 deletions(-) diff --git a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb index 2e041176..e7f5aae4 100644 --- a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +++ b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb @@ -2,16 +2,15 @@ # defined inside another class. # # https://puppet.com/docs/puppet/latest/style_guide.html#nested-classes-or-defined-types +CLASS_DEFINE_TOKENS = Set[:CLASS, :DEFINE] PuppetLint.new_check(:nested_classes_or_defines) do - TOKENS = Set[:CLASS, :DEFINE] - def check class_indexes.each do |class_idx| # Skip the first token so that we don't pick up the first :CLASS class_tokens = class_idx[:tokens][1..-1] class_tokens.each do |token| - next unless TOKENS.include?(token.type) + next unless CLASS_DEFINE_TOKENS.include?(token.type) next if token.next_code_token.type == :LBRACE type = (token.type == :CLASS) ? 'class' : 'defined type' diff --git a/lib/puppet-lint/plugins/check_classes/variable_scope.rb b/lib/puppet-lint/plugins/check_classes/variable_scope.rb index 9e67a2e9..57da19bf 100644 --- a/lib/puppet-lint/plugins/check_classes/variable_scope.rb +++ b/lib/puppet-lint/plugins/check_classes/variable_scope.rb @@ -5,35 +5,35 @@ # not. # # https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables -PuppetLint.new_check(:variable_scope) do - DEFAULT_SCOPE_VARS = Set[ - 'name', - 'title', - 'module_name', - 'environment', - 'clientcert', - 'clientversion', - 'servername', - 'serverip', - 'serverversion', - 'caller_module_name', - 'alias', - 'audit', - 'before', - 'loglevel', - 'noop', - 'notify', - 'require', - 'schedule', - 'stage', - 'subscribe', - 'tag', - 'facts', - 'trusted', - 'server_facts', - ] - POST_VAR_TOKENS = Set[:COMMA, :EQUALS, :RPAREN] +DEFAULT_SCOPE_VARS = Set[ + 'name', + 'title', + 'module_name', + 'environment', + 'clientcert', + 'clientversion', + 'servername', + 'serverip', + 'serverversion', + 'caller_module_name', + 'alias', + 'audit', + 'before', + 'loglevel', + 'noop', + 'notify', + 'require', + 'schedule', + 'stage', + 'subscribe', + 'tag', + 'facts', + 'trusted', + 'server_facts', +] +POST_VAR_TOKENS = Set[:COMMA, :EQUALS, :RPAREN] +PuppetLint.new_check(:variable_scope) do def check variables_in_scope = DEFAULT_SCOPE_VARS.clone diff --git a/lib/puppet-lint/plugins/check_documentation/documentation.rb b/lib/puppet-lint/plugins/check_documentation/documentation.rb index 02a37f49..a0549298 100644 --- a/lib/puppet-lint/plugins/check_documentation/documentation.rb +++ b/lib/puppet-lint/plugins/check_documentation/documentation.rb @@ -3,10 +3,10 @@ # record a warning for each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private -PuppetLint.new_check(:documentation) do - COMMENT_TOKENS = Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT] - WHITESPACE_TOKENS = Set[:WHITESPACE, :NEWLINE, :INDENT] +COMMENT_TOKENS = Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT] +WHITESPACE_TOKENS = Set[:WHITESPACE, :NEWLINE, :INDENT] +PuppetLint.new_check(:documentation) do def check (class_indexes + defined_type_indexes).each do |item_idx| comment_token = find_comment_token(item_idx[:tokens].first) diff --git a/lib/puppet-lint/plugins/check_resources/file_mode.rb b/lib/puppet-lint/plugins/check_resources/file_mode.rb index 156b645c..5e7e0299 100644 --- a/lib/puppet-lint/plugins/check_resources/file_mode.rb +++ b/lib/puppet-lint/plugins/check_resources/file_mode.rb @@ -3,12 +3,12 @@ # not a 4 digit octal value (0755) or a symbolic mode ('o=rwx,g+r'). # # https://puppet.com/docs/puppet/latest/style_guide.html#file-modes -PuppetLint.new_check(:file_mode) do - MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze - SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze - IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME] - MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze +MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze +SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze +IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME] +MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze +PuppetLint.new_check(:file_mode) do def check resource_indexes.each do |resource| next unless resource[:type].value == 'file' || resource[:type].value == 'concat' diff --git a/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb b/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb index e634f28c..8374745b 100644 --- a/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +++ b/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb @@ -3,9 +3,9 @@ # not a quoted string. # # https://puppet.com/docs/puppet/latest/style_guide.html#file-modes -PuppetLint.new_check(:unquoted_file_mode) do - TOKEN_TYPES = Set[:NAME, :NUMBER] +TOKEN_TYPES = Set[:NAME, :NUMBER] +PuppetLint.new_check(:unquoted_file_mode) do def check resource_indexes.each do |resource| next unless resource[:type].value == 'file' || resource[:type].value == 'concat' diff --git a/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb b/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb index f79553db..4fc3e945 100644 --- a/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +++ b/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb @@ -3,9 +3,9 @@ # each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#quoting -PuppetLint.new_check(:double_quoted_strings) do - ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze +ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze +PuppetLint.new_check(:double_quoted_strings) do def check invalid_tokens = tokens.select do |token| token.type == :STRING && diff --git a/lib/puppet-lint/plugins/check_strings/only_variable_string.rb b/lib/puppet-lint/plugins/check_strings/only_variable_string.rb index be80be71..2f7695c5 100644 --- a/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +++ b/lib/puppet-lint/plugins/check_strings/only_variable_string.rb @@ -2,9 +2,9 @@ # a single variable only and record a warning for each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#quoting -PuppetLint.new_check(:only_variable_string) do - VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +PuppetLint.new_check(:only_variable_string) do def check tokens.each_with_index do |start_token, start_token_idx| next unless start_token.type == :DQPRE && start_token.value == '' diff --git a/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb b/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb index 04a69183..2c26a9c0 100644 --- a/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +++ b/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb @@ -3,10 +3,10 @@ # found. # # No style guide reference -PuppetLint.new_check(:quoted_booleans) do - STRING_TYPES = Set[:STRING, :SSTRING] - BOOLEANS = Set['true', 'false'] +STRING_TYPES = Set[:STRING, :SSTRING] +BOOLEANS = Set['true', 'false'] +PuppetLint.new_check(:quoted_booleans) do def check invalid_tokens = tokens.select do |token| STRING_TYPES.include?(token.type) && BOOLEANS.include?(token.value) diff --git a/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb b/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb index 251b5598..945cee0a 100644 --- a/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +++ b/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb @@ -6,14 +6,14 @@ # found. # # https://puppet.com/docs/puppet/latest/style_guide.html#quoting -PuppetLint.new_check(:variables_not_enclosed) do - STRING_TOKEN_TYPES = Set[ - :DQMID, - :DQPOST, - :HEREDOC_MID, - :HEREDOC_POST, - ] +STRING_TOKEN_TYPES = Set[ + :DQMID, + :DQPOST, + :HEREDOC_MID, + :HEREDOC_POST, +] +PuppetLint.new_check(:variables_not_enclosed) do def check invalid_tokens = tokens.select do |token| token.type == :UNENC_VARIABLE diff --git a/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb b/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb index da839ef1..59d44b0a 100644 --- a/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +++ b/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb @@ -2,9 +2,9 @@ # record a warning for each instance found. # # No style guide reference -PuppetLint.new_check(:variable_contains_dash) do - VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +PuppetLint.new_check(:variable_contains_dash) do def check invalid_tokens = tokens.select do |token| VARIABLE_DASH_TYPES.include?(token.type) diff --git a/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb b/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb index 7f686807..0804f5a9 100644 --- a/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +++ b/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb @@ -2,9 +2,9 @@ # letter and record a warning for each instance found. # # No style guide reference -PuppetLint.new_check(:variable_is_lowercase) do - VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +PuppetLint.new_check(:variable_is_lowercase) do def check invalid_tokens = tokens.select do |token| VARIABLE_LOWERCASE_TYPES.include?(token.type) diff --git a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb index 75cfa478..5372628d 100644 --- a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +++ b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb @@ -2,9 +2,9 @@ # are not aligned with other arrows in that grouping. # # https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace -PuppetLint.new_check(:arrow_alignment) do - COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT] +COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT] +PuppetLint.new_check(:arrow_alignment) do def check resource_indexes.each do |res_idx| arrow_column = [0] diff --git a/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb b/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb index 8e8e54c8..e6fd2632 100644 --- a/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +++ b/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb @@ -2,9 +2,9 @@ # characters and record an error for each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace -PuppetLint.new_check(:hard_tabs) do - WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE] +WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE] +PuppetLint.new_check(:hard_tabs) do def check invalid_tokens = tokens.select do |token| WHITESPACE_TYPES.include?(token.type) && token.value.include?("\t") diff --git a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb index 50ce5f6c..a463f87d 100644 --- a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +++ b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb @@ -6,111 +6,111 @@ # # This plugin was adopted in to puppet-lint from https://github.com/mmckinst/puppet-lint-legacy_facts-check # Thanks to @mmckinst, @seanmil, @rodjek, @baurmatt, @bart2 and @joshcooper for the original work. -PuppetLint.new_check(:legacy_facts) do - LEGACY_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] - - # These facts that can't be converted to new facts. - UNCONVERTIBLE_FACTS = ['memoryfree_mb', 'memorysize_mb', 'swapfree_mb', - 'swapsize_mb', 'blockdevices', 'interfaces', 'zones', - 'sshfp_dsa', 'sshfp_ecdsa', 'sshfp_ed25519', - 'sshfp_rsa'].freeze - - # These facts will depend on how a system is set up and can't just be - # enumerated like the EASY_FACTS below. - # - # For example a server might have two block devices named 'sda' and 'sdb' so - # there would be a $blockdeivce_sda_vendor and $blockdeivce_sdb_vendor fact - # for each device. Or it could have 26 block devices going all the way up to - # 'sdz'. There is no way to know what the possibilities are so we have to use - # a regex to match them. - REGEX_FACTS = [%r{^blockdevice_(?.*)_(?model|size|vendor)$}, - %r{^(?ipaddress|ipaddress6|macaddress|mtu|netmask|netmask6|network|network6)_(?.*)$}, - %r{^processor(?[0-9]+)$}, - %r{^sp_(?.*)$}, - %r{^ssh(?dsa|ecdsa|ed25519|rsa)key$}, - %r{^ldom_(?.*)$}, - %r{^zone_(?.*)_(?brand|iptype|name|uuid|id|path|status)$}].freeze - - # These facts have a one to one correlation between a legacy fact and a new - # structured fact. - EASY_FACTS = { - 'architecture' => "facts['os']['architecture']", - 'augeasversion' => "facts['augeas']['version']", - 'bios_release_date' => "facts['dmi']['bios']['release_date']", - 'bios_vendor' => "facts['dmi']['bios']['vendor']", - 'bios_version' => "facts['dmi']['bios']['version']", - 'boardassettag' => "facts['dmi']['board']['asset_tag']", - 'boardmanufacturer' => "facts['dmi']['board']['manufacturer']", - 'boardproductname' => "facts['dmi']['board']['product']", - 'boardserialnumber' => "facts['dmi']['board']['serial_number']", - 'chassisassettag' => "facts['dmi']['chassis']['asset_tag']", - 'chassistype' => "facts['dmi']['chassis']['type']", - 'domain' => "facts['networking']['domain']", - 'fqdn' => "facts['networking']['fqdn']", - 'gid' => "facts['identity']['group']", - 'hardwareisa' => "facts['processors']['isa']", - 'hardwaremodel' => "facts['os']['hardware']", - 'hostname' => "facts['networking']['hostname']", - 'id' => "facts['identity']['user']", - 'ipaddress' => "facts['networking']['ip']", - 'ipaddress6' => "facts['networking']['ip6']", - 'lsbdistcodename' => "facts['os']['distro']['codename']", - 'lsbdistdescription' => "facts['os']['distro']['description']", - 'lsbdistid' => "facts['os']['distro']['id']", - 'lsbdistrelease' => "facts['os']['distro']['release']['full']", - 'lsbmajdistrelease' => "facts['os']['distro']['release']['major']", - 'lsbminordistrelease' => "facts['os']['distro']['release']['minor']", - 'lsbrelease' => "facts['os']['distro']['release']['specification']", - 'macaddress' => "facts['networking']['mac']", - 'macosx_buildversion' => "facts['os']['macosx']['build']", - 'macosx_productname' => "facts['os']['macosx']['product']", - 'macosx_productversion' => "facts['os']['macosx']['version']['full']", - 'macosx_productversion_major' => "facts['os']['macosx']['version']['major']", - 'macosx_productversion_minor' => "facts['os']['macosx']['version']['minor']", - 'manufacturer' => "facts['dmi']['manufacturer']", - 'memoryfree' => "facts['memory']['system']['available']", - 'memorysize' => "facts['memory']['system']['total']", - 'netmask' => "facts['networking']['netmask']", - 'netmask6' => "facts['networking']['netmask6']", - 'network' => "facts['networking']['network']", - 'network6' => "facts['networking']['network6']", - 'operatingsystem' => "facts['os']['name']", - 'operatingsystemmajrelease' => "facts['os']['release']['major']", - 'operatingsystemrelease' => "facts['os']['release']['full']", - 'osfamily' => "facts['os']['family']", - 'physicalprocessorcount' => "facts['processors']['physicalcount']", - 'processorcount' => "facts['processors']['count']", - 'productname' => "facts['dmi']['product']['name']", - 'rubyplatform' => "facts['ruby']['platform']", - 'rubysitedir' => "facts['ruby']['sitedir']", - 'rubyversion' => "facts['ruby']['version']", - 'selinux' => "facts['os']['selinux']['enabled']", - 'selinux_config_mode' => "facts['os']['selinux']['config_mode']", - 'selinux_config_policy' => "facts['os']['selinux']['config_policy']", - 'selinux_current_mode' => "facts['os']['selinux']['current_mode']", - 'selinux_enforced' => "facts['os']['selinux']['enforced']", - 'selinux_policyversion' => "facts['os']['selinux']['policy_version']", - 'serialnumber' => "facts['dmi']['product']['serial_number']", - 'swapencrypted' => "facts['memory']['swap']['encrypted']", - 'swapfree' => "facts['memory']['swap']['available']", - 'swapsize' => "facts['memory']['swap']['total']", - 'system32' => "facts['os']['windows']['system32']", - 'uptime' => "facts['system_uptime']['uptime']", - 'uptime_days' => "facts['system_uptime']['days']", - 'uptime_hours' => "facts['system_uptime']['hours']", - 'uptime_seconds' => "facts['system_uptime']['seconds']", - 'uuid' => "facts['dmi']['product']['uuid']", - 'xendomains' => "facts['xen']['domains']", - 'zonename' => "facts['solaris_zones']['current']", - }.freeze - - # A list of valid hash key token types - HASH_KEY_TYPES = Set[ - :STRING, # Double quoted string - :SSTRING, # Single quoted string - :NAME, # Unquoted single word - ].freeze +LEGACY_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] + +# These facts that can't be converted to new facts. +UNCONVERTIBLE_FACTS = ['memoryfree_mb', 'memorysize_mb', 'swapfree_mb', + 'swapsize_mb', 'blockdevices', 'interfaces', 'zones', + 'sshfp_dsa', 'sshfp_ecdsa', 'sshfp_ed25519', + 'sshfp_rsa'].freeze +# These facts will depend on how a system is set up and can't just be +# enumerated like the EASY_FACTS below. +# +# For example a server might have two block devices named 'sda' and 'sdb' so +# there would be a $blockdeivce_sda_vendor and $blockdeivce_sdb_vendor fact +# for each device. Or it could have 26 block devices going all the way up to +# 'sdz'. There is no way to know what the possibilities are so we have to use +# a regex to match them. +REGEX_FACTS = [%r{^blockdevice_(?.*)_(?model|size|vendor)$}, + %r{^(?ipaddress|ipaddress6|macaddress|mtu|netmask|netmask6|network|network6)_(?.*)$}, + %r{^processor(?[0-9]+)$}, + %r{^sp_(?.*)$}, + %r{^ssh(?dsa|ecdsa|ed25519|rsa)key$}, + %r{^ldom_(?.*)$}, + %r{^zone_(?.*)_(?brand|iptype|name|uuid|id|path|status)$}].freeze + +# These facts have a one to one correlation between a legacy fact and a new +# structured fact. +EASY_FACTS = { + 'architecture' => "facts['os']['architecture']", + 'augeasversion' => "facts['augeas']['version']", + 'bios_release_date' => "facts['dmi']['bios']['release_date']", + 'bios_vendor' => "facts['dmi']['bios']['vendor']", + 'bios_version' => "facts['dmi']['bios']['version']", + 'boardassettag' => "facts['dmi']['board']['asset_tag']", + 'boardmanufacturer' => "facts['dmi']['board']['manufacturer']", + 'boardproductname' => "facts['dmi']['board']['product']", + 'boardserialnumber' => "facts['dmi']['board']['serial_number']", + 'chassisassettag' => "facts['dmi']['chassis']['asset_tag']", + 'chassistype' => "facts['dmi']['chassis']['type']", + 'domain' => "facts['networking']['domain']", + 'fqdn' => "facts['networking']['fqdn']", + 'gid' => "facts['identity']['group']", + 'hardwareisa' => "facts['processors']['isa']", + 'hardwaremodel' => "facts['os']['hardware']", + 'hostname' => "facts['networking']['hostname']", + 'id' => "facts['identity']['user']", + 'ipaddress' => "facts['networking']['ip']", + 'ipaddress6' => "facts['networking']['ip6']", + 'lsbdistcodename' => "facts['os']['distro']['codename']", + 'lsbdistdescription' => "facts['os']['distro']['description']", + 'lsbdistid' => "facts['os']['distro']['id']", + 'lsbdistrelease' => "facts['os']['distro']['release']['full']", + 'lsbmajdistrelease' => "facts['os']['distro']['release']['major']", + 'lsbminordistrelease' => "facts['os']['distro']['release']['minor']", + 'lsbrelease' => "facts['os']['distro']['release']['specification']", + 'macaddress' => "facts['networking']['mac']", + 'macosx_buildversion' => "facts['os']['macosx']['build']", + 'macosx_productname' => "facts['os']['macosx']['product']", + 'macosx_productversion' => "facts['os']['macosx']['version']['full']", + 'macosx_productversion_major' => "facts['os']['macosx']['version']['major']", + 'macosx_productversion_minor' => "facts['os']['macosx']['version']['minor']", + 'manufacturer' => "facts['dmi']['manufacturer']", + 'memoryfree' => "facts['memory']['system']['available']", + 'memorysize' => "facts['memory']['system']['total']", + 'netmask' => "facts['networking']['netmask']", + 'netmask6' => "facts['networking']['netmask6']", + 'network' => "facts['networking']['network']", + 'network6' => "facts['networking']['network6']", + 'operatingsystem' => "facts['os']['name']", + 'operatingsystemmajrelease' => "facts['os']['release']['major']", + 'operatingsystemrelease' => "facts['os']['release']['full']", + 'osfamily' => "facts['os']['family']", + 'physicalprocessorcount' => "facts['processors']['physicalcount']", + 'processorcount' => "facts['processors']['count']", + 'productname' => "facts['dmi']['product']['name']", + 'rubyplatform' => "facts['ruby']['platform']", + 'rubysitedir' => "facts['ruby']['sitedir']", + 'rubyversion' => "facts['ruby']['version']", + 'selinux' => "facts['os']['selinux']['enabled']", + 'selinux_config_mode' => "facts['os']['selinux']['config_mode']", + 'selinux_config_policy' => "facts['os']['selinux']['config_policy']", + 'selinux_current_mode' => "facts['os']['selinux']['current_mode']", + 'selinux_enforced' => "facts['os']['selinux']['enforced']", + 'selinux_policyversion' => "facts['os']['selinux']['policy_version']", + 'serialnumber' => "facts['dmi']['product']['serial_number']", + 'swapencrypted' => "facts['memory']['swap']['encrypted']", + 'swapfree' => "facts['memory']['swap']['available']", + 'swapsize' => "facts['memory']['swap']['total']", + 'system32' => "facts['os']['windows']['system32']", + 'uptime' => "facts['system_uptime']['uptime']", + 'uptime_days' => "facts['system_uptime']['days']", + 'uptime_hours' => "facts['system_uptime']['hours']", + 'uptime_seconds' => "facts['system_uptime']['seconds']", + 'uuid' => "facts['dmi']['product']['uuid']", + 'xendomains' => "facts['xen']['domains']", + 'zonename' => "facts['solaris_zones']['current']", +}.freeze + +# A list of valid hash key token types +HASH_KEY_TYPES = Set[ + :STRING, # Double quoted string + :SSTRING, # Single quoted string + :NAME, # Unquoted single word +].freeze + +PuppetLint.new_check(:legacy_facts) do def check tokens.select { |x| LEGACY_FACTS_VAR_TYPES.include?(x.type) }.each do |token| fact_name = '' diff --git a/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb b/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb index e2de194f..9baa3be3 100644 --- a/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +++ b/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb @@ -13,8 +13,9 @@ # # This plugin was adopted in to puppet-lint from https://github.com/mmckinst/puppet-lint-top_scope_facts-check # Thanks to @mmckinst, @seanmil and @alexjfisher for the original work. +TOP_SCOPE_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] + PuppetLint.new_check(:top_scope_facts) do - TOP_SCOPE_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] def check whitelist = ['trusted', 'facts'] + (PuppetLint.configuration.top_scope_variables || []) whitelist = whitelist.join('|') From 823b654eff2a7783784d54e1a26a08a0395808ef Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 10:58:27 +0100 Subject: [PATCH 26/56] (CONT-811) Correct Lint/NonDeterministicRequireOrder --- lib/puppet-lint/plugins.rb | 2 +- lib/puppet-lint/plugins/check_whitespace/line_length.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet-lint/plugins.rb b/lib/puppet-lint/plugins.rb index cc5cb13c..f474c2b6 100644 --- a/lib/puppet-lint/plugins.rb +++ b/lib/puppet-lint/plugins.rb @@ -77,7 +77,7 @@ def gem_directories end end -Dir[File.expand_path('plugins/**/*.rb', File.dirname(__FILE__))].each do |file| +Dir[File.expand_path('plugins/**/*.rb', File.dirname(__FILE__))].sort.each do |file| require file end diff --git a/lib/puppet-lint/plugins/check_whitespace/line_length.rb b/lib/puppet-lint/plugins/check_whitespace/line_length.rb index dafe700a..585878c1 100644 --- a/lib/puppet-lint/plugins/check_whitespace/line_length.rb +++ b/lib/puppet-lint/plugins/check_whitespace/line_length.rb @@ -21,7 +21,7 @@ def self.check(line_number, content, character_count) message: "line has more than #{character_count} characters", line: line_number, column: character_count, - description: 'Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. ' \ + description: "Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. " \ 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace', ] From 8925d8432695a236f4b8c208a5ead641d1e3f016 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 12:07:00 +0100 Subject: [PATCH 27/56] (CONT-811) Correct Lint/RedundantRequireStatement --- lib/puppet-lint/lexer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index 90b36853..3383490a 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -1,6 +1,5 @@ # encoding: utf-8 -require 'pp' require 'strscan' require 'set' require 'puppet-lint/lexer/token' From d96c1645842dc02794d560a2e1ab852f2097ffa0 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 12:25:14 +0100 Subject: [PATCH 28/56] (CONT-811) Correct Performance/BindCall --- lib/puppet-lint/monkeypatches.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/monkeypatches.rb b/lib/puppet-lint/monkeypatches.rb index a986f58d..510e5312 100644 --- a/lib/puppet-lint/monkeypatches.rb +++ b/lib/puppet-lint/monkeypatches.rb @@ -18,7 +18,7 @@ def %(*a, &b) if a.empty? string else - Percent.bind(string).call(a, &b) + Percent.bind_call(string, a, &b) end end From 65f6bfd69d7ead458076b36e8e757fffcd35fcf4 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 13:38:27 +0100 Subject: [PATCH 29/56] (CONT-811) Correct Performance/DeletePrefix --- lib/puppet-lint/lexer.rb | 4 ++-- spec/spec_helper.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index 3383490a..d2925001 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -422,7 +422,7 @@ def process_string_segments(segments) tokens << new_token(type, t.value, raw: t.raw) end when :UNENC_VAR - tokens << new_token(:UNENC_VARIABLE, segment[1].gsub(%r{\A\$}, '')) + tokens << new_token(:UNENC_VARIABLE, segment[1].delete_prefix('$')) else tokens << new_token(:DQMID, segment[1]) end @@ -454,7 +454,7 @@ def process_heredoc_segments(segments) tokens << new_token(type, t.value, raw: t.raw) end when :UNENC_VAR - tokens << new_token(:UNENC_VARIABLE, segment[1].gsub(%r{\A\$}, '')) + tokens << new_token(:UNENC_VARIABLE, segment[1].delete_prefix('$')) else tokens << new_token(:HEREDOC_MID, segment[1]) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d54c5ece..be59e625 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,7 +23,7 @@ module RSpec::LintExampleGroup class HaveProblem def initialize(method, message) @expected_problem = { - kind: method.to_s.gsub(%r{\Acontain_}, '').to_sym, + kind: method.to_s.delete_prefix('contain_').to_sym, message: message, } @description = ["contain a #{@expected_problem[:kind]}"] From 13de8bb3e51936e7c79e5d6502b76ff67f017f92 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 13:39:49 +0100 Subject: [PATCH 30/56] (CONT-811) Correct RSpec/ContextMethod --- spec/unit/puppet-lint/lexer_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index 28f77f7c..17586a3b 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -13,7 +13,7 @@ end end - context '#new_token' do + describe '#new_token' do it 'calculates the line number for an empty string' do token = lexer.new_token(:TEST, 'test') expect(token.line).to eq(1) @@ -63,7 +63,7 @@ end end - context '#process_string_segments' do + describe '#process_string_segments' do subject(:tokens) { lexer.tokens } subject(:manifest) { lexer.tokens.map(&:to_manifest).join } From d23da53bdcdfd2838ff2563d54934b3c2857cce9 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 13:44:02 +0100 Subject: [PATCH 31/56] (CONT-811) Correct RSpec/EmptyLineAfterExample --- spec/unit/puppet-lint/bin_spec.rb | 10 ++++++++++ spec/unit/puppet-lint/lexer_spec.rb | 1 + .../plugins/legacy_facts/legacy_facts_spec.rb | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/spec/unit/puppet-lint/bin_spec.rb b/spec/unit/puppet-lint/bin_spec.rb index 3374f3e3..17c91afb 100644 --- a/spec/unit/puppet-lint/bin_spec.rb +++ b/spec/unit/puppet-lint/bin_spec.rb @@ -89,6 +89,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do is_expected.to eq( [ @@ -145,6 +146,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do is_expected.to match(%r{WARNING}) is_expected.not_to match(%r{ERROR}) @@ -162,6 +164,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.not_to match(%r{ERROR}) is_expected.to match(%r{WARNING}) @@ -200,6 +203,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq( [ @@ -294,6 +298,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do is_expected.to match(%r{^(/|[A-Za-z]\:).+/spec/fixtures/test/manifests/fail\.pp$}) end @@ -374,6 +379,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do if respond_to?(:include_json) is_expected.to include_json([[{ 'KIND' => 'WARNING' }]]) @@ -393,6 +399,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do if respond_to?(:include_json) is_expected.to include_json([[{ 'KIND' => 'ERROR' }], [{ 'KIND' => 'WARNING' }]]) @@ -493,6 +500,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq( [ @@ -615,6 +623,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq('WARNING: variable contains a dash on line 3 (check: variable_contains_dash)') end @@ -629,6 +638,7 @@ def initialize(args) end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq('WARNING: variable contains an uppercase letter on line 4 (check: variable_is_lowercase)') end diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index 17586a3b..c03f7a68 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -1382,6 +1382,7 @@ expect(token.type).to eq(:TYPE) expect(token.value).to eq('Callable') end + it 'matches Sensitive' do token = lexer.tokenise('Sensitive').first expect(token.type).to eq(:TYPE) diff --git a/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb b/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb index d1323610..15343af0 100644 --- a/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +++ b/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb @@ -250,6 +250,7 @@ it 'onlies detect a single problem' do expect(problems).to have(1).problem end + it 'uses the facts hash' do expect(manifest).to eq("$facts['disks']['sda']['model']") end @@ -261,6 +262,7 @@ it 'onlies detect a single problem' do expect(problems).to have(1).problem end + it 'uses the facts hash' do expect(manifest).to eq("$facts['networking']['interfaces']['em2']['ip6']") end @@ -272,6 +274,7 @@ it 'onlies detect a single problem' do expect(problems).to have(1).problem end + it 'uses the facts hash' do expect(manifest).to eq("$facts['solaris_zones']['zones']['foobar']['uuid']") end @@ -283,6 +286,7 @@ it 'onlies detect a single problem' do expect(problems).to have(1).problem end + it 'uses the facts hash' do expect(manifest).to eq("$facts['processors']['models'][314]") end @@ -294,6 +298,7 @@ it 'onlies detect a single problem' do expect(problems).to have(1).problem end + it 'uses the facts hash' do expect(manifest).to eq("$facts['system_profiler']['l3_cache']") end @@ -305,6 +310,7 @@ it 'onlies detect a single problem' do expect(problems).to have(1).problem end + it 'uses the facts hash' do expect(manifest).to eq("$facts['ssh']['rsa']['key']") end From b66043478ec24ab28f0076105b648af389d3fb2a Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 13:45:13 +0100 Subject: [PATCH 32/56] (CONT-811) Correct RSpec/EmptyLineAfterExampleGroup --- .../plugins/legacy_facts/legacy_facts_spec.rb | 10 ++++++++++ .../plugins/top_scope_facts/top_scope_facts_spec.rb | 1 + 2 files changed, 11 insertions(+) diff --git a/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb b/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb index 15343af0..5e49be60 100644 --- a/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb +++ b/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb @@ -339,6 +339,7 @@ expect(manifest).to eq("\"$facts['os']['family']\"") end end + context 'fact variable using legacy variable in double quotes "$::gid"' do let(:code) { '"$::gid"' } @@ -350,6 +351,7 @@ expect(manifest).to eq("\"$facts['identity']['group']\"") end end + context 'fact variable using legacy variable in double quotes "$::id"' do let(:code) { '"$::id"' } @@ -361,6 +363,7 @@ expect(manifest).to eq("\"$facts['identity']['user']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbdistcodename"' do let(:code) { '"$::lsbdistcodename"' } @@ -372,6 +375,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['codename']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbdistdescription"' do let(:code) { '"$::lsbdistdescription"' } @@ -383,6 +387,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['description']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbdistid"' do let(:code) { '"$::lsbdistid"' } @@ -394,6 +399,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['id']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbdistrelease"' do let(:code) { '"$::lsbdistrelease"' } @@ -405,6 +411,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['release']['full']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbmajdistrelease"' do let(:code) { '"$::lsbmajdistrelease"' } @@ -416,6 +423,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['release']['major']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbminordistrelease"' do let(:code) { '"$::lsbminordistrelease"' } @@ -427,6 +435,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['release']['minor']\"") end end + context 'fact variable using legacy variable in double quotes "$::lsbrelease"' do let(:code) { '"$::lsbrelease"' } @@ -438,6 +447,7 @@ expect(manifest).to eq("\"$facts['os']['distro']['release']['specification']\"") end end + context "fact variable using facts hash in double quotes \"$facts['lsbrelease']\"" do let(:code) { "\"${facts['lsbrelease']}\"" } diff --git a/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb b/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb index c09f8bae..43d477ef 100644 --- a/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +++ b/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb @@ -11,6 +11,7 @@ expect(problems).to have(0).problem end end + context 'non-fact variable with two colons' do let(:code) { '$foo::bar' } From 034715ac148cee01ab11247cd184c2e8ad914a2a Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 13:53:56 +0100 Subject: [PATCH 33/56] (CONT-811) Correct RSpec/ImplicitSubject --- spec/unit/puppet-lint/lexer/string_slurper_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/puppet-lint/lexer/string_slurper_spec.rb b/spec/unit/puppet-lint/lexer/string_slurper_spec.rb index 7694a089..33177062 100644 --- a/spec/unit/puppet-lint/lexer/string_slurper_spec.rb +++ b/spec/unit/puppet-lint/lexer/string_slurper_spec.rb @@ -458,7 +458,7 @@ let(:string) { 'accentués"' } it 'counts the multibyte character as a single consumed character' do - is_expected.to eq(10) + expect(subject).to eq(10) end end @@ -466,7 +466,7 @@ let(:string) { '"' } it 'consumes only the closing quote' do - is_expected.to eq(1) + expect(subject).to eq(1) end end end From 92c35b9f6caf0f3802c3bb60b57812fc3f1b3e90 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:30:35 +0100 Subject: [PATCH 34/56] (CONT-811) Correct NamedSubject --- spec/unit/puppet-lint/lexer/string_slurper_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit/puppet-lint/lexer/string_slurper_spec.rb b/spec/unit/puppet-lint/lexer/string_slurper_spec.rb index 33177062..85694425 100644 --- a/spec/unit/puppet-lint/lexer/string_slurper_spec.rb +++ b/spec/unit/puppet-lint/lexer/string_slurper_spec.rb @@ -452,13 +452,13 @@ end describe '#consumed_chars' do - subject { described_class.new(string).tap(&:parse).consumed_chars } + subject(:consumed_chars) { described_class.new(string).tap(&:parse).consumed_chars } context 'when slurping a string containing multibyte characters' do let(:string) { 'accentués"' } it 'counts the multibyte character as a single consumed character' do - expect(subject).to eq(10) + expect(consumed_chars).to eq(10) end end @@ -466,7 +466,7 @@ let(:string) { '"' } it 'consumes only the closing quote' do - expect(subject).to eq(1) + expect(consumed_chars).to eq(1) end end end From 5e11a79079512b0899654b8c504ab2ffd07b130f Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:35:31 +0100 Subject: [PATCH 35/56] (CONT-811) Correct RSpec/MultipleSubjects --- spec/unit/puppet-lint/lexer_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index c03f7a68..2484e06e 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -64,10 +64,10 @@ end describe '#process_string_segments' do - subject(:tokens) { lexer.tokens } - subject(:manifest) { lexer.tokens.map(&:to_manifest).join } + let(:tokens) { lexer.tokens } + before(:each) do lexer.process_string_segments(segments) end From 5e5978995bd7289e36232136d13b64c988e5c4f4 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:37:46 +0100 Subject: [PATCH 36/56] (CONT-811) Correct RSpec/PredicateMatcher --- spec/unit/puppet-lint/configuration_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/puppet-lint/configuration_spec.rb b/spec/unit/puppet-lint/configuration_spec.rb index 0dc50503..f208cf41 100644 --- a/spec/unit/puppet-lint/configuration_spec.rb +++ b/spec/unit/puppet-lint/configuration_spec.rb @@ -14,11 +14,11 @@ config.disable_foo expect(config.settings['foo_disabled']).to be_truthy - expect(config.foo_enabled?).to be_falsey + expect(config).not_to be_foo_enabled config.enable_foo expect(config.settings['foo_disabled']).to be_falsey - expect(config.foo_enabled?).to be_truthy + expect(config).to be_foo_enabled end it 'knows what checks have been added' do From 085adb665a78deda40b9b28707f51b7c2dd8829e Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:40:26 +0100 Subject: [PATCH 37/56] (CONT-811) Correct Style/AccessorGrouping --- lib/puppet-lint/lexer/string_slurper.rb | 4 +--- lib/puppet-lint/tasks/puppet-lint.rb | 14 +------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/lib/puppet-lint/lexer/string_slurper.rb b/lib/puppet-lint/lexer/string_slurper.rb index 403af9c8..29304fb9 100644 --- a/lib/puppet-lint/lexer/string_slurper.rb +++ b/lib/puppet-lint/lexer/string_slurper.rb @@ -4,9 +4,7 @@ class PuppetLint::Lexer # Internal: A class for slurping strings from a Puppet manifest. class StringSlurper - attr_accessor :scanner - attr_accessor :results - attr_accessor :interp_stack + attr_accessor :scanner, :results, :interp_stack START_INTERP_PATTERN = %r{\$\{}.freeze END_INTERP_PATTERN = %r{\}}.freeze diff --git a/lib/puppet-lint/tasks/puppet-lint.rb b/lib/puppet-lint/tasks/puppet-lint.rb index fe37d642..6515f79b 100644 --- a/lib/puppet-lint/tasks/puppet-lint.rb +++ b/lib/puppet-lint/tasks/puppet-lint.rb @@ -17,19 +17,7 @@ class PuppetLint::RakeTask < Rake::TaskLib DEFAULT_PATTERN = '**/*.pp'.freeze - attr_accessor :name - attr_accessor :pattern - attr_accessor :ignore_paths - attr_accessor :with_filename - attr_accessor :disable_checks - attr_accessor :only_checks - attr_accessor :fail_on_warnings - attr_accessor :error_level - attr_accessor :log_format - attr_accessor :with_context - attr_accessor :fix - attr_accessor :show_ignored - attr_accessor :relative + attr_accessor :name, :pattern, :ignore_paths, :with_filename, :disable_checks, :only_checks, :fail_on_warnings, :error_level, :log_format, :with_context, :fix, :show_ignored, :relative # Public: Initialise a new PuppetLint::RakeTask. # From 95ef20778544d43279281ec89d14cbb17ad04b66 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:44:00 +0100 Subject: [PATCH 38/56] (CONT-811) Correct Style/CaseLikeIf --- lib/puppet-lint/plugins/check_classes/parameter_order.rb | 9 +++++---- .../plugins/check_whitespace/arrow_alignment.rb | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/puppet-lint/plugins/check_classes/parameter_order.rb b/lib/puppet-lint/plugins/check_classes/parameter_order.rb index d91a080a..23c9820b 100644 --- a/lib/puppet-lint/plugins/check_classes/parameter_order.rb +++ b/lib/puppet-lint/plugins/check_classes/parameter_order.rb @@ -11,13 +11,14 @@ def check paren_stack = [] hash_or_array_stack = [] class_idx[:param_tokens].each_with_index do |token, i| - if token.type == :LPAREN + case token.type + when :LPAREN paren_stack.push(true) - elsif token.type == :RPAREN + when :RPAREN paren_stack.pop - elsif token.type == :LBRACE || token.type == :LBRACK + when :LBRACE, :LBRACK hash_or_array_stack.push(true) - elsif token.type == :RBRACE || token.type == :RBRACK + when :RBRACE, :RBRACK hash_or_array_stack.pop end diff --git a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb index 5372628d..0e38ab48 100644 --- a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +++ b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb @@ -24,7 +24,8 @@ def check next if resource_tokens[first_arrow].line == resource_tokens[last_arrow].line resource_tokens.each do |token| - if token.type == :FARROW + case token.type + when :FARROW param_token = token.prev_code_token if param_token.type == :DQPOST @@ -59,12 +60,12 @@ def check end (level_tokens[level_idx] ||= []) << token - elsif token.type == :LBRACE + when :LBRACE level_idx += 1 arrow_column << 0 level_tokens[level_idx] ||= [] param_column << nil - elsif token.type == :RBRACE || token.type == :SEMIC + when :RBRACE, :SEMIC if (level_tokens[level_idx] ||= []).map(&:line).uniq.length > 1 level_tokens[level_idx].each do |arrow_tok| next if arrow_tok.column == arrow_column[level_idx] || level_tokens[level_idx].size == 1 From 23be6dd8ec329c5a5b0f28b5d732095171e69a6e Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:48:33 +0100 Subject: [PATCH 39/56] (CONT-811) Correct Style/Encoding --- lib/puppet-lint/lexer.rb | 2 -- spec/unit/puppet-lint/lexer/string_slurper_spec.rb | 2 -- spec/unit/puppet-lint/lexer_spec.rb | 2 -- spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb | 2 -- spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb | 2 -- 5 files changed, 10 deletions(-) diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index d2925001..ddae02a2 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'strscan' require 'set' require 'puppet-lint/lexer/token' diff --git a/spec/unit/puppet-lint/lexer/string_slurper_spec.rb b/spec/unit/puppet-lint/lexer/string_slurper_spec.rb index 85694425..c394536d 100644 --- a/spec/unit/puppet-lint/lexer/string_slurper_spec.rb +++ b/spec/unit/puppet-lint/lexer/string_slurper_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe PuppetLint::Lexer::StringSlurper do diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index 2484e06e..e324acfd 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe PuppetLint::Lexer do diff --git a/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb b/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb index ff03e6a6..ceb9a56e 100644 --- a/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe '140chars' do diff --git a/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb b/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb index 4717755b..9b9f1570 100644 --- a/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe '80chars' do From 4a541e60a7eccebfafce7a23cbb4d3f1f8247016 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:49:34 +0100 Subject: [PATCH 40/56] (CONT-811) Correct Style/ExpandPathArguments --- puppet-lint.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/puppet-lint.gemspec b/puppet-lint.gemspec index 57a008ad..35a32ed2 100644 --- a/puppet-lint.gemspec +++ b/puppet-lint.gemspec @@ -1,4 +1,4 @@ -$LOAD_PATH.push(File.expand_path('../lib', __FILE__)) +$LOAD_PATH.push(File.expand_path('lib', __dir__)) require 'puppet-lint/version' Gem::Specification.new do |spec| From 27d02ae6fac3f2bcc0f02b18a49976b0057b9513 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:51:51 +0100 Subject: [PATCH 41/56] (CONT-811) Correct Style/ExplicitBlockArgument --- lib/puppet-lint/tasks/release_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet-lint/tasks/release_test.rb b/lib/puppet-lint/tasks/release_test.rb index 9ddc357b..3d6057b5 100644 --- a/lib/puppet-lint/tasks/release_test.rb +++ b/lib/puppet-lint/tasks/release_test.rb @@ -27,7 +27,7 @@ def run_cmd(message, *cmd) [output.strip, status.success?] end -def with_puppet_lint_head +def with_puppet_lint_head(&block) print(' Updating Gemfile to use puppet-lint HEAD... ') buffer = Parser::Source::Buffer.new('Gemfile') @@ -49,7 +49,7 @@ def with_puppet_lint_head puts 'Done' - Bundler.with_clean_env { yield } + Bundler.with_clean_env(&block) run_cmd('Restoring Gemfile', 'git', 'checkout', '--', 'Gemfile') end From 06e66c55027a1fa4dec21cf8fc66d61d8662fbfc Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 15:59:54 +0100 Subject: [PATCH 42/56] (CONT-811) Correct Style/HashAsLastArrayItem --- .../plugins/check_whitespace/line_length.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/puppet-lint/plugins/check_whitespace/line_length.rb b/lib/puppet-lint/plugins/check_whitespace/line_length.rb index 585878c1..88c6536a 100644 --- a/lib/puppet-lint/plugins/check_whitespace/line_length.rb +++ b/lib/puppet-lint/plugins/check_whitespace/line_length.rb @@ -18,12 +18,12 @@ def self.check(line_number, content, character_count) [ :warning, - message: "line has more than #{character_count} characters", - line: line_number, - column: character_count, - description: "Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. " \ - 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', - help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace', + { message: "line has more than #{character_count} characters", + line: line_number, + column: character_count, + description: "Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. " \ + 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', + help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace' }, ] end end From 662d0abc59c594b4db96b7a9e2f932a129aa181c Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:01:41 +0100 Subject: [PATCH 43/56] (CONT-811) Correct Style/IfUnlessModifier --- lib/puppet-lint/bin.rb | 8 ++------ lib/puppet-lint/checkplugin.rb | 8 ++------ lib/puppet-lint/data.rb | 8 ++------ lib/puppet-lint/plugins.rb | 4 +--- .../plugins/check_classes/autoloader_layout.rb | 4 +--- .../plugins/check_classes/parameter_order.rb | 4 +--- .../check_resources/ensure_first_param.rb | 4 +--- .../check_strings/only_variable_string.rb | 4 +--- .../plugins/check_whitespace/arrow_alignment.rb | 4 +--- lib/puppet-lint/tasks/puppet-lint.rb | 16 ++++------------ 10 files changed, 16 insertions(+), 48 deletions(-) diff --git a/lib/puppet-lint/bin.rb b/lib/puppet-lint/bin.rb index 9e3edeb4..f74bc3fe 100644 --- a/lib/puppet-lint/bin.rb +++ b/lib/puppet-lint/bin.rb @@ -85,9 +85,7 @@ def run l.run all_problems << l.print_problems - if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings) - return_val = 1 - end + return_val = 1 if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings) next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax } @@ -105,9 +103,7 @@ def run puts JSON.pretty_generate(all_problems) end - if PuppetLint.configuration.codeclimate_report_file - PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) - end + PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file return_val rescue PuppetLint::NoCodeError diff --git a/lib/puppet-lint/checkplugin.rb b/lib/puppet-lint/checkplugin.rb index e8a31ff3..e78a2ce4 100644 --- a/lib/puppet-lint/checkplugin.rb +++ b/lib/puppet-lint/checkplugin.rb @@ -202,14 +202,10 @@ def notify(kind, problem) problem[:kind] = kind problem.merge!(default_info) { |_key, v1, _v2| v1 } - unless [:warning, :error, :fixed].include?(kind) - raise ArgumentError, 'unknown value passed for kind' - end + raise ArgumentError, 'unknown value passed for kind' unless [:warning, :error, :fixed].include?(kind) [:message, :line, :column, :check].each do |attr| - unless problem.key?(attr) - raise ArgumentError, "problem hash must contain #{attr.inspect}" - end + raise ArgumentError, "problem hash must contain #{attr.inspect}" unless problem.key?(attr) end @problems << problem diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index 900cd950..7e2bad42 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -92,9 +92,7 @@ def insert(index, token) end current_token.next_token = token - unless formatting_tokens.include?(token.type) - current_token.next_code_token = token - end + current_token.next_code_token = token unless formatting_tokens.include?(token.type) tokens.insert(index, token) end @@ -239,9 +237,7 @@ def find_resource_param_tokens(resource_tokens) break unless resource_tokens.include?(iter_token) - if iter_token && iter_token.next_code_token.type == :FARROW - param_tokens << iter_token - end + param_tokens << iter_token if iter_token && iter_token.next_code_token.type == :FARROW end param_tokens diff --git a/lib/puppet-lint/plugins.rb b/lib/puppet-lint/plugins.rb index f474c2b6..905c5046 100644 --- a/lib/puppet-lint/plugins.rb +++ b/lib/puppet-lint/plugins.rb @@ -55,9 +55,7 @@ def gemspecs def load_prerelease_plugins? # Load prerelease plugins (which ruby defines as any gem which has a letter in its version number). # Can't use puppet-lint configuration object here because this code executes before the command line is parsed. - if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'] - return ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase) - end + return ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase) if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'] false end diff --git a/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb b/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb index ac88a7d1..d78dd293 100644 --- a/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +++ b/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb @@ -17,9 +17,7 @@ def check "/#{title_token.value}/manifests/init.pp" end - if PuppetLint.configuration.relative - expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..-1].join('/') - end + expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..-1].join('/') if PuppetLint.configuration.relative next if fullpath.end_with?(expected_path) diff --git a/lib/puppet-lint/plugins/check_classes/parameter_order.rb b/lib/puppet-lint/plugins/check_classes/parameter_order.rb index 23c9820b..a1deb2b9 100644 --- a/lib/puppet-lint/plugins/check_classes/parameter_order.rb +++ b/lib/puppet-lint/plugins/check_classes/parameter_order.rb @@ -59,9 +59,7 @@ def required_parameter?(token) data_type = token.prev_token_of(:TYPE, skip_blocks: true) return false if data_type && data_type.value == 'Optional' - if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type) - return !(token.prev_code_token && token.prev_code_token.type == :EQUALS) - end + return !(token.prev_code_token && token.prev_code_token.type == :EQUALS) if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type) false end diff --git a/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb b/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb index edb8af34..f5eee84c 100644 --- a/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +++ b/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb @@ -37,9 +37,7 @@ def fix(problem) ensure_param_comma_token = ensure_param_name_token.next_token_of([:COMMA, :SEMIC]) - if first_param_name_token.nil? || first_param_comma_token.nil? || ensure_param_comma_token.nil? - raise PuppetLint::NoFix - end + raise PuppetLint::NoFix if first_param_name_token.nil? || first_param_comma_token.nil? || ensure_param_comma_token.nil? first_param_name_idx = tokens.index(first_param_name_token) first_param_comma_idx = tokens.index(first_param_comma_token) diff --git a/lib/puppet-lint/plugins/check_strings/only_variable_string.rb b/lib/puppet-lint/plugins/check_strings/only_variable_string.rb index 2f7695c5..063e1562 100644 --- a/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +++ b/lib/puppet-lint/plugins/check_strings/only_variable_string.rb @@ -20,9 +20,7 @@ def check eos_offset += 3 when :DQPOST if eos_token.value == '' - if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW - break - end + break if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW notify( :warning, diff --git a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb index 0e38ab48..64650cdf 100644 --- a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +++ b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb @@ -55,9 +55,7 @@ def check this_arrow_column += 1 end - if arrow_column[level_idx] < this_arrow_column - arrow_column[level_idx] = this_arrow_column - end + arrow_column[level_idx] = this_arrow_column if arrow_column[level_idx] < this_arrow_column (level_tokens[level_idx] ||= []) << token when :LBRACE diff --git a/lib/puppet-lint/tasks/puppet-lint.rb b/lib/puppet-lint/tasks/puppet-lint.rb index 6515f79b..bda63e80 100644 --- a/lib/puppet-lint/tasks/puppet-lint.rb +++ b/lib/puppet-lint/tasks/puppet-lint.rb @@ -68,13 +68,9 @@ def define(args, &task_block) PuppetLint.configuration.send("#{config}=".to_sym, value) unless value.nil? end - if PuppetLint.configuration.ignore_paths && @ignore_paths.empty? - @ignore_paths = PuppetLint.configuration.ignore_paths - end + @ignore_paths = PuppetLint.configuration.ignore_paths if PuppetLint.configuration.ignore_paths && @ignore_paths.empty? - if PuppetLint.configuration.pattern - @pattern = PuppetLint.configuration.pattern - end + @pattern = PuppetLint.configuration.pattern if PuppetLint.configuration.pattern RakeFileUtils.send(:verbose, true) do linter = PuppetLint.new @@ -90,14 +86,10 @@ def define(args, &task_block) linter.run all_problems << linter.print_problems - if PuppetLint.configuration.fix && linter.problems.none? { |e| e[:check] == :syntax } - File.write(puppet_file, linter.manifest) - end + File.write(puppet_file, linter.manifest) if PuppetLint.configuration.fix && linter.problems.none? { |e| e[:check] == :syntax } end - if PuppetLint.configuration.codeclimate_report_file - PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) - end + PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file abort if linter.errors? || ( linter.warnings? && PuppetLint.configuration.fail_on_warnings From 42b2805039d30e1850a0925d573a147dd3a12e85 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:02:37 +0100 Subject: [PATCH 44/56] (CONT-811) Correct Style/NumericPredicate --- lib/puppet-lint/data.rb | 2 +- lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index 7e2bad42..ec6a57a1 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -448,7 +448,7 @@ def hash_indexes level += 1 if cur_token.type == :LBRACE level -= 1 if cur_token.type == :RBRACE - break if level < 0 + break if level.negative? end hashes << { diff --git a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb index 64650cdf..d993db7c 100644 --- a/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +++ b/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb @@ -116,7 +116,7 @@ def fix(problem) new_ws_len += (problem[:arrow_column] - problem[:token].column) end - raise PuppetLint::NoFix if new_ws_len < 0 + raise PuppetLint::NoFix if new_ws_len.negative? new_ws = ' ' * new_ws_len From 69f3071361238e7146a60605036498096d3cfdd2 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:04:03 +0100 Subject: [PATCH 45/56] (CONT-811) Correct Style/RedundantArgument --- lib/puppet-lint/checks.rb | 2 +- spec/unit/puppet-lint/lexer_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet-lint/checks.rb b/lib/puppet-lint/checks.rb index c68ded07..e4088c3b 100644 --- a/lib/puppet-lint/checks.rb +++ b/lib/puppet-lint/checks.rb @@ -129,6 +129,6 @@ def enabled_checks # # Returns the manifest as a String. def manifest - PuppetLint::Data.tokens.map(&:to_manifest).join('') + PuppetLint::Data.tokens.map(&:to_manifest).join end end diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index e324acfd..6af805a1 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -1289,7 +1289,7 @@ it 'does not enclose variable with a chained function call' do manifest = '"This is ${a.test}"' tokens = lexer.tokenise(manifest) - expect(tokens.map(&:to_manifest).join('')).to eq(manifest) + expect(tokens.map(&:to_manifest).join).to eq(manifest) end end @@ -1688,7 +1688,7 @@ END tokens = lexer.tokenise(manifest) - expect(tokens.map(&:to_manifest).join('')).to eq(manifest) + expect(tokens.map(&:to_manifest).join).to eq(manifest) expect(tokens[0].type).to eq(:VARIABLE) expect(tokens[0].value).to eq('str') @@ -1755,7 +1755,7 @@ expect(tokens[7].raw).to eq('$myvar') expect(tokens[7].to_manifest).to eq('$myvar') - expect(tokens.map(&:to_manifest).join('')).to eq(manifest) + expect(tokens.map(&:to_manifest).join).to eq(manifest) end end From 826d33a2e0b806fae8a13751641adf76f0138276 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:05:01 +0100 Subject: [PATCH 46/56] (CONT-811) Correct Style/RedundantRegexpEscape --- lib/puppet-lint/data.rb | 4 ++-- lib/puppet-lint/monkeypatches.rb | 2 +- spec/unit/puppet-lint/bin_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index ec6a57a1..409b379f 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -562,7 +562,7 @@ def parse_control_comments comment_token_types.include?(token.type) end control_comment_tokens = comment_tokens.select do |token| - token.value.strip =~ %r{\Alint\:(ignore\:[\w\d]+|endignore)} + token.value.strip =~ %r{\Alint:(ignore:[\w\d]+|endignore)} end stack = [] @@ -572,7 +572,7 @@ def parse_control_comments comment_words = token.value.strip.split(%r{\s+}) comment_words.each_with_index do |word, i| - if %r{\Alint\:(ignore|endignore)}.match?(word) + if %r{\Alint:(ignore|endignore)}.match?(word) comment_data << word else # Once we reach the first non-controlcomment word, assume the rest diff --git a/lib/puppet-lint/monkeypatches.rb b/lib/puppet-lint/monkeypatches.rb index 510e5312..368d557b 100644 --- a/lib/puppet-lint/monkeypatches.rb +++ b/lib/puppet-lint/monkeypatches.rb @@ -28,7 +28,7 @@ def expand!(vars = {}) vars.each do |var, value| var = var.to_s var.gsub!(%r{[^a-zA-Z0-9_]}, '') - changed = gsub!(%r{\%\{#{var}\}}, value.to_s) + changed = gsub!(%r{%\{#{var}\}}, value.to_s) end break unless changed end diff --git a/spec/unit/puppet-lint/bin_spec.rb b/spec/unit/puppet-lint/bin_spec.rb index 17c91afb..118d054b 100644 --- a/spec/unit/puppet-lint/bin_spec.rb +++ b/spec/unit/puppet-lint/bin_spec.rb @@ -300,7 +300,7 @@ def initialize(args) its(:exitstatus) { is_expected.to eq(1) } its(:stdout) do - is_expected.to match(%r{^(/|[A-Za-z]\:).+/spec/fixtures/test/manifests/fail\.pp$}) + is_expected.to match(%r{^(/|[A-Za-z]:).+/spec/fixtures/test/manifests/fail\.pp$}) end end From 2b071f0d1782a05e39913f1e8ed62dafb00f9d1a Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:05:51 +0100 Subject: [PATCH 47/56] (CONT-811) Correct Style/RescueStandardError --- lib/puppet-lint/checks.rb | 2 +- lib/puppet-lint/monkeypatches.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet-lint/checks.rb b/lib/puppet-lint/checks.rb index e4088c3b..9ad57fe6 100644 --- a/lib/puppet-lint/checks.rb +++ b/lib/puppet-lint/checks.rb @@ -84,7 +84,7 @@ def run(fileinfo, data) } @problems - rescue => e + rescue StandardError => e $stdout.puts <<-END.gsub(%r{^ {6}}, '') Whoops! It looks like puppet-lint has encountered an error that it doesn't know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint diff --git a/lib/puppet-lint/monkeypatches.rb b/lib/puppet-lint/monkeypatches.rb index 368d557b..72461a91 100644 --- a/lib/puppet-lint/monkeypatches.rb +++ b/lib/puppet-lint/monkeypatches.rb @@ -1,6 +1,6 @@ begin '%{test}' % { test: 'replaced' } == 'replaced' -rescue +rescue StandardError # monkeypatch String#% into Ruby 1.8.7 class String Percent = instance_method(:%) unless defined?(Percent) From 47f42585e077143885bad3187c7543d3c53f621d Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:07:21 +0100 Subject: [PATCH 48/56] (CONT-811) Correct Style/SlicingWithRange --- lib/puppet-lint/data.rb | 18 +++++++++--------- lib/puppet-lint/lexer.rb | 12 ++++++------ .../plugins/check_classes/autoloader_layout.rb | 4 ++-- .../check_classes/nested_classes_or_defines.rb | 2 +- .../plugins/check_classes/variable_scope.rb | 2 +- .../check_conditionals/case_without_default.rb | 4 ++-- .../plugins/check_nodes/unquoted_node_name.rb | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index 409b379f..1b4bb2ad 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -72,7 +72,7 @@ def insert(index, token) unless formatting_tokens.include?(token.type) current_token.next_token.prev_code_token = token unless current_token.next_token.nil? - next_nf_idx = tokens[index..-1].index { |r| !formatting_tokens.include?(r.type) } + next_nf_idx = tokens[index..].index { |r| !formatting_tokens.include?(r.type) } unless next_nf_idx.nil? next_nf_token = tokens[index + next_nf_idx] token.next_code_token = next_nf_token @@ -182,12 +182,12 @@ def resource_indexes next unless colon_token.next_code_token && colon_token.next_code_token.type != :LBRACE next if classref?(colon_token) - rel_start_idx = tokens[marker..-1].index(colon_token) + rel_start_idx = tokens[marker..].index(colon_token) break if rel_start_idx.nil? start_idx = rel_start_idx + marker end_token = colon_token.next_token_of([:SEMIC, :RBRACE]) - rel_end_idx = tokens[start_idx..-1].index(end_token) + rel_end_idx = tokens[start_idx..].index(end_token) raise PuppetLint::SyntaxError, colon_token if rel_end_idx.nil? marker = rel_end_idx + start_idx @@ -304,7 +304,7 @@ def definition_indexes(type) paren_depth = 0 in_params = false inherited_class = nil - tokens[i + 1..-1].each_with_index do |definition_token, j| + tokens[i + 1..].each_with_index do |definition_token, j| case definition_token.type when :INHERITS inherited_class = definition_token.next_code_token @@ -365,7 +365,7 @@ def function_indexes level = 0 real_idx = 0 in_paren = false - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| break if level.zero? && in_paren break if level.zero? && cur_token.type == :NEWLINE @@ -404,7 +404,7 @@ def array_indexes next unless token.type == :LBRACK real_idx = 0 - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| real_idx = token_idx + 1 + cur_token_idx break if cur_token.type == :RBRACK end @@ -443,7 +443,7 @@ def hash_indexes level = 0 real_idx = 0 - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| real_idx = token_idx + 1 + cur_token_idx level += 1 if cur_token.type == :LBRACE @@ -480,7 +480,7 @@ def defaults_indexes real_idx = 0 - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| real_idx = token_idx + 1 + cur_token_idx break if cur_token.type == :RBRACE end @@ -577,7 +577,7 @@ def parse_control_comments else # Once we reach the first non-controlcomment word, assume the rest # of the words are the reason. - reason = comment_words[i..-1] + reason = comment_words[i..] break end end diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index ddae02a2..681cf308 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -200,7 +200,7 @@ def tokenise(code) i = 0 while i < code.size - chunk = code[i..-1] + chunk = code[i..] found = false @@ -230,12 +230,12 @@ def tokenise(code) tokens << new_token(:VARIABLE, var_name, opts) elsif %r{\A'.*?'}m.match?(chunk) - str_content = StringScanner.new(code[i + 1..-1]).scan_until(%r{(\A|[^\\])(\\\\)*'}m) + str_content = StringScanner.new(code[i + 1..]).scan_until(%r{(\A|[^\\])(\\\\)*'}m) length = str_content.size + 1 tokens << new_token(:SSTRING, str_content[0..-2]) elsif chunk.start_with?('"') - slurper = PuppetLint::Lexer::StringSlurper.new(code[i + 1..-1]) + slurper = PuppetLint::Lexer::StringSlurper.new(code[i + 1..]) begin string_segments = slurper.parse process_string_segments(string_segments) @@ -268,7 +268,7 @@ def tokenise(code) tokens << new_token(:MLCOMMENT, mlcomment, raw: mlcomment_raw) elsif chunk.match(%r{\A/.*?/}m) && possible_regex? - str_content = StringScanner.new(code[i + 1..-1]).scan_until(%r{(\A|[^\\])(\\\\)*/}m) + str_content = StringScanner.new(code[i + 1..]).scan_until(%r{(\A|[^\\])(\\\\)*/}m) length = str_content.size + 1 tokens << new_token(:REGEX, str_content[0..-2]) @@ -283,7 +283,7 @@ def tokenise(code) length += indent.size else heredoc_tag = heredoc_queue.shift - slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..-1]) + slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..]) heredoc_segments = slurper.parse_heredoc(heredoc_tag) process_heredoc_segments(heredoc_segments) length += slurper.consumed_chars @@ -295,7 +295,7 @@ def tokenise(code) unless heredoc_queue.empty? heredoc_tag = heredoc_queue.shift - slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..-1]) + slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..]) heredoc_segments = slurper.parse_heredoc(heredoc_tag) process_heredoc_segments(heredoc_segments) length += slurper.consumed_chars diff --git a/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb b/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb index d78dd293..1aef1ed6 100644 --- a/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +++ b/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb @@ -12,12 +12,12 @@ def check split_title = title_token.value.split('::') mod = split_title.first expected_path = if split_title.length > 1 - "/#{mod}/manifests/#{split_title[1..-1].join('/')}.pp" + "/#{mod}/manifests/#{split_title[1..].join('/')}.pp" else "/#{title_token.value}/manifests/init.pp" end - expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..-1].join('/') if PuppetLint.configuration.relative + expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..].join('/') if PuppetLint.configuration.relative next if fullpath.end_with?(expected_path) diff --git a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb index e7f5aae4..4ed25869 100644 --- a/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +++ b/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb @@ -7,7 +7,7 @@ def check class_indexes.each do |class_idx| # Skip the first token so that we don't pick up the first :CLASS - class_tokens = class_idx[:tokens][1..-1] + class_tokens = class_idx[:tokens][1..] class_tokens.each do |token| next unless CLASS_DEFINE_TOKENS.include?(token.type) diff --git a/lib/puppet-lint/plugins/check_classes/variable_scope.rb b/lib/puppet-lint/plugins/check_classes/variable_scope.rb index 57da19bf..61d9ec03 100644 --- a/lib/puppet-lint/plugins/check_classes/variable_scope.rb +++ b/lib/puppet-lint/plugins/check_classes/variable_scope.rb @@ -93,7 +93,7 @@ def check end_token = nil brace_depth = 0 - tokens[start_idx..-1].each do |sub_token| + tokens[start_idx..].each do |sub_token| case sub_token.type when :LBRACE brace_depth += 1 diff --git a/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb b/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb index 3973ef4d..060208a6 100644 --- a/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +++ b/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb @@ -10,7 +10,7 @@ def check next unless tokens[token_idx].type == :CASE depth = 0 - tokens[(token_idx + 1)..-1].each_index do |case_token_idx| + tokens[(token_idx + 1)..].each_index do |case_token_idx| idx = case_token_idx + token_idx + 1 if tokens[idx].type == :LBRACE depth += 1 @@ -27,7 +27,7 @@ def check case_indexes.each_with_index do |kase, kase_index| case_tokens = tokens[kase[:start]..kase[:end]] - case_indexes[(kase_index + 1)..-1].each do |successor_kase| + case_indexes[(kase_index + 1)..].each do |successor_kase| case_tokens -= tokens[successor_kase[:start]..successor_kase[:end]] end diff --git a/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb b/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb index 8f1be047..1c9c8662 100644 --- a/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +++ b/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb @@ -7,7 +7,7 @@ def check node_tokens = tokens.select { |token| token.type == :NODE } node_tokens.each do |node| node_token_idx = tokens.index(node) - node_lbrace_tok = tokens[node_token_idx..-1].find { |token| token.type == :LBRACE } + node_lbrace_tok = tokens[node_token_idx..].find { |token| token.type == :LBRACE } if node_lbrace_tok.nil? notify( :error, From fc8dae6d4ec5cf65316d3dd965120d669732fe1c Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:08:20 +0100 Subject: [PATCH 49/56] (CONT-811) Correct Style/SoleNestedConditional --- lib/puppet-lint/data.rb | 24 +++++++++---------- lib/puppet-lint/lexer/token.rb | 4 +--- .../plugins/check_classes/variable_scope.rb | 4 +--- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index 1b4bb2ad..a3a6455c 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -318,19 +318,17 @@ def definition_indexes(type) brace_depth += 1 when :RBRACE brace_depth -= 1 - if brace_depth.zero? && !in_params - if token.next_code_token.type != :LBRACE - result << { - start: i, - end: i + j + 1, - tokens: tokens[i..(i + j + 1)], - param_tokens: param_tokens(tokens[i..(i + j + 1)]), - type: type, - name_token: token.next_code_token, - inherited_token: inherited_class, - } - break - end + if brace_depth.zero? && !in_params && (token.next_code_token.type != :LBRACE) + result << { + start: i, + end: i + j + 1, + tokens: tokens[i..(i + j + 1)], + param_tokens: param_tokens(tokens[i..(i + j + 1)]), + type: type, + name_token: token.next_code_token, + inherited_token: inherited_class, + } + break end end end diff --git a/lib/puppet-lint/lexer/token.rb b/lib/puppet-lint/lexer/token.rb index 1b4d509b..d45c2443 100644 --- a/lib/puppet-lint/lexer/token.rb +++ b/lib/puppet-lint/lexer/token.rb @@ -176,9 +176,7 @@ def find_token_of(direction, type, opts = {}) token_iter = send("#{direction}_token".to_sym) until token_iter.nil? - if to_find.include?(token_iter.type) - return token_iter if opts[:value].nil? || token_iter.value == opts[:value] - end + return token_iter if to_find.include?(token_iter.type) && (opts[:value].nil? || token_iter.value == opts[:value]) opening_token = (direction == :next) ? 'L' : 'R' closing_token = (direction == :next) ? 'R' : 'L' diff --git a/lib/puppet-lint/plugins/check_classes/variable_scope.rb b/lib/puppet-lint/plugins/check_classes/variable_scope.rb index 61d9ec03..6136e0c7 100644 --- a/lib/puppet-lint/plugins/check_classes/variable_scope.rb +++ b/lib/puppet-lint/plugins/check_classes/variable_scope.rb @@ -117,9 +117,7 @@ def check msg = 'top-scope variable being used without an explicit namespace' referenced_variables.each do |token| - unless future_parser_scopes[token.line].nil? - next if future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, '')) - end + next if !future_parser_scopes[token.line].nil? && future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, '')) next if token.value.include?('::') next if %r{^(facts|trusted)\[.+\]}.match?(token.value) From 3c7450526828a1b60b4c2eb0f51667b4fcf9f339 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:09:24 +0100 Subject: [PATCH 50/56] (CONT-811) Correct Style/StderrPuts --- lib/puppet-lint.rb | 2 +- lib/puppet-lint/data.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet-lint.rb b/lib/puppet-lint.rb index 6ef82944..3950cb23 100644 --- a/lib/puppet-lint.rb +++ b/lib/puppet-lint.rb @@ -190,7 +190,7 @@ def report(problems) print_github_annotation(message) if configuration.github_actions end end - $stderr.puts 'Try running `puppet parser validate `' if problems.any? { |p| p[:check] == :syntax } + warn 'Try running `puppet parser validate `' if problems.any? { |p| p[:check] == :syntax } json end diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index a3a6455c..0a3df00e 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -600,7 +600,7 @@ def parse_control_comments if top_override.nil? # TODO: refactor to provide a way to expose problems from # PuppetLint::Data via the normal problem reporting mechanism. - $stderr.puts "WARNING: lint:endignore comment with no opening lint:ignore: comment found on line #{token.line}" + warn "WARNING: lint:endignore comment with no opening lint:ignore: comment found on line #{token.line}" else top_override.each do |start| next if start.nil? @@ -616,7 +616,7 @@ def parse_control_comments end stack.each do |control| - $stderr.puts "WARNING: lint:ignore:#{control[0][2]} comment on line #{control[0][0]} with no closing lint:endignore comment" + warn "WARNING: lint:ignore:#{control[0][2]} comment on line #{control[0][0]} with no closing lint:endignore comment" end end end From 96e4122d90e6e565bde0aed30b80fc98ee5efac3 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:20:51 +0100 Subject: [PATCH 51/56] (CONT-811) Correct Style/TrailingCommaInHashLiteral --- lib/puppet-lint/bin.rb | 2 +- lib/puppet-lint/checkplugin.rb | 2 +- lib/puppet-lint/checks.rb | 4 ++-- lib/puppet-lint/data.rb | 12 ++++++------ lib/puppet-lint/lexer.rb | 8 ++++---- lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb | 4 ++-- .../plugins/top_scope_facts/top_scope_facts.rb | 2 +- lib/puppet-lint/report/codeclimate.rb | 4 ++-- spec/spec_helper.rb | 2 +- spec/spec_helper_acceptance_local.rb | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/puppet-lint/bin.rb b/lib/puppet-lint/bin.rb index f74bc3fe..aa697b81 100644 --- a/lib/puppet-lint/bin.rb +++ b/lib/puppet-lint/bin.rb @@ -144,7 +144,7 @@ def report_sarif(problems, base_path, base_path_uri) 'ruleIndex' => rule_index, 'message' => { 'text' => message[:message] }, 'locations' => [{ 'physicalLocation' => { 'artifactLocation' => { 'uri' => relative_path, 'uriBaseId' => 'ROOTPATH' }, - 'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }], + 'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }] } results << result end diff --git a/lib/puppet-lint/checkplugin.rb b/lib/puppet-lint/checkplugin.rb index e78a2ce4..9561483a 100644 --- a/lib/puppet-lint/checkplugin.rb +++ b/lib/puppet-lint/checkplugin.rb @@ -182,7 +182,7 @@ def default_info check: self.class.const_get(:NAME), fullpath: fullpath, path: path, - filename: filename, + filename: filename } end diff --git a/lib/puppet-lint/checks.rb b/lib/puppet-lint/checks.rb index 9ad57fe6..399508f5 100644 --- a/lib/puppet-lint/checks.rb +++ b/lib/puppet-lint/checks.rb @@ -39,7 +39,7 @@ def load_data(path, content) column: e.column, fullpath: PuppetLint::Data.fullpath, path: PuppetLint::Data.path, - filename: PuppetLint::Data.filename, + filename: PuppetLint::Data.filename } PuppetLint::Data.tokens = [] end @@ -80,7 +80,7 @@ def run(fileinfo, data) filename: File.basename(fileinfo), path: fileinfo, line: e.token.line, - column: e.token.column, + column: e.token.column } @problems diff --git a/lib/puppet-lint/data.rb b/lib/puppet-lint/data.rb index 0a3df00e..940029bf 100644 --- a/lib/puppet-lint/data.rb +++ b/lib/puppet-lint/data.rb @@ -197,7 +197,7 @@ def resource_indexes end: marker, tokens: tokens[start_idx..marker], type: find_resource_type_token(start_idx), - param_tokens: find_resource_param_tokens(tokens[start_idx..marker]), + param_tokens: find_resource_param_tokens(tokens[start_idx..marker]) } end result @@ -326,7 +326,7 @@ def definition_indexes(type) param_tokens: param_tokens(tokens[i..(i + j + 1)]), type: type, name_token: token.next_code_token, - inherited_token: inherited_class, + inherited_token: inherited_class } break end @@ -378,7 +378,7 @@ def function_indexes functions << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end functions @@ -414,7 +414,7 @@ def array_indexes arrays << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end arrays @@ -452,7 +452,7 @@ def hash_indexes hashes << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end hashes @@ -486,7 +486,7 @@ def defaults_indexes defaults << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end defaults diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index 681cf308..b525e85d 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -73,7 +73,7 @@ def heredoc_queue 'function' => true, 'type' => true, 'attr' => true, - 'private' => true, + 'private' => true }.freeze # Internal: A Hash whose keys are Strings representing reserved keywords in @@ -85,7 +85,7 @@ def heredoc_queue 'application' => true, 'consumes' => true, 'produces' => true, - 'site' => true, + 'site' => true }.freeze # Internal: A Hash whose keys are Symbols representing token types which @@ -101,7 +101,7 @@ def heredoc_queue IF: true, ELSIF: true, LPAREN: true, - EQUALS: true, + EQUALS: true }.freeze # Internal: some commonly used regular expressions @@ -179,7 +179,7 @@ def heredoc_queue COMMENT: true, MLCOMMENT: true, SLASH_COMMENT: true, - INDENT: true, + INDENT: true }.freeze # Internal: Access the internal token storage. diff --git a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb index a463f87d..dd63656a 100644 --- a/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb +++ b/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb @@ -100,7 +100,7 @@ 'uptime_seconds' => "facts['system_uptime']['seconds']", 'uuid' => "facts['dmi']['product']['uuid']", 'xendomains' => "facts['xen']['domains']", - 'zonename' => "facts['solaris_zones']['current']", + 'zonename' => "facts['solaris_zones']['current']" }.freeze # A list of valid hash key token types @@ -143,7 +143,7 @@ def check line: token.line, column: token.column, token: token, - fact_name: fact_name, + fact_name: fact_name } end end diff --git a/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb b/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb index 9baa3be3..e14a1223 100644 --- a/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +++ b/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb @@ -28,7 +28,7 @@ def check message: 'top scope fact instead of facts hash', line: token.line, column: token.column, - token: token, + token: token } end end diff --git a/lib/puppet-lint/report/codeclimate.rb b/lib/puppet-lint/report/codeclimate.rb index 205010c4..8a922938 100644 --- a/lib/puppet-lint/report/codeclimate.rb +++ b/lib/puppet-lint/report/codeclimate.rb @@ -30,9 +30,9 @@ def self.write_report_file(problems, report_file) path: message[:path], lines: { begin: message[:line], - end: message[:line], + end: message[:line] } - }, + } } issue[:fingerprint] = Digest::MD5.hexdigest(Marshal.dump(issue)) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be59e625..a8ff3314 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,7 +24,7 @@ class HaveProblem def initialize(method, message) @expected_problem = { kind: method.to_s.delete_prefix('contain_').to_sym, - message: message, + message: message } @description = ["contain a #{@expected_problem[:kind]}"] end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index b63225f0..4286411a 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -17,7 +17,7 @@ def puppet_lint(args = []) { stdout: stdout.chomp, stderr: stderr.chomp, - exit_code: status.exitstatus, + exit_code: status.exitstatus } end From fec124464d405b1b60979c8cd64c4e2f851ff3ed Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:21:53 +0100 Subject: [PATCH 52/56] (CONT-811) Correct Style/UnpackFirst --- lib/puppet-lint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint.rb b/lib/puppet-lint.rb index 3950cb23..580dbd60 100644 --- a/lib/puppet-lint.rb +++ b/lib/puppet-lint.rb @@ -95,7 +95,7 @@ def file=(path) # Check if the input is an SE Linux policy package file (which also use # the .pp extension), which all have the first 4 bytes 0xf97cff8f. - @code = '' if @code[0..3].unpack('V').first == 0xf97cff8f + @code = '' if @code[0..3].unpack1('V') == 0xf97cff8f end # Internal: Retrieve the format string to be used when writing problems to From a3a0a10366cf938293cd29ef6c94dcf03c634400 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 16:27:09 +0100 Subject: [PATCH 53/56] (CONT-811) Adding rubocop_todo as this module is under rewrite --- .rubocop_todo.yml | 262 +--------------------------------------------- 1 file changed, 5 insertions(+), 257 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e22a0938..40005897 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,50 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-03-29 10:44:50 UTC using RuboCop version 1.48.1. +# on 2023-04-03 10:54:30 UTC using RuboCop version 1.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 20 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterGuardClause: - Enabled: false - -# Offense count: 100 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'lib/puppet-lint/bin.rb' - - 'lib/puppet-lint/lexer.rb' - - 'lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb' - - 'spec/unit/puppet-lint/configuration_spec.rb' - -# Offense count: 25 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb' - - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' - - 'lib/puppet-lint/plugins/check_documentation/documentation.rb' - - 'lib/puppet-lint/plugins/check_resources/file_mode.rb' - - 'lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb' - - 'lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb' - - 'lib/puppet-lint/plugins/check_strings/only_variable_string.rb' - - 'lib/puppet-lint/plugins/check_strings/quoted_booleans.rb' - - 'lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb' - - 'lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb' - - 'lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb' - - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' - - 'lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb' - - 'lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb' - - 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb' - # Offense count: 4 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. Lint/DuplicateBranch: @@ -52,12 +13,6 @@ Lint/DuplicateBranch: - 'lib/puppet-lint/lexer/string_slurper.rb' - 'lib/puppet-lint/lexer/token.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/InterpolationCheck: - Exclude: - - 'lib/puppet-lint/plugins/check_whitespace/line_length.rb' - # Offense count: 9 # Configuration parameters: MaximumRangeSize. Lint/MissingCopEnableDirective: @@ -71,28 +26,18 @@ Lint/MissingCopEnableDirective: - 'lib/puppet-lint/tasks/puppet-lint.rb' - 'spec/unit/puppet-lint/puppet-lint_spec.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/NonDeterministicRequireOrder: - Exclude: - - 'lib/puppet-lint/plugins.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantRequireStatement: - Exclude: - - 'lib/puppet-lint/lexer.rb' - # Offense count: 58 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 142 -# Offense count: 35 +# Offense count: 34 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: - Max: 145 + Max: 105 + Exclude: + - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' # Offense count: 2 # Configuration parameters: CountBlocks. @@ -132,12 +77,6 @@ Naming/MethodParameterName: Exclude: - 'lib/puppet-lint/monkeypatches.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Performance/BindCall: - Exclude: - - 'lib/puppet-lint/monkeypatches.rb' - # Offense count: 7 # Configuration parameters: MinSize. Performance/CollectionLiteralInLoop: @@ -147,20 +86,6 @@ Performance/CollectionLiteralInLoop: - 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb' - 'lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb' -# Offense count: 3 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SafeMultiline. -Performance/DeletePrefix: - Exclude: - - 'lib/puppet-lint/lexer.rb' - - 'spec/spec_helper.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -RSpec/ContextMethod: - Exclude: - - 'spec/unit/puppet-lint/lexer_spec.rb' - # Offense count: 408 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without @@ -172,22 +97,6 @@ RSpec/ContextWording: RSpec/DescribeClass: Enabled: false -# Offense count: 17 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterExample: - Exclude: - - 'spec/unit/puppet-lint/bin_spec.rb' - - 'spec/unit/puppet-lint/lexer_spec.rb' - - 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb' - -# Offense count: 11 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterExampleGroup: - Exclude: - - 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb' - - 'spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb' - # Offense count: 50 # Configuration parameters: CountAsOne. RSpec/ExampleLength: @@ -207,14 +116,6 @@ RSpec/FilePath: - 'spec/unit/puppet-lint/lexer_spec.rb' - 'spec/unit/puppet-lint/puppet-lint_spec.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit -RSpec/ImplicitSubject: - Exclude: - - 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb' - # Offense count: 138 RSpec/MultipleExpectations: Max: 137 @@ -224,25 +125,11 @@ RSpec/MultipleExpectations: RSpec/MultipleMemoizedHelpers: Max: 13 -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -RSpec/MultipleSubjects: - Exclude: - - 'spec/unit/puppet-lint/lexer_spec.rb' - # Offense count: 52 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 5 -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. -# SupportedStyles: inflected, explicit -RSpec/PredicateMatcher: - Exclude: - - 'spec/unit/puppet-lint/configuration_spec.rb' - # Offense count: 8 RSpec/RepeatedExampleGroupDescription: Exclude: @@ -259,36 +146,6 @@ Style/AccessorGrouping: - 'lib/puppet-lint/lexer/string_slurper.rb' - 'lib/puppet-lint/tasks/puppet-lint.rb' -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: MinBranchesCount. -Style/CaseLikeIf: - Exclude: - - 'lib/puppet-lint/plugins/check_classes/parameter_order.rb' - - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -Style/Encoding: - Exclude: - - 'lib/puppet-lint/lexer.rb' - - 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb' - - 'spec/unit/puppet-lint/lexer_spec.rb' - - 'spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb' - - 'spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/ExpandPathArguments: - Exclude: - - 'puppet-lint.gemspec' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/ExplicitBlockArgument: - Exclude: - - 'lib/puppet-lint/tasks/release_test.rb' - # Offense count: 106 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. @@ -296,92 +153,6 @@ Style/ExplicitBlockArgument: Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: braces, no_braces -Style/HashAsLastArrayItem: - Exclude: - - 'lib/puppet-lint/plugins/check_whitespace/line_length.rb' - -# Offense count: 16 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'lib/puppet-lint/bin.rb' - - 'lib/puppet-lint/checkplugin.rb' - - 'lib/puppet-lint/data.rb' - - 'lib/puppet-lint/plugins.rb' - - 'lib/puppet-lint/plugins/check_classes/autoloader_layout.rb' - - 'lib/puppet-lint/plugins/check_classes/parameter_order.rb' - - 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb' - - 'lib/puppet-lint/plugins/check_strings/only_variable_string.rb' - - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' - - 'lib/puppet-lint/tasks/puppet-lint.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Exclude: - - 'spec/**/*' - - 'lib/puppet-lint/data.rb' - - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' - -# Offense count: 4 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Methods. -Style/RedundantArgument: - Exclude: - - 'lib/puppet-lint/checks.rb' - - 'spec/unit/puppet-lint/lexer_spec.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'lib/puppet-lint/data.rb' - - 'lib/puppet-lint/monkeypatches.rb' - - 'spec/unit/puppet-lint/bin_spec.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'lib/puppet-lint/checks.rb' - - 'lib/puppet-lint/monkeypatches.rb' - -# Offense count: 22 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/SlicingWithRange: - Exclude: - - 'lib/puppet-lint/data.rb' - - 'lib/puppet-lint/lexer.rb' - - 'lib/puppet-lint/plugins/check_classes/autoloader_layout.rb' - - 'lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb' - - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' - - 'lib/puppet-lint/plugins/check_conditionals/case_without_default.rb' - - 'lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'lib/puppet-lint/data.rb' - - 'lib/puppet-lint/lexer/token.rb' - - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Style/StderrPuts: - Exclude: - - 'lib/puppet-lint.rb' - - 'lib/puppet-lint/data.rb' - # Offense count: 9 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Mode. @@ -391,26 +162,3 @@ Style/StringConcatenation: - 'lib/puppet-lint/plugins.rb' - 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb' - 'spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb' - -# Offense count: 21 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/puppet-lint/bin.rb' - - 'lib/puppet-lint/checkplugin.rb' - - 'lib/puppet-lint/checks.rb' - - 'lib/puppet-lint/data.rb' - - 'lib/puppet-lint/lexer.rb' - - 'lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb' - - 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb' - - 'lib/puppet-lint/report/codeclimate.rb' - - 'spec/spec_helper.rb' - - 'spec/spec_helper_acceptance_local.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/UnpackFirst: - Exclude: - - 'lib/puppet-lint.rb' From b5209a6f6c114bfc71478665e767610556064647 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 17:01:10 +0100 Subject: [PATCH 54/56] (CONT-811) Removing addition of rubygems_mfa requirement in gemspec - we already use GEM_HOST_API_KEY in our gem_release workflow --- puppet-lint.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/puppet-lint.gemspec b/puppet-lint.gemspec index 35a32ed2..64ba7d85 100644 --- a/puppet-lint.gemspec +++ b/puppet-lint.gemspec @@ -33,5 +33,4 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.required_ruby_version = Gem::Requirement.new('>= 2.7'.freeze) - spec.metadata['rubygems_mfa_required'] = 'true' end From 28559cffa9ff19d0d6bd408be30f0a64d6f0e340 Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Mon, 3 Apr 2023 17:13:11 +0100 Subject: [PATCH 55/56] (CONT-811) removing redundant check for HOME env variable as this is accounted for with the introduction of Dir.home --- lib/puppet-lint/optparser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/optparser.rb b/lib/puppet-lint/optparser.rb index 6351ed21..6931be8d 100644 --- a/lib/puppet-lint/optparser.rb +++ b/lib/puppet-lint/optparser.rb @@ -143,7 +143,7 @@ def self.build(args = []) unless args.include?('--no-config') opt_parser.load('/etc/puppet-lint.rc') - if ENV.key?('HOME') && File.readable?(Dir.home) + if File.readable?(Dir.home) home_dotfile_path = File.expand_path('~/.puppet-lint.rc') opt_parser.load(home_dotfile_path) if File.readable?(home_dotfile_path) end From 95d7dff016b103f39f03e5cb95423eed04d5c15c Mon Sep 17 00:00:00 2001 From: Gavin Patton Date: Tue, 4 Apr 2023 09:46:29 +0100 Subject: [PATCH 56/56] (CONT-811) Regenerated rubocop_todo to account for removal of Gemspec/RequireMFA fix --- .rubocop_todo.yml | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 40005897..f2348889 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,19 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-04-03 10:54:30 UTC using RuboCop version 1.48.1. +# on 2023-04-04 08:44:46 UTC using RuboCop version 1.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'puppet-lint.gemspec' + # Offense count: 4 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. Lint/DuplicateBranch: @@ -35,9 +43,7 @@ Metrics/AbcSize: # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: - Max: 105 - Exclude: - - 'lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb' + Max: 104 # Offense count: 2 # Configuration parameters: CountBlocks. @@ -47,14 +53,14 @@ Metrics/BlockNesting: # Offense count: 7 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 393 + Max: 387 # Offense count: 33 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 33 -# Offense count: 81 +# Offense count: 80 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 108 @@ -62,7 +68,7 @@ Metrics/MethodLength: # Offense count: 26 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 32 + Max: 31 # Offense count: 182 # Configuration parameters: ForbiddenDelimiters. @@ -86,7 +92,7 @@ Performance/CollectionLiteralInLoop: - 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb' - 'lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb' -# Offense count: 408 +# Offense count: 406 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: @@ -137,15 +143,6 @@ RSpec/RepeatedExampleGroupDescription: - 'spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb' - 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb' -# Offense count: 16 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: separated, grouped -Style/AccessorGrouping: - Exclude: - - 'lib/puppet-lint/lexer/string_slurper.rb' - - 'lib/puppet-lint/tasks/puppet-lint.rb' - # Offense count: 106 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle.