Static code analysis in Ruby 1.9

Hi guys,

I am wondering if there is any way to perform sort of static code
analysis for Ruby 1.9 based programs. I don’t need nothing fancy, just
some sort of “code complexity” metric that I could analyse over time.
I wanted to use Flog (http://ruby.sadi.st/Flog.html) but it fails on
1.9 syntax (hashes).

I am wondering if I can perform 1.9 code analysis with other tools? If
not, maybe I can convert 1.9 code to 1.8 code in some automatic way?

Thanks,
Hubert

Hubert Lepicki wrote:

I am wondering if there is any way to perform sort of static code
analysis for Ruby 1.9 based programs.

See the Ripper standard library which comes with Ruby 1.9:
http://www.artweb-design.de/2009/7/5/using-ruby-1-9-ripper

Cheers.

On 24 Sie, 03:16, Ryan D. [email protected] wrote:

I’ve got a code contribution that will convert ripper output into unified ParseTree-compatibile output, but I haven’t gotten around to integrating it. I think I’m probably going to use it to sanity check my parser as I add 1.9 compatibility to it.

Well, that’s a good link, thank you for that. I think for now I’ll
write sort of very simple ABC calculating routine myself. Have looked
at Flog source code and it should be much better to use that, however
I don’t have much time to spend on that now (need to see the results
fast).

Ryan, if you need a hand with integrating your Ripple to ruby_parser
format ASTs with your tools I’m happy to help.

On Aug 23, 2010, at 14:59 , Suraj K. wrote:

Hubert Lepicki wrote:

I am wondering if there is any way to perform sort of static code
analysis for Ruby 1.9 based programs.

See the Ripper standard library which comes with Ruby 1.9:
http://www.artweb-design.de/2009/7/5/using-ruby-1-9-ripper

Unfortunately that doesn’t really help him much. He’s still left hanging
with actually analyzing the code.

I’ve got a code contribution that will convert ripper output into
unified ParseTree-compatibile output, but I haven’t gotten around to
integrating it. I think I’m probably going to use it to sanity check my
parser as I add 1.9 compatibility to it.

On 24 Sie, 11:30, Hubert Łępicki [email protected] wrote:

Ryan, if you need a hand with integrating your Ripple to ruby_parser
format ASTs with your tools I’m happy to help.

Ok, I have commited this crime in the meantime:

gives me good enough inteligence where should I look for bad code.
Certainly needs some more work but it’s usable with some pain.

Hubert Lepicki wrote:

I am wondering if I can perform 1.9 code analysis with other tools? If
not, maybe I can convert 1.9 code to 1.8 code in some automatic way?

Thanks,
Hubert

For quite a long time now, I have been using all the 1.8 tools (flog,
flay, reek, …) after filtering the 1.9 files thru the following ad hoc
rake tast

desc “copy in flog_temp with 1.8 hash syntax, ascii characters and unix
end_of_line”
task :convert do
flog_temp = File.join(SRC, ‘flog_temp’)
Dir.chdir(flog_temp)
Dir.glob(’/*.rb’) { |name| File.delete(name) }
Dir.chdir(SRC)
list = Dir.glob('lib/
/*.rb’)
list.each do |name|
arr = IO.readlines(File.join(SRC, name))
File.open(File.join(flog_temp, name), “wb:utf-8”) do |f|
arr.each do |line|
line.gsub!(/:(nodoc|startdoc|stopdoc):/, “”)
line.gsub!(/(\w+):\s+/, ':\1 => ')
line.gsub!(/[éèà êîôùïöüë]/, “_”)
f.print line
end
end
end
end

HTH,
_md