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



11
12
13
# File 'lib/cane/style_check.rb', line 11

def opts
  @opts
end

Class Method Details

.keyObject



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

def self.key; :style; end

.nameObject



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

def self.name; "style checking"; end

.optionsObject



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

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 from style checking',
                     variable: 'FILE',
                     type: Array,
                     default: [],
                     clobber: :no_style],
    no_style:      ['Disable style checking']
  }
end

Instance Method Details

#violationsObject



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

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