Excellent

1,554 views

Published on

Excellent is a static analysis gem that finds the nasty lines in your code. It implements a comprehensive set of checks for possibly buggy parts of your app that would otherwise make it into your repo and eventually to the production server.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,554
On SlideShare
0
From Embeds
0
Number of Embeds
467
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Excellent

  1. 1. Excellent
  2. 2. Me Marco Otte-Witte • 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
  3. 3. 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)
  4. 4. 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!
  5. 5. 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) == ".") { ...
  6. 6. Complexity Measures • Cyclomatic Complexity • ABC metric • Flog • also: method line count, even class name check • etc.
  7. 7. 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!
  8. 8. Rails specific checks 1 class ShoppingBasket < ActiveRecord::Base 2   3   def initialize(items = []) 4     self.items = items 5   end 6   7 end
  9. 9. Rails specific checks 1 class ShoppingBasket < ActiveRecord::Base 2   3   def initialize(items = []) 4     self.items = items 5   end 6   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.
  10. 10. How does it work? • ruby_parser • sexp_processor • Stack of context infos • simple checks on these contexts
  11. 11. 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
  12. 12. with HTML reports
  13. 13. Get it • http://simplabs.github.com/excellent/
  14. 14. Get it • http://simplabs.github.com/excellent/ $ sudo gem install gemcutter $ sudo gem tumble $ sudo gem install excellent
  15. 15. Resources • http://simplabs.github.com/excellent/ • http://wiki.github.com/simplabs/excellent • http://static.simplabs.com/rails3-0-unstable.html • http://parsetree.rubyforge.org/

×