Skip to content

Commit

Permalink
Remove OpenStruct from primer_octicon cop
Browse files Browse the repository at this point in the history
OpenStruct will not be included in modern Ruby versions, so we should not rely on it being there.
This removes usage and instead builds the same class instance that is returned above.

irb(main):003> h = RuboCop::AST::HashNode.new(hash)
=> s(:hash)
irb(main):004> h.keys
=> []
irb(main):005> h.pairs
=> []
irb(main):006> h.type
=> :hash
  • Loading branch information
HParker committed Sep 4, 2024
1 parent 35a735c commit c7693cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/primer/primer_octicon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def string_args_to_string(node)
def kwargs(node)
return node.arguments.last if node.arguments.size > 1

OpenStruct.new(keys: [], pairs: [], type: :hash)
RuboCop::AST::HashNode.new("hash")
end

def icon(node)
Expand Down
9 changes: 9 additions & 0 deletions test/lib/rubocop/primer_octicon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,13 @@ def test_medium_size

assert_correction "primer_octicon(:icon, size: :medium)"
end

def test_no_args
investigate(cop, <<-RUBY)
octicon
RUBY

raise "run"
assert_correction "primer_octicon"

Check failure on line 283 in test/lib/rubocop/primer_octicon_test.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/UnreachableCode: Unreachable code detected.
end
end

0 comments on commit c7693cb

Please sign in to comment.