Class: Skeptic::Rules::NoTrailingWhitespace
- Inherits:
-
Object
- Object
- Skeptic::Rules::NoTrailingWhitespace
- Defined in:
- lib/skeptic/rules/no_trailing_whitespace.rb
Constant Summary collapse
- DESCRIPTION =
'Disallows trailing whitespace'
Instance Attribute Summary collapse
-
#lines_with_trailing_whitespace ⇒ Object
readonly
Returns the value of attribute lines_with_trailing_whitespace.
Instance Method Summary collapse
- #apply_to(code, tokens, sexp) ⇒ Object
-
#initialize(enable = false) ⇒ NoTrailingWhitespace
constructor
A new instance of NoTrailingWhitespace.
- #name ⇒ Object
- #violations ⇒ Object
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_whitespace ⇒ Object (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 |
#name ⇒ Object
25 26 27 |
# File 'lib/skeptic/rules/no_trailing_whitespace.rb', line 25 def name "Trailing whitespace" end |
#violations ⇒ Object
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 |