Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `name' for #<Fasterer::Primitive:0x00007f9a2092afd8> #77

Closed
manuelmeurer opened this issue Feb 4, 2020 · 2 comments
Closed

Comments

@manuelmeurer
Copy link

I just installed fasterer 0.8.1 and got the following error on running it:

% fasterer
app/models/freelancers/freelancer.rb:149 Array#reverse.each is slower than Array#reverse_each.

app/models/concerns/has_phone_numbers.rb:100 Using tr is faster than gsub when replacing a single character in a string with another single character.

app/dashboards/freelancers/freelancer_dashboard.rb:102 Hash#keys.each is slower than Hash#each_key. N.B. Hash#each_key cannot be used if the hash is modified during the each block.

app/controllers/admin/freelancers_controller.rb:137 Array#select.last is slower than Array#reverse.detect.

Traceback (most recent call last):
	34: from /Users/manuel/.rbenv/versions/2.6.5/bin/fasterer:23:in `<main>'
	33: from /Users/manuel/.rbenv/versions/2.6.5/bin/fasterer:23:in `load'
	32: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/bin/fasterer:5:in `<top (required)>'
	31: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/cli.rb:7:in `execute'
	30: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/file_traverser.rb:26:in `traverse'
	29: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/file_traverser.rb:49:in `traverse_files'
	28: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/file_traverser.rb:49:in `each'
	27: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/file_traverser.rb:49:in `block in traverse_files'
	26: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/file_traverser.rb:57:in `scan_file'
	25: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:22:in `scan'
	24: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `traverse_sexp_tree'
	23: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `each'
	22: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `block in traverse_sexp_tree'
	21: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `traverse_sexp_tree'
	20: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `each'
	19: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `block in traverse_sexp_tree'
	18: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `traverse_sexp_tree'
	17: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `each'
	16: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `block in traverse_sexp_tree'
	15: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `traverse_sexp_tree'
	14: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `each'
	13: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `block in traverse_sexp_tree'
	12: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `traverse_sexp_tree'
	11: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `each'
	10: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `block in traverse_sexp_tree'
	 9: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `traverse_sexp_tree'
	 8: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `each'
	 7: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:45:in `block in traverse_sexp_tree'
	 6: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:36:in `traverse_sexp_tree'
	 5: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:54:in `scan_by_token'
	 4: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:71:in `scan_method_calls'
	 3: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/analyzer.rb:71:in `new'
	 2: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/scanners/method_call_scanner.rb:13:in `initialize'
	 1: from /Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/scanners/method_call_scanner.rb:48:in `check_offense'
/Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fasterer-0.8.1/lib/fasterer/scanners/method_call_scanner.rb:135:in `check_symbol_to_proc': undefined method `name' for #<Fasterer::Primitive:0x00007f9a2092afd8> (NoMethodError)
DamirSvrtan added a commit that referenced this issue Feb 5, 2020
…ge or array

Fixes the following issue: #77. Happens when somebody invokes a method with no args on an array or range in a block. Example in the spec.
@DamirSvrtan
Copy link
Owner

Hi! 👋 Thanks for reporting the issue, i've released fasterer version 0.8.2 with a fix for this situation.

I would really love to know whether you can check your code, as from what I see, it looks like you have a iterator that has a block that invokes a method with no arguments on an array or a range, and I'm not sure what the use case would be, but potentially could be a bug.

The code would look like something like this:

collection.each do |element|
  [].perform_something
end

If you look at the code above, it does not make a lot of sense to iterate and then invoke a method on a different array or range. But I might be wrong, and maybe everything's alright with your code, I might not just see a scenario like that.

Please let me know if the fix helped you.

@manuelmeurer
Copy link
Author

Hi @DamirSvrtan, thanks for the quick fix! I installed v0.8.2 and indeed the error doesn't happen anymore.
My codebase is quite large, so I can't easily look for the iterator you describe.
Maybe you could add a --verbose option that outputs the file being checked, if that's possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants