Date post: | 29-Nov-2014 |
Category: |
Technology |
Upload: | marco-otte-witte |
View: | 2,374 times |
Download: | 2 times |
Excellent
Me
• Freelancer since 2007
• Web Development since ~1998
• PHP => (Java) => .NET => Ruby (on Rails)
• http://simplabs.com
• http://xing.com/profile/Marco_OtteWitte
• http://github.com/marcoow
Marco Otte-Witte
Excellent
• static code analysis for Ruby
• like roodi, flog, reek etc. but more
• static code analysis for Rails
• (it‘s still beta despite the 1.5.4 - be kind)
Static Analysis
• it‘s not about finding errors
• it‘s no red/ green, no fail/ pass
• it‘s about getting hints on possible problems
• don‘t try to code for zero warnings!
Complexity Measures global.checkEmail = function(e) { function checkChars(s, i, l) { while (i < l && "_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".indexOf(s.charAt(i)) != -1) { i = ++i; } // end while return (i); } function checkFirstLevelDomainChars(s, i, l) { while (i < l && "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(s.charAt(j)) != -1) { i = ++i; } // end while return (i == l); } // End of the function var _loc1; var j; var _loc2 = e.length; var _loc4 = false; _loc1 = checkChars(e, 0, _loc2); if (checkChars(e, 0, _loc2) == 0) { return (-1); } // end if j = _loc1; while (_loc1 < _loc2 && e.charAt(_loc1) == ".") {
...
Complexity Measures
• Cyclomatic Complexity
• ABC metric
• Flog
• also: method line count, even class name check
• etc.
Rails specific checks• no restriction on (sometimes helpful, sometime not
so helpful) complexity measures etc.
• Rails checks can be red/ green
• no magic, finds stuff you forgot/ didn‘t know about
• AttrAccessibleCheck: specify attr_accessible!
• ValidationsCheck: validate!
• InstanceVarInPartialCheck: don‘t use instance vars in partials!
Rails specific checks1 class ShoppingBasket < ActiveRecord::Base2 3 def initialize(items = [])4 self.items = items5 end6 7 end
Rails specific checks1 class ShoppingBasket < ActiveRecord::Base2 3 def initialize(items = [])4 self.items = items5 end6 7 end
$ excellent shopping_basket.rb Excellent result: test.rb * Line 1: ShoppingBasket does not validate any attributes. * Line 1: ShoppingBasket defines initialize method. * Line 1: ShoppingBasket does not specify attr_accessible. Found 3 warnings.
How does it work?
• ruby_parser
• sexp_processor
• Stack of context infos
• simple checks on these contexts
Run it via rake
1 require 'simplabs/excellent/rake'2 3 desc 'Analyse the Excellent source with itself.'4 Simplabs::Excellent::Rake::ExcellentTask.new(:excellent) do |t|5 t.html = 'doc/excellent.html'6 t.paths = ['lib']7 end
with HTML reports
Get it
• http://simplabs.github.com/excellent/
Get it
• http://simplabs.github.com/excellent/
$ sudo gem install gemcutter$ sudo gem tumble$ sudo gem install excellent
Resources
• http://simplabs.github.com/excellent/
• http://wiki.github.com/simplabs/excellent
• http://static.simplabs.com/rails3-0-unstable.html
• http://parsetree.rubyforge.org/