Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Static code analysis in Ruby 1.9

2 views
Skip to first unread message

Hubert Łępicki

unread,
Aug 23, 2010, 5:40:20 PM8/23/10
to
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

Suraj Kurapati

unread,
Aug 23, 2010, 5:59:16 PM8/23/10
to
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.
--
Posted via http://www.ruby-forum.com/.

Ryan Davis

unread,
Aug 23, 2010, 9:16:21 PM8/23/10
to

On Aug 23, 2010, at 14:59 , Suraj Kurapati 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.


Hubert Łępicki

unread,
Aug 24, 2010, 5:30:54 AM8/24/10
to

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.

Hubert Łępicki

unread,
Aug 24, 2010, 7:48:28 AM8/24/10
to

Ok, I have commited this crime in the meantime:
http://github.com/hubertlepicki/metric_abc

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

Michel Demazure

unread,
Aug 24, 2010, 12:07:34 PM8/24/10
to
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

0 new messages