Class: HamlLint::Linter::TrailingEmptyLines

Inherits:
Linter
  • Object
show all
Includes:
HamlLint::LinterRegistry
Defined in:
lib/haml_lint/linter/trailing_empty_lines.rb

Overview

Checks for trailing empty lines.

Defined Under Namespace

Classes: DummyNode

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Instance Method Details

#visit_root(root) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/haml_lint/linter/trailing_empty_lines.rb', line 12

def visit_root(root)
  return if document.source.empty?
  line_number = document.last_non_empty_line

  node = root.node_for_line(line_number)
  return if node.disabled?(self)

  return unless document.source.end_with?("\n\n")

  record_lint(line_number, 'Files should not end with trailing empty lines',
              corrected: autocorrect?)

  apply_autocorrect(corrected_source)
end