Skip to content

Commit

Permalink
Add TrailingWhitespace linter
Browse files Browse the repository at this point in the history
Closes sds#468
  • Loading branch information
sds committed Jun 8, 2015
1 parent 3494089 commit 73a5158
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
properties
* Change `NameFormat` to no longer check placeholder names, as this is handled
by the `SelectorFormat` linter
* Add `TrailingWhitespace` linter which reports whitespace characters at the
end of a line

## 0.39.0

Expand Down
3 changes: 3 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ linters:
TrailingSemicolon:
enabled: true

TrailingWhitespace:
enabled: true

TrailingZero:
enabled: false

Expand Down
5 changes: 5 additions & 0 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Below is a list of linters supported by `scss-lint`, ordered alphabetically.
* [SpaceBetweenParens](#spacebetweenparens)
* [StringQuotes](#stringquotes)
* [TrailingSemicolon](#trailingsemicolon)
* [TrailingWhitespace](#trailingwhitespace)
* [TrailingZero](#trailingzero)
* [UnnecessaryMantissa](#unnecessarymantissa)
* [UnnecessaryParentReference](#unnecessaryparentreference)
Expand Down Expand Up @@ -1369,6 +1370,10 @@ CSS allows you to omit the semicolon if the statement is the last statement in
the rule set. However, this introduces inconsistency and requires anyone adding
a property after that property to remember to append a semicolon.

## TrailingWhitespace

Reports lines containing trailing whitespace.

## TrailingZero

Don't write trailing zeros for numeric values with a decimal point.
Expand Down
14 changes: 14 additions & 0 deletions lib/scss_lint/linter/trailing_whitespace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module SCSSLint
# Checks for trailing whitespace on a line.
class Linter::TrailingWhitespace < Linter
include LinterRegistry

def visit_root(_node)
engine.lines.each_with_index do |line, index|
next unless line =~ /[ \t]+$/

add_lint(index + 1, 'Line contains trailing whitespace')
end
end
end
end
33 changes: 33 additions & 0 deletions spec/scss_lint/linter/trailing_whitespace_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

describe SCSSLint::Linter::TrailingWhitespace do
context 'when lines contain trailing spaces' do
let(:scss) { <<-SCSS }
p {
margin: 0;\s\s
}
SCSS

it { should report_lint line: 2 }
end

context 'when lines contain trailing tabs' do
let(:scss) { <<-SCSS }
p {
margin: 0;\t\t
}
SCSS

it { should report_lint line: 2 }
end

context 'when lines does not contain trailing whitespace' do
let(:scss) { <<-SCSS }
p {
margin: 0;
}
SCSS

it { should_not report_lint }
end
end

0 comments on commit 73a5158

Please sign in to comment.