Class: RemLint::Rules::TrailingWhitespace

Inherits:
RemLint::Rule show all
Defined in:
lib/remlint/rules/trailing_whitespace.rb

Overview

Whitespace at the end of a line.

Not bikeshedding in Remind. The shipped examples/remind.vim highlights it as an error, with the note "This will match trailing whitespaces that seem to break rem2ps". A linter that stayed quiet about it would disagree with the editor Remind ships.

The pattern is vim's -- \S\s\+$, a non-space then whitespace -- so a line of nothing but spaces is left alone. Emptying such a line is a cosmetic change and flagging every one of them in a file that has a few is how a linter teaches people to ignore it.

A trailing run that follows a backslash belongs to DanglingContinuation, which has something more useful to say about it, so it is skipped here rather than reported twice.

Constant Summary collapse

OFFENDING =
/\S[ \t]+\z/
AFTER_CONTINUATION =
/\\[ \t]+\z/
MESSAGE =
"Trailing whitespace (breaks rem2ps output)"

Constants inherited from RemLint::Rule

RemLint::Rule::REGISTRY

Instance Attribute Summary

Attributes inherited from RemLint::Rule

#config, #document, #offenses

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemLint::Rule

all, enabled_by_default?, find, inherited, #initialize, rule_name, #rule_name, #run

Constructor Details

This class inherits a constructor from RemLint::Rule

Class Method Details

.default_severityObject



28
29
30
# File 'lib/remlint/rules/trailing_whitespace.rb', line 28

def self.default_severity
  "error"
end

.descriptionObject



32
33
34
# File 'lib/remlint/rules/trailing_whitespace.rb', line 32

def self.description
  "Whitespace at the end of a line, which breaks rem2ps output."
end

Instance Method Details

#checkObject



36
37
38
39
40
41
42
43
44
# File 'lib/remlint/rules/trailing_whitespace.rb', line 36

def check
  document.each_raw_line do |raw, line|
    body = raw.chomp

    if offending?(body)
      offend(line, MESSAGE, column: body.rstrip.length + 1)
    end
  end
end