+ All Categories
Home > Technology > Excellent

Excellent

Date post: 29-Nov-2014
Category:
Upload: marco-otte-witte
View: 2,374 times
Download: 2 times
Share this document with a friend
Description:
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.
15
Excellent
Transcript
Page 1: Excellent

Excellent

Page 2: 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

Page 3: Excellent

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)

Page 4: Excellent

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!

Page 5: Excellent

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) == ".") {

...

Page 6: Excellent

Complexity Measures

• Cyclomatic Complexity

• ABC metric

• Flog

• also: method line count, even class name check

• etc.

Page 7: Excellent

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!

Page 8: Excellent

Rails specific checks1 class ShoppingBasket < ActiveRecord::Base2  3   def initialize(items = [])4     self.items = items5   end6  7 end

Page 9: Excellent

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.

Page 10: Excellent

How does it work?

• ruby_parser

• sexp_processor

• Stack of context infos

• simple checks on these contexts

Page 11: Excellent

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

Page 12: Excellent

with HTML reports

Page 13: Excellent

Get it

• http://simplabs.github.com/excellent/

Page 14: Excellent

Get it

• http://simplabs.github.com/excellent/

$ sudo gem install gemcutter$ sudo gem tumble$ sudo gem install excellent


Recommended