seattlerb / debride

Analyze code for potentially uncalled / dead methods, now with auto-removal.
https://www.zenspider.com/projects/debride.html
720 stars 19 forks source link

Support new Ruby Hash shorthand syntax #51

Open TSMMark opened 1 year ago

TSMMark commented 1 year ago

Style/HashSyntax: Omit the hash value.RuboCop(Style/HashSyntax)

EnforcedShorthandSyntax: always (default)

def foobar
  # This is the new shorthand for { foo: foo }
  { foo: }
end

# Debride sees this as unused:
def foo
  :bar
end

I imagine this would be an easy fix

TSMMark commented 1 year ago

reproduced in test/test_debride.rb with case:

def test_hash_shorthand
  ruby = <<-RUBY.strip
    class Seattle
      def self.status
        { raining?: }
      end

      def self.raining?
        true
      end
    end

    Seattle.status
  RUBY

  assert_process [], ruby
end
Failure:
TestDebride#test_hash_shorthand [test/test_debride.rb:274]:
--- expected
+++ actual
@@ -1 +1 @@
-[]
+[["Seattle", [:raining?]]]
TSMMark commented 1 year ago

got a fix, pr incoming