Static code analysis in Ruby 1.9

  • Thread starter Hubert ÅÄ™picki
  • Start date
H

Hubert ÅÄ™picki

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
 
R

Ryan Davis

=20
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.
 
H

Hubert ÅÄ™picki

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.

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.
 
H

Hubert ÅÄ™picki

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.

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.
 
M

Michel Demazure

Hubert said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top