Skip to content

Commit

Permalink
Fix typos and get things passing against cookstyle
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith84@gmail.com>
  • Loading branch information
tas50 committed Dec 9, 2024
1 parent d685aa6 commit f68cfb6
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions config/chefstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ Style/CommentedKeyword:
Lint/DeprecatedOpenSSLConstant:
Enabled: true

# alert on invalid ruby synatx
# alert on invalid ruby syntax
Lint/Syntax:
Enabled: true

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions config/cookstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/chef/deprecation/node_set_without_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/chef/modernize/windows_registry_uac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/chef/style/comments_copyright_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f68cfb6

Please sign in to comment.