class ERBLint::Linters::TrailingWhitespace

Detects trailing whitespace at the end of a line

Constants

TRAILING_WHITESPACE

Public Instance Methods

autocorrect(_processed_source, offense) click to toggle source
# File lib/erb_lint/linters/trailing_whitespace.rb, line 26
def autocorrect(_processed_source, offense)
  lambda do |corrector|
    corrector.replace(offense.source_range, "")
  end
end
run(processed_source) click to toggle source
# File lib/erb_lint/linters/trailing_whitespace.rb, line 11
def run(processed_source)
  lines = processed_source.file_content.split("\n", -1)
  document_pos = 0
  lines.each do |line|
    document_pos += line.length + 1
    whitespace = line.match(TRAILING_WHITESPACE)&.captures&.first
    next unless whitespace && !whitespace.empty?

    add_offense(
      processed_source.to_source_range((document_pos - whitespace.length - 1)...(document_pos - 1)),
      "Extra whitespace detected at end of line."
    )
  end
end