Class: Greener::Checker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/greener/checker/base.rb

Overview

Base checker class

Direct Known Subclasses

Style::FeatureName, Style::IndentationWidth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, path, config) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
# File 'lib/greener/checker/base.rb', line 7

def initialize(ast, path, config)
  @ast = ast
  @path = path
  @config = config

  @violations = []
end

Instance Attribute Details

#violationsObject (readonly)

Returns the value of attribute violations.



5
6
7
# File 'lib/greener/checker/base.rb', line 5

def violations
  @violations
end

Instance Method Details

#featureObject

For readability in checker subclasses



41
42
43
# File 'lib/greener/checker/base.rb', line 41

def feature
  @ast
end

#log_violation(line, col, msg = nil, raw_txt = nil) ⇒ Object

Adds violation data to the @violations array



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/greener/checker/base.rb', line 25

def log_violation(line, col, msg = nil, raw_txt = nil)
  # Set defaults for last 2 params if not overridden
  raw_txt ||= raw_line(line)
  msg ||= message

  violation = {}
  violation[:file] = @path
  violation[:line] = line
  violation[:column] = col
  violation[:text_of_line] = raw_txt
  violation[:message] = msg

  @violations << violation
end

#messageObject

Read the violation message text set in the checker subclass



20
21
22
# File 'lib/greener/checker/base.rb', line 20

def message
  self.class::MSG
end

#raw_line(num) ⇒ Object

Given a num, returns the full text corresponding to that line number in the file



46
47
48
# File 'lib/greener/checker/base.rb', line 46

def raw_line(num)
  open(@path).each_line.take(num).last
end

#runObject

Method invoked when a checker is applied to a file



16
17
# File 'lib/greener/checker/base.rb', line 16

def run
end