Class: Cane::AbcCheck

Inherits:
Struct
  • Object
show all
Defined in:
lib/cane/abc_check.rb

Overview

Creates violations for methods that are too complicated using a simple algorithm run against the parse tree of a file to count assignments, branches, and conditionals. Borrows heavily from metric_abc.

Defined Under Namespace

Classes: InvalidAst, RubyAst

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



12
13
14
# File 'lib/cane/abc_check.rb', line 12

def opts
  @opts
end

Class Method Details

.keyObject



14
# File 'lib/cane/abc_check.rb', line 14

def self.key; :abc; end

.nameObject



15
# File 'lib/cane/abc_check.rb', line 15

def self.name; "ABC check"; end

.optionsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cane/abc_check.rb', line 16

def self.options
  {
    abc_glob: ['Glob to run ABC metrics over',
                  default: '{app,lib}/**/*.rb',
                  variable: 'GLOB',
                  clobber: :no_abc],
    abc_max:  ['Ignore methods under this complexity',
                  default: 15,
                  cast:    :to_i,
                  clobber: :no_abc],
    abc_exclude: ['Exclude method from analysis (eg. Foo::Bar#method)',
                     variable: 'METHOD',
                     type: Array,
                     default: [],
                     clobber: :no_abc],
    no_abc:   ['Disable ABC checking',
                  cast: ->(x) { !x }]
  }
end

Instance Method Details

#violationsObject



36
37
38
39
40
41
42
# File 'lib/cane/abc_check.rb', line 36

def violations
  return [] if opts[:no_abc]

  order worker.map(file_names) {|file_name|
    find_violations(file_name)
  }.flatten
end