Class: Cane::StyleCheck

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

Overview

Creates violations for files that do not meet style conventions. Only highly obvious, probable, and non-controversial checks are performed here. It is not the goal of the tool to provide an extensive style report, but only to prevent stupid mistakes.

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/style_check.rb', line 12

def opts
  @opts
end

Class Method Details

.keyObject



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

def self.key; :style; end

.nameObject



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

def self.name; "style checking"; end

.optionsObject



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

def self.options
  {
    style_glob:    ['Glob to run style checks over',
                       default:  '{app,lib,spec}/**/*.rb',
                       variable: 'GLOB',
                       clobber:  :no_style],
    style_measure: ['Max line length',
                       default: 80,
                       cast:    :to_i,
                       clobber: :no_style],
    style_exclude: ['Exclude file or glob from style checking',
                     variable: 'GLOB',
                     type: Array,
                     default: [],
                     clobber: :no_style],
    no_style:      ['Disable style checking', cast: ->(x) { !x }]
  }
end

Instance Method Details

#violationsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cane/style_check.rb', line 35

def violations
  return [] if opts[:no_style]

  worker.map(file_list) do |file_path|
    map_lines(file_path) do |line, line_number|
      violations_for_line(line.chomp).map {|message| {
        file:        file_path,
        line:        line_number + 1,
        label:       message,
        description: "Lines violated style requirements"
      }}
    end
  end.flatten
end