forked from sds/haml-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HAML documents should not contain empty lines at the end of the file. Inspired by Slim lint's `TrailingBlankLines` Close sds#422
- Loading branch information
Showing
6 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module HamlLint | ||
# Checks for trailing empty lines. | ||
class Linter::TrailingEmptyLines < Linter | ||
include LinterRegistry | ||
|
||
DummyNode = Struct.new(:line) | ||
|
||
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') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
describe HamlLint::Linter::TrailingEmptyLines do | ||
include_context 'linter' | ||
|
||
context 'when the file is empty' do | ||
let(:haml) { '' } | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when file ends with a single newline' do | ||
let(:haml) { "%h1 Hello\n" } | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when file contains multiple newlines' do | ||
let(:haml) { "%h1 Hello\n\n" } | ||
|
||
it { should report_lint line: 1 } | ||
|
||
context 'but the linter is disabled in the file' do | ||
let(:haml) { "-# haml-lint:disable TrailingEmptyLines\n" + super() } | ||
|
||
it { should_not report_lint } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%h1 Hello |