excellent 1.7.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/History.txt +9 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +123 -0
  4. data/bin/excellent +49 -12
  5. data/lib/simplabs/excellent.rb +2 -2
  6. data/lib/simplabs/excellent/checks.rb +1 -1
  7. data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +1 -1
  8. data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +1 -1
  9. data/lib/simplabs/excellent/checks/base.rb +12 -9
  10. data/lib/simplabs/excellent/checks/case_missing_else_check.rb +1 -1
  11. data/lib/simplabs/excellent/checks/class_line_count_check.rb +3 -3
  12. data/lib/simplabs/excellent/checks/class_name_check.rb +5 -5
  13. data/lib/simplabs/excellent/checks/{singleton_variable_check.rb → class_variable_check.rb} +3 -3
  14. data/lib/simplabs/excellent/checks/control_coupling_check.rb +1 -1
  15. data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +4 -4
  16. data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +3 -3
  17. data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +2 -2
  18. data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +1 -1
  19. data/lib/simplabs/excellent/checks/flog_block_check.rb +2 -2
  20. data/lib/simplabs/excellent/checks/flog_check.rb +3 -3
  21. data/lib/simplabs/excellent/checks/flog_class_check.rb +2 -2
  22. data/lib/simplabs/excellent/checks/flog_method_check.rb +2 -2
  23. data/lib/simplabs/excellent/checks/for_loop_check.rb +1 -1
  24. data/lib/simplabs/excellent/checks/global_variable_check.rb +5 -2
  25. data/lib/simplabs/excellent/checks/line_count_check.rb +3 -3
  26. data/lib/simplabs/excellent/checks/method_line_count_check.rb +2 -2
  27. data/lib/simplabs/excellent/checks/method_name_check.rb +5 -4
  28. data/lib/simplabs/excellent/checks/module_line_count_check.rb +2 -2
  29. data/lib/simplabs/excellent/checks/module_name_check.rb +3 -3
  30. data/lib/simplabs/excellent/checks/name_check.rb +4 -4
  31. data/lib/simplabs/excellent/checks/nested_iterators_check.rb +2 -2
  32. data/lib/simplabs/excellent/checks/parameter_number_check.rb +1 -1
  33. data/lib/simplabs/excellent/checks/rails/attr_accessible_check.rb +1 -1
  34. data/lib/simplabs/excellent/checks/rails/attr_protected_check.rb +1 -1
  35. data/lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb +1 -1
  36. data/lib/simplabs/excellent/checks/rails/instance_var_in_partial_check.rb +1 -1
  37. data/lib/simplabs/excellent/checks/rails/params_hash_in_view_check.rb +1 -1
  38. data/lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb +1 -1
  39. data/lib/simplabs/excellent/checks/rails/validations_check.rb +1 -1
  40. data/lib/simplabs/excellent/formatters/text.rb +7 -1
  41. data/lib/simplabs/excellent/parsing/gvar_context.rb +0 -8
  42. data/lib/simplabs/excellent/parsing/loc_parser.rb +94 -0
  43. data/lib/simplabs/excellent/parsing/resbody_context.rb +0 -6
  44. data/lib/simplabs/excellent/runner.rb +49 -32
  45. data/lib/simplabs/excellent/warning.rb +1 -4
  46. metadata +23 -49
  47. data/README.rdoc +0 -72
  48. data/VERSION.yml +0 -4
  49. data/lib/simplabs/excellent/extensions/string.rb +0 -28
  50. data/spec/checks/abc_metric_method_check_spec.rb +0 -122
  51. data/spec/checks/assignment_in_conditional_check_spec.rb +0 -90
  52. data/spec/checks/case_missing_else_check_spec.rb +0 -46
  53. data/spec/checks/class_line_count_check_spec.rb +0 -62
  54. data/spec/checks/class_name_check_spec.rb +0 -48
  55. data/spec/checks/control_coupling_check_spec.rb +0 -103
  56. data/spec/checks/cyclomatic_complexity_block_check_spec.rb +0 -47
  57. data/spec/checks/cyclomatic_complexity_method_check_spec.rb +0 -210
  58. data/spec/checks/empty_rescue_body_check_spec.rb +0 -170
  59. data/spec/checks/flog_block_check_spec.rb +0 -28
  60. data/spec/checks/flog_class_check_spec.rb +0 -28
  61. data/spec/checks/flog_method_check_spec.rb +0 -46
  62. data/spec/checks/for_loop_check_spec.rb +0 -52
  63. data/spec/checks/global_variable_check_spec.rb +0 -66
  64. data/spec/checks/method_line_count_check_spec.rb +0 -49
  65. data/spec/checks/method_name_check_spec.rb +0 -112
  66. data/spec/checks/module_line_count_check_spec.rb +0 -48
  67. data/spec/checks/module_name_check_spec.rb +0 -61
  68. data/spec/checks/nested_iterators_check_spec.rb +0 -44
  69. data/spec/checks/parameter_number_check_spec.rb +0 -97
  70. data/spec/checks/rails/attr_accessible_check_spec.rb +0 -79
  71. data/spec/checks/rails/attr_protected_check_spec.rb +0 -77
  72. data/spec/checks/rails/custom_initialize_method_check_spec.rb +0 -58
  73. data/spec/checks/rails/instance_var_in_partial_check_spec.rb +0 -40
  74. data/spec/checks/rails/params_hash_in_view_check_spec.rb +0 -40
  75. data/spec/checks/rails/session_hash_in_view_check_spec.rb +0 -40
  76. data/spec/checks/rails/validations_check_spec.rb +0 -81
  77. data/spec/checks/singleton_variable_check_spec.rb +0 -66
  78. data/spec/extensions/string_spec.rb +0 -13
  79. data/spec/spec_helper.rb +0 -13
data/History.txt CHANGED
@@ -1,9 +1,18 @@
1
1
  =======
2
+ = 2.0.0
3
+
4
+ * now supporting config file .excellent.yml in current working directory to configure which specs to run/ not to run with thresholds, patterns etc.
5
+ * predefined globals will not be reported anymore ($!, $@, $&, $`, $', $+, $1, $2.., $~, $=, $/, $\, $,, $;, $., $<, $>, $_, $0, $*, $$, $?, $:, $", $DEBUG, $FILENAME, $LOAD_PATH, $stdin, $stdout, $stderr, $VERBOSE, option variables, $-0, $-a, $-d, $-F, $-i, $-I, $-l, $-p, $-v)
6
+ * enabled previously disable checks again: AbcMetricMethodCheck, ControlCouplingCheck, CyclomaticComplexityBlockCheck, CyclomaticComplexityMethodCheck, ForLoopCheck, FlogBlockCheck, FlogClassCheck, FlogMethodCheck
7
+ * testing now uses Rspec 2
8
+ * internal cleanups/ simplifications
9
+
2
10
  = 1.7.2
3
11
 
4
12
  * fixed Simplabs::Excellent::Checks::Rails::CustomInitializeMethodCheck
5
13
  * fixed Simplabs::Excellent::Checks::MethodNameCheck so it allows method names that exist in Ruby itself
6
14
  * fixed Simplabs::Excellent::Checks::GlobalVariableCheck so it doesn't report false positives for rescue bodies
15
+ * made the parser more forgiving/stable in some situations
7
16
 
8
17
  = 1.7.1
9
18
 
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2009 Marco Otte-Witte
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ Excellent
2
+ =========
3
+
4
+ [![Build Status](https://travis-ci.org/simplabs/excellent.png)](https://travis-ci.org/simplabs/excellent)
5
+
6
+ Excellent **finds the nasty lines in your code**. It implements a comprehensive set of checks for possibly
7
+ buggy parts of your app that would **otherwise make it into your repo and eventually to the production server**.
8
+
9
+ See the API documentation at [http://docs.github.com/simplabs/excellent](http://docs.github.com/simplabs/excellent)
10
+ and the Wiki at [http://wiki.github.com/simplabs/excellent](http://wiki.github.com/simplabs/excellent).
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Simply install with Ruby Gems:
16
+
17
+ ```bash
18
+ gem install excellent
19
+ ```
20
+
21
+ Example
22
+ -------
23
+
24
+ Assume you have the following class definition,
25
+
26
+ ```ruby
27
+ class ShoppingBasket < ActiveRecord::Base
28
+
29
+ def initialize(items = [])
30
+ self.items = items
31
+ end
32
+
33
+ end
34
+ ````
35
+
36
+ then Excellent will report the problems in this piece of code:
37
+
38
+ ```bash
39
+ $ excellent shopping_basket.rb
40
+
41
+ Excellent result:
42
+
43
+ test.rb
44
+ * Line 1: ShoppingBasket does not validate any attributes.
45
+ * Line 1: ShoppingBasket defines initialize method.
46
+ * Line 1: ShoppingBasket does not specify attr_accessible.
47
+
48
+ Found 3 warnings.
49
+ ```
50
+
51
+ To analyse all the models in your Rails application, just do
52
+
53
+ ```bash
54
+ excellent app/models
55
+ ```
56
+
57
+ in your `RAILS_ROOT`. You can also invoke analysation through the `Simplabs::Excellent::Runner` class.
58
+ Excellent can also produce HTML output. To get a formatted HTML report, just specify `html:<filename>`:
59
+
60
+ ```bash
61
+ excellent -o out.html app/models
62
+ ```
63
+
64
+ You can also use Excellent in a Rake task:
65
+
66
+ ```ruby
67
+ require 'simplabs/excellent/rake'
68
+
69
+ Simplabs::Excellent::Rake::ExcellentTask.new(:excellent) do |t|
70
+ t.html = 'doc/excellent.html' # optional, if you don't specify html, output will be written to $stdout
71
+ t.paths = %w(app lib)
72
+ end
73
+ ```
74
+
75
+ Configuration
76
+ -------------
77
+
78
+ You can configure which checks to run and which thresholds etc. to use. Simply place a `.excellent.yml` in the
79
+ root directory of you project (the directory that you will be starting excellent from). You can enable/disable
80
+ by using the check name as hash key and specifying a truthy/falsy value:
81
+
82
+ ```yaml
83
+ AbcMetricMethodCheck: true
84
+ AssignmentInConditionalCheck: false
85
+ ```
86
+
87
+ By default all checks are enabled so you would usually only switch off certain checks you're not interested in.
88
+ Some checks also take cofngigurations like thresholds, patterns etc. You can configure those by simply defining
89
+ nested hashes in the YAML:
90
+
91
+ ```yaml
92
+ ClassLineCountCheck:
93
+ threshold: 500
94
+ MethodNameCheck:
95
+ pattern: '^[a-z].*'
96
+ ```
97
+
98
+ This would for example only report classes with more than 500 lines and require that all method names start
99
+ with a lower case letter.
100
+
101
+ You can get a list of the enabled checks and their configurations by running:
102
+
103
+ ```bash
104
+ excellent --checks
105
+ ```
106
+
107
+ Static analysis
108
+ ---------------
109
+
110
+ A few words regarding static code analysis: Static code analysis tools like Excellent can never really
111
+ understand the code. They just search for patterns that *might* inidicate problematic code. The word **might**
112
+ really has to be stressed here since static analysis will usually return a reasonable number of false
113
+ positives. For example, there might be pretty good reasons for empty +rescue+ blocks that suppress all
114
+ errors (Excellent itself does it). So, don't try and code with the aim of passing Excellent with zero warnings.
115
+ That will most likely make your code a mess. Instead use Excellent as a helper to find **potentially**
116
+ problematic code early.
117
+
118
+ Author
119
+ ------
120
+
121
+ Copyright (c) 2008-2013 Marco Otte-Witte ([http://simplabs.com](http://simplabs.com)), released under the MIT license.
122
+
123
+ Excellent was inspired by roodi ([https://github.com/martinjandrews/roodi](https://github.com/martinjandrews/roodi)), reek ([https://github.com/troessner/reek](https://github.com/troessner/reek)) and flog ([https://github.com/seattlerb/flog](https://github.com/seattlerb/flog)).
data/bin/excellent CHANGED
@@ -8,9 +8,12 @@ options = {}
8
8
 
9
9
  optparse = OptionParser.new do |opt|
10
10
  opt.banner = 'Usage: excellent [OPTIONS] <PATH1> [<PATH2> ...]'
11
- opt.on('--output', '-o [FILE]', 'Write HTML output to [FILE].') do |target|
11
+ opt.on('--output', '-o [FILE]', 'Write HTML output to [FILE]') do |target|
12
12
  options[:output] = target
13
13
  end
14
+ opt.on('--checks', 'Show a list of the enabled checks and their configuraton values') do |target|
15
+ options[:print_checks] = true
16
+ end
14
17
  opt.on_tail('--help', '-h', 'Help') do
15
18
  puts optparse
16
19
  exit
@@ -24,27 +27,61 @@ end
24
27
  optparse.parse!
25
28
 
26
29
  target = options[:output]
27
- paths = ARGV.dup
28
-
29
- if paths.empty?
30
- puts "\n You must specify one or more directories to analyse, e.g.:\n"
31
- puts "\n excellent lib/\n\n"
32
- exit 1
33
- end
34
-
35
30
  if target
36
31
  begin
37
32
  fileio = File.open(target, 'w+')
38
33
  formatter = Simplabs::Excellent::Formatters::Html.new(fileio)
39
34
  rescue Errno::ENOENT
40
- puts "\n #{target} cannot be opened for writing. Specify a file name like so:\n"
41
- puts "\n excellent -o excellent.html lib/\n\n"
35
+ puts "\n **#{target} cannot be opened for writing. Specify a file name like so:\n"
36
+ puts "\n excellent -o excellent.html lib/\n\n"
42
37
  end
43
38
  else
44
39
  formatter = Simplabs::Excellent::Formatters::Text.new
45
40
  end
46
41
 
47
- excellent = Simplabs::Excellent::Runner.new
42
+ custom_config = {}
43
+ config_file = File.join(Dir.pwd, '.excellent.yml')
44
+ if File.exists?(config_file)
45
+ require 'yaml'
46
+ begin
47
+ custom_config = YAML.load(File.open(config_file)) || {}
48
+ config_valid = custom_config.is_a?(Hash) && custom_config.all? do |key, value|
49
+ key.is_a?(String) || key.is_a?(Symbol)
50
+ end
51
+ rescue Exception
52
+ config_valid = false
53
+ end
54
+ unless config_valid
55
+ puts "\n ** The configuration in #{config_file} is not valid!\n\n"
56
+ puts " Please make sure you specify a hash with check names as keys and hashes or truthy/falsy values as hash values, e.g.:\n\n"
57
+ puts " AbcMetricMethodCheck:"
58
+ puts " false"
59
+ puts " ClassLineCountCheck:"
60
+ puts " threshold: 10"
61
+ puts "\n\n"
62
+ exit 1
63
+ end
64
+ end
65
+
66
+ excellent = Simplabs::Excellent::Runner.new(custom_config)
67
+
68
+ if options[:print_checks]
69
+ puts "\n Configured Checks\n\n"
70
+ excellent.checks.each do |check|
71
+ puts " #{check.class.name.gsub('Simplabs::Excellent::Checks::', '')}"
72
+ check.options.each do |key, value|
73
+ puts " #{key}: #{value}"
74
+ end
75
+ end
76
+ exit 0
77
+ end
78
+
79
+ paths = ARGV.dup
80
+ if paths.empty?
81
+ puts "\n **You must specify one or more directories to analyse, e.g.:\n"
82
+ puts "\n excellent lib/\n\n"
83
+ exit 1
84
+ end
48
85
 
49
86
  begin
50
87
  excellent.check_paths(paths, formatter)
@@ -2,14 +2,14 @@ require 'simplabs/excellent/checks'
2
2
  require 'simplabs/excellent/parsing'
3
3
  require 'simplabs/excellent/formatters'
4
4
  require 'simplabs/excellent/runner'
5
- require 'rubygems'
6
5
  require 'sexp'
6
+ require 'hashr'
7
7
 
8
8
  module Simplabs #:nodoc:
9
9
 
10
10
  module Excellent #:nodoc:
11
11
 
12
- VERSION = '1.7.2'
12
+ VERSION = '2.0.0'
13
13
 
14
14
  end
15
15
 
@@ -14,7 +14,7 @@ require 'simplabs/excellent/checks/assignment_in_conditional_check'
14
14
  require 'simplabs/excellent/checks/case_missing_else_check'
15
15
  require 'simplabs/excellent/checks/class_line_count_check'
16
16
  require 'simplabs/excellent/checks/class_name_check'
17
- require 'simplabs/excellent/checks/singleton_variable_check'
17
+ require 'simplabs/excellent/checks/class_variable_check'
18
18
  require 'simplabs/excellent/checks/global_variable_check'
19
19
  require 'simplabs/excellent/checks/control_coupling_check'
20
20
  require 'simplabs/excellent/checks/cyclomatic_complexity_block_check'
@@ -23,7 +23,7 @@ module Simplabs
23
23
  DEFAULT_THRESHOLD = 10
24
24
 
25
25
  def initialize(options = {}) #:nodoc:
26
- super()
26
+ super
27
27
  @threshold = options[:threshold] || DEFAULT_THRESHOLD
28
28
  @interesting_contexts = [Parsing::MethodContext, Parsing::SingletonMethodContext]
29
29
  end
@@ -21,7 +21,7 @@ module Simplabs
21
21
  class AssignmentInConditionalCheck < Base
22
22
 
23
23
  def initialize(options = {}) #:nodoc:
24
- super()
24
+ super
25
25
  @interesting_contexts = [Parsing::IfContext, Parsing::WhileContext, Parsing::UntilContext]
26
26
  @interesting_files = [/\.rb$/, /\.erb$/]
27
27
  end
@@ -10,7 +10,9 @@ module Simplabs
10
10
  # will invoke the +evaluate_context+ method of all checks that specify the context as one if their +interesting_contexts+.
11
11
  class Base
12
12
 
13
- attr_reader :warnings
13
+ attr_reader :warnings #:nodoc:
14
+
15
+ attr_reader :options #:nodoc:
14
16
 
15
17
  # An array of contexts that are interesting for the check. These contexts are based on symbols as returned by RubyParser (see
16
18
  # http://parsetree.rubyforge.org/ruby_parser/) and add some additional data,
@@ -23,12 +25,14 @@ module Simplabs
23
25
  # Defaults to /\.rb$/. If you do not specify anything else in custom checks, only *.rb files will be processed
24
26
  attr_reader :interesting_files
25
27
 
26
- def initialize #:nodoc:
27
- @warnings = []
28
- @interesting_files = [/\.rb$/]
28
+ def initialize(options = {}) #:nodoc:
29
+ @options = options
30
+ @interesting_contexts = []
31
+ @warnings = []
32
+ @interesting_files = [/\.rb$/]
29
33
  end
30
34
 
31
- # This method is called whenever Excellent processes a context that the check specified as one of the contexts it is interested in (see
35
+ # This method is called whenever Excellent processes a context that the check specified as one of the contexts it is interested in (see
32
36
  # interesting_contexts).
33
37
  #
34
38
  # ==== Parameters
@@ -47,14 +51,13 @@ module Simplabs
47
51
  # * <tt>info</tt> - The information hash that contains more info on the finding.
48
52
  # * <tt>offset</tt> - The line offset that is added to the context's line property.
49
53
  def add_warning(context, message, info = {}, offset = 0)
50
- klass = self.class
51
- @warnings << Simplabs::Excellent::Warning.new(klass, message, context.file, context.line + offset, info)
54
+ @warnings << Simplabs::Excellent::Warning.new(message, context.file, context.line + offset, info)
52
55
  end
53
-
56
+
54
57
  def warnings_for(filename) #:nodoc:
55
58
  warnings.select { |warning| warning.filename == filename }
56
59
  end
57
-
60
+
58
61
  end
59
62
 
60
63
  end
@@ -15,7 +15,7 @@ module Simplabs
15
15
  # * +case+ statements
16
16
  class CaseMissingElseCheck < Base
17
17
 
18
- def initialize #:nodoc:
18
+ def initialize(options = {}) #:nodoc:
19
19
  super
20
20
  @interesting_contexts = [Parsing::CaseContext]
21
21
  @interesting_files = [/\.rb$/, /\.erb$/]
@@ -14,11 +14,11 @@ module Simplabs
14
14
  # * classes
15
15
  class ClassLineCountCheck < LineCountCheck
16
16
 
17
- DEFAULT_THRESHOLD = 400
17
+ DEFAULT_THRESHOLD = 300
18
18
 
19
19
  def initialize(options = {}) #:nodoc:
20
- threshold = options[:threshold] || DEFAULT_THRESHOLD
21
- super([Parsing::ClassContext], threshold)
20
+ options[:threshold] ||= DEFAULT_THRESHOLD
21
+ super([Parsing::ClassContext], options)
22
22
  end
23
23
 
24
24
  def evaluate(context)
@@ -16,13 +16,13 @@ module Simplabs
16
16
  # * classes
17
17
  class ClassNameCheck < NameCheck
18
18
 
19
- DEFAULT_PATTERN = /^[A-Z]{1}[a-zA-Z0-9]*$/
20
-
19
+ DEFAULT_PATTERN = '^[A-Z]{1}[a-zA-Z0-9]*$'
20
+
21
21
  def initialize(options = {}) #:nodoc:
22
- pattern = options[:pattern] || DEFAULT_PATTERN
23
- super([Parsing::ClassContext], pattern)
22
+ options[:pattern] ||= DEFAULT_PATTERN
23
+ super([Parsing::ClassContext], options)
24
24
  end
25
-
25
+
26
26
  protected
27
27
 
28
28
  def warning_args(context) #:nodoc:
@@ -12,16 +12,16 @@ module Simplabs
12
12
  # ==== Applies to
13
13
  #
14
14
  # * class variables
15
- class SingletonVariableCheck < Base
15
+ class ClassVariableCheck < Base
16
16
 
17
- def initialize #:nodoc:
17
+ def initialize(options = {}) #:nodoc:
18
18
  super
19
19
  @interesting_contexts = [Parsing::CvarContext]
20
20
  @interesting_files = [/\.rb$/, /\.erb$/]
21
21
  end
22
22
 
23
23
  def evaluate(context) #:nodoc:
24
- add_warning(context, 'Singleton variable {{variable}} used.', { :variable => context.full_name })
24
+ add_warning(context, 'Class variable {{variable}} used.', { :variable => context.full_name })
25
25
  end
26
26
 
27
27
  end
@@ -15,7 +15,7 @@ module Simplabs
15
15
  # * methods
16
16
  class ControlCouplingCheck < Base
17
17
 
18
- def initialize #:nodoc:
18
+ def initialize(options = {}) #:nodoc:
19
19
  super
20
20
  @interesting_contexts = [Parsing::IfContext, Parsing::CaseContext]
21
21
  end
@@ -27,12 +27,12 @@ module Simplabs
27
27
  class CyclomaticComplexityBlockCheck < CyclomaticComplexityCheck
28
28
 
29
29
  DEFAULT_THRESHOLD = 4
30
-
30
+
31
31
  def initialize(options = {}) #:nodoc:
32
- threshold = options[:threshold] || DEFAULT_THRESHOLD
33
- super([Parsing::BlockContext], threshold)
32
+ options[:threshold] ||= DEFAULT_THRESHOLD
33
+ super([Parsing::BlockContext], options)
34
34
  end
35
-
35
+
36
36
  def evaluate(context) #:nodoc:
37
37
  unless context.cc_score <= @threshold
38
38
  add_warning(context, '{{block}} has cyclomatic complexity of {{score}}.', { :block => context.full_name, :score => context.cc_score })
@@ -8,10 +8,10 @@ module Simplabs
8
8
 
9
9
  class CyclomaticComplexityCheck < Base #:nodoc:
10
10
 
11
- def initialize(interesting_contexts, threshold)
12
- super()
11
+ def initialize(interesting_contexts, options = {}) #:nodoc:
12
+ super(options)
13
13
  @interesting_contexts = interesting_contexts
14
- @threshold = threshold
14
+ @threshold = options[:threshold].to_i
15
15
  end
16
16
 
17
17
  end