Class: HamlLint::Linter::FinalNewline

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

Overview

Checks for final newlines at the end of a file.

Instance Attribute Summary

Attributes inherited from HamlLint::Linter

#lints

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Methods inherited from HamlLint::Linter

#initialize, #name, #run

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

This class inherits a constructor from HamlLint::Linter

Instance Method Details

#visit_root(root) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/haml_lint/linter/final_newline.rb', line 8

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

  node = root.node_for_line(document.source_lines.count)
  return if node.disabled?(self)

  ends_with_newline = document.source.end_with?("\n")

  if config['present']
    unless ends_with_newline
      record_lint(node, 'Files should end with a trailing newline')
    end
  elsif ends_with_newline
    record_lint(node, 'Files should not end with a trailing newline')
  end
end