From f68cfb63f22b5d7bd715318db1e2bc1eb9e82faa Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 9 Dec 2024 14:10:03 -0800 Subject: [PATCH] Fix typos and get things passing against cookstyle Signed-off-by: Tim Smith --- config/chefstyle.yml | 8 ++++---- config/cookstyle.yml | 6 +++--- .../chef/correctness/invalid_platform_family_helper.rb | 2 +- .../cop/chef/deprecation/node_set_without_level.rb | 2 +- lib/rubocop/cop/chef/modernize/windows_registry_uac.rb | 4 ++-- .../cop/chef/redundant/unnecessary_desired_state.rb | 2 +- lib/rubocop/cop/chef/style/comments_copyright_format.rb | 6 +++--- .../cop/chef/style/unnecessary_platform_case_statement.rb | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config/chefstyle.yml b/config/chefstyle.yml index 38789934..4b8a1104 100644 --- a/config/chefstyle.yml +++ b/config/chefstyle.yml @@ -640,7 +640,7 @@ Style/CommentedKeyword: Lint/DeprecatedOpenSSLConstant: Enabled: true -# alert on invalid ruby synatx +# alert on invalid ruby syntax Lint/Syntax: Enabled: true @@ -736,7 +736,7 @@ Style/YAMLFileRead: Bundler/DuplicatedGroup: Enabled: true -# Avoid creating and array and interating into it when .map can be used +# Avoid creating an array and iterating it when .map can be used Style/MapIntoArray: Enabled: true @@ -824,11 +824,11 @@ Layout/LineContinuationSpacing: Lint/RequireRangeParentheses: Enabled: true -# Don't attributes in the gemspec that are deprecated and/or ignored now +# Don't use attributes in the gemspec that are deprecated and/or ignored now Gemspec/DeprecatedAttributeAssignment: Enabled: true -# Don't .map and then .compact when you can use .selct or .reject instead +# Don't .map and then .compact when you can use .select or .reject instead Style/MapCompactWithConditionalBlock: Enabled: true diff --git a/config/cookstyle.yml b/config/cookstyle.yml index 11b1b409..b34d4a24 100644 --- a/config/cookstyle.yml +++ b/config/cookstyle.yml @@ -3164,7 +3164,7 @@ Style/YAMLFileRead: Bundler/DuplicatedGroup: Enabled: true -# Avoid creating and array and interating into it when .map can be used +# Avoid creating an array and iterating it when .map can be used Style/MapIntoArray: Enabled: true @@ -3252,11 +3252,11 @@ Layout/LineContinuationSpacing: Lint/RequireRangeParentheses: Enabled: true -# Don't attributes in the gemspec that are deprecated and/or ignored now +# Don't use attributes in the gemspec that are deprecated and/or ignored now Gemspec/DeprecatedAttributeAssignment: Enabled: true -# Don't .map and then .compact when you can use .selct or .reject instead +# Don't .map and then .compact when you can use .select or .reject instead Style/MapCompactWithConditionalBlock: Enabled: true diff --git a/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb b/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb index ee8686e0..42db3ea2 100644 --- a/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb +++ b/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb @@ -56,7 +56,7 @@ def on_send(node) # if the replacement platform was one of the other platforms passed we can just delete this bad platform if all_passed_platforms.include?(replacement_platform) all_passed_platforms.delete(p.value) - arg_range = p.parent.arguments.first.loc.expression.join(p.parent.arguments[-1].loc.expression.end) + arg_range = p.parent.arguments.first.loc.expression.join(p.parent.arguments.last.loc.expression.end) corrector.replace(arg_range, all_passed_platforms.map { |x| "'#{x}'" }.join(', ')) else corrector.replace(p.loc.expression, p.value.gsub(p.value, "'#{replacement_platform}'")) # gsub to retain quotes diff --git a/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb b/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb index 9c76ab13..8a1d9db9 100644 --- a/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb +++ b/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb @@ -58,7 +58,7 @@ def add_offense_for_bare_assignment(sub_node) if sub_node.receiver == s(:send, nil, :node) # node['foo'] scenario add_offense(sub_node.receiver.loc.selector, severity: :warning) elsif sub_node.receiver && - sub_node.receiver&.node_parts[0] == s(:send, nil, :node) && + sub_node.receiver&.node_parts.first == s(:send, nil, :node) && sub_node.receiver&.node_parts[1] == :[] # node['foo']['bar'] scenario add_offense(sub_node.receiver.node_parts.first.loc.selector, severity: :warning) end diff --git a/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb b/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb index 30fd1a2c..a4f4e3bd 100644 --- a/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +++ b/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb @@ -61,8 +61,8 @@ def on_block(node) # this key has other values we don't support in the windows_uac resource def uac_supported_values?(node) match_property_in_resource?(:registry_key, 'values', node) do |val_prop| - return false unless val_prop&.arguments[0].array_type? # make sure values isn't being passed a variable or method - val_prop.arguments[0].each_value do |array| + return false unless val_prop&.arguments.first.array_type? # make sure values isn't being passed a variable or method + val_prop.arguments.first.each_value do |array| array.each_pair do |key, value| if key == s(:sym, :name) return false unless value.str_type? # make sure it isn't being a variable or method that we can't parse diff --git a/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb b/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb index e19b74e0..461aebf4 100644 --- a/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb +++ b/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb @@ -45,7 +45,7 @@ class UnnecessaryDesiredState < Base def on_send(node) property?(node) do |hash_vals| hash_vals.each_pair do |k, v| - next unless k == s(:sym, :desired_state) && v == s(:true) # cookstyle: disable Lint/BooleanSymbol + next unless k == s(:sym, :desired_state) && v == s(true) # cookstyle: disable Lint/BooleanSymbol add_offense(v.parent, severity: :refactor) do |corrector| range = range_with_surrounding_comma(range_with_surrounding_space(range: v.parent.loc.expression, side: :left), :left) corrector.remove(range) diff --git a/lib/rubocop/cop/chef/style/comments_copyright_format.rb b/lib/rubocop/cop/chef/style/comments_copyright_format.rb index c4277cca..2d4dfbe6 100644 --- a/lib/rubocop/cop/chef/style/comments_copyright_format.rb +++ b/lib/rubocop/cop/chef/style/comments_copyright_format.rb @@ -64,7 +64,7 @@ def copyright_date_range(comment) # no copyright year present so return this year return Time.new.year if dates.empty? - oldest_date = dates.min[0].to_i + oldest_date = dates.min.first.to_i # Avoid returning THIS_YEAR - THIS_YEAR if oldest_date == Time.new.year @@ -77,7 +77,7 @@ def copyright_date_range(comment) def copyright_holder(comment) # Grab just the company / individual name w/o :: or dates match = /(?:.*[0-9]{4}|Copyright\W*)(?:,)?(?:\s)?(.*)/.match(comment.text) - marketing_sanitizer(match.captures[0]) + marketing_sanitizer(match.captures.first) end # Flush Opscode down the memory hole and Chef Inc is not a company @@ -89,7 +89,7 @@ def invalid_copyright_comment?(comment) match = /# (?:Copyright\W*)(.*)/.match(comment.text) return false unless match # it's not even a copyright - current_text = match.captures[0] + current_text = match.captures.first desired_text = "#{copyright_date_range(comment)}, #{copyright_holder(comment)}" true unless current_text == desired_text diff --git a/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb b/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb index b5164d12..4ca9ed67 100644 --- a/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +++ b/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb @@ -75,7 +75,7 @@ def on_case(node) corrector.replace(case_range, "if #{type.value}?(#{condition_string})") # find the range from the start of the when to the end of the last argument - conditional_range = node.when_branches.first.conditions[-1].source_range.join(node.when_branches.first.loc.keyword.begin) + conditional_range = node.when_branches.first.conditions.last.source_range.join(node.when_branches.first.loc.keyword.begin) # remove the when XYZ condition along with any leading spaces so that we remove the whole empty line corrector.remove(range_with_surrounding_space(range: conditional_range, side: :left))