troessner / reek

Code smell detector for Ruby
https://github.com/troessner/reek
MIT License
4.05k stars 280 forks source link

undefined method `simple_name' for [anonymous class] (NoMethodError) #719

Closed backus closed 9 years ago

backus commented 9 years ago

Very similar to #715:

The following produces an error when reek attempts to parse it:

Foo = Class.new do
  def self.bar; end
end.new

Example run against current master (7ba35a3):

$ git log | head -n1
Wed Sep 23 15:55:35 2015 +0200 7ba35a3 (HEAD -> master, origin/master, origin/HEAD) Merge pull request #716 from troessner/don’t_blow_up_on_Foo_=_new  [Matijs van Zuijlen]
$ cat ../example6.rb
Foo = Class.new do
  def self.bar; end
end.new
$ bin/reek ../example6.rb
/private/tmp/reek/lib/reek/ast/sexp_extensions.rb:188:in `module_creation_receiver?': undefined method `simple_name' for #<#<Class:0x007ff4dd62d278>:0x007ff4dd62d1d8> (NoMethodError)
    from /private/tmp/reek/lib/reek/ast/sexp_extensions.rb:184:in `module_creation_call?'
    from /private/tmp/reek/lib/reek/ast/sexp_extensions.rb:439:in `defines_module?'
    from /private/tmp/reek/lib/reek/tree_walker.rb:60:in `process_casgn'
    from /private/tmp/reek/lib/reek/tree_walker.rb:44:in `process'
    from /private/tmp/reek/lib/reek/tree_walker.rb:38:in `result'
    from /private/tmp/reek/lib/reek/tree_walker.rb:27:in `walk'
    from /private/tmp/reek/lib/reek/examiner.rb:87:in `run'
    from /private/tmp/reek/lib/reek/examiner.rb:42:in `initialize'
    from /private/tmp/reek/lib/reek/cli/reek_command.rb:13:in `new'
    from /private/tmp/reek/lib/reek/cli/reek_command.rb:13:in `block in execute'
    from /private/tmp/reek/lib/reek/cli/reek_command.rb:12:in `each'
    from /private/tmp/reek/lib/reek/cli/reek_command.rb:12:in `execute'
    from /private/tmp/reek/lib/reek/cli/application.rb:31:in `execute'
    from bin/reek:12:in `<main>'
backus commented 9 years ago

Reek would likely benefit from a corpus spec similar to what @mbj built for mbj/mutant. See:

mbj commented 9 years ago

I also use it for unparser. Helps a lot to "have a high chance the engine at least does not crash on the best known ruby-entropy source: rubyspec" ;)

chastell commented 9 years ago

Right, I discovered #710 by running reek over all of Ruby’s *.rb files to find examples for this slide. :)

chastell commented 9 years ago

This is now fixed in the freshly-released reek 3.4.1 – thanks for the bug report!