flog fails on empty files and files containing only comments #18

Closed
rrschmidt opened this Issue Dec 25, 2012 · 1 comment

2 participants

@rrschmidt

When running flog over on of my rails projects I ran into this problem:

/home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:297:in flog_ruby!': undefined methodmass' for nil:NilClass (NoMethodError)
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:266:in flog_ruby'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:256:in
block in flog'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:253:in each'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:253:in
flog'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/bin/flog:13:in <top (required)>'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/flog:19:in
load'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/flog:19:in <main>'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in
eval'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `

'

I was able to reproduce the problem on a plain new rails project:

ruediger@RS-HP-NB:~/git_projects/flog_test/flog_test$ find . -name *.rb | xargs flog -av
** flogging ./app/controllers/application_controller.rb
** flogging ./app/helpers/application_helper.rb
** flogging ./config/application.rb
** flogging ./config/boot.rb
** flogging ./config/environment.rb
** flogging ./config/environments/development.rb
** flogging ./config/environments/production.rb
** flogging ./config/environments/test.rb
** flogging ./config/initializers/backtrace_silencers.rb
/home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:297:in flog_ruby!': undefined methodmass' for nil:NilClass (NoMethodError)
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:266:in flog_ruby'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:256:in
block in flog'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:253:in each'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/lib/flog.rb:253:in
flog'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/gems/flog-3.2.1/bin/flog:13:in <top (required)>'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/flog:19:in
load'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/flog:19:in <main>'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in
eval'
from /home/ruediger/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `

'

The file in question (backtrace_silencers.rb) contains only comments. It seems that makes the parser return nil in flog.rb, line 296 which leads to the 'undefined method' error above.

Running flog over an empty rb file results in the same error.

Putting an "if ast" around lines 297 and 298 seems to fix the problem, but I'm not sure whether this may cause unexpected side effects and maybe a cleaner solution is to make the parser object return a non-nil result for empty and comment-only files.

@zenspider zenspider was assigned Jan 3, 2013
@zenspider
Seattle Ruby Brigade member

thanks

@zenspider zenspider closed this Jan 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment