Class: Skeptic::Rules::NoTrailingWhitespace

Inherits:
Object
  • Object
show all
Defined in:
lib/skeptic/rules/no_trailing_whitespace.rb

Constant Summary collapse

DESCRIPTION =
'Disallows trailing whitespace'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enable = false) ⇒ NoTrailingWhitespace

Returns a new instance of NoTrailingWhitespace.



8
9
10
# File 'lib/skeptic/rules/no_trailing_whitespace.rb', line 8

def initialize(enable = false)
  @lines_with_trailing_whitespace = []
end

Instance Attribute Details

#lines_with_trailing_whitespaceObject (readonly)

Returns the value of attribute lines_with_trailing_whitespace.



6
7
8
# File 'lib/skeptic/rules/no_trailing_whitespace.rb', line 6

def lines_with_trailing_whitespace
  @lines_with_trailing_whitespace
end

Instance Method Details

#apply_to(code, tokens, sexp) ⇒ Object



12
13
14
15
16
17
# File 'lib/skeptic/rules/no_trailing_whitespace.rb', line 12

def apply_to(code, tokens, sexp)
  code.lines.each_with_index do |line, index|
    @lines_with_trailing_whitespace << index + 1 if line.chomp =~ /\s+$/
  end
  self
end

#nameObject



25
26
27
# File 'lib/skeptic/rules/no_trailing_whitespace.rb', line 25

def name
  "Trailing whitespace"
end

#violationsObject



19
20
21
22
23
# File 'lib/skeptic/rules/no_trailing_whitespace.rb', line 19

def violations
  @lines_with_trailing_whitespace.map do |line|
    "Line #{line} has trailing whitespace"
  end
end