forked from sds/scss-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.
Change-Id: I9ad5e2fa2224044a499d60ddbc2b24406b7f2ac7 Reviewed-on: https://gerrit.causes.com/32214 Tested-by: jenkins <[email protected]> Reviewed-by: Henric Trotzig <[email protected]>
- Loading branch information
1 parent
c2d6b75
commit e716c7c
Showing
4 changed files
with
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module SCSSLint | ||
# Checks for the presence of spaces between parentheses. | ||
class Linter::SpaceBetweenParens < Linter | ||
include LinterRegistry | ||
|
||
def visit_root(node) | ||
@spaces = config['spaces'] | ||
engine.lines.each_with_index do |line, index| | ||
line.scan /(\( *[^ ]|[^\s] *\))/ do |match| | ||
match.each { |str| check(str, index, engine) } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def check(str, index, engine) | ||
spaces = str.count ' ' | ||
|
||
if spaces != @spaces | ||
@lints << Lint.new(engine.filename, index + 1, "Expected #{pluralize(@spaces, 'space')}" << | ||
" between parentheses instead of #{spaces}") | ||
end | ||
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,135 @@ | ||
require 'spec_helper' | ||
|
||
describe SCSSLint::Linter::SpaceBetweenParens do | ||
context 'when the opening parens is followed by a space' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( value); | ||
} | ||
CSS | ||
|
||
it { should report_lint line: 2 } | ||
end | ||
|
||
context 'when the closing parens is preceded by a space' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: (value ); | ||
} | ||
CSS | ||
|
||
it { should report_lint line: 2 } | ||
end | ||
|
||
context 'when both parens are space padded' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( value ); | ||
} | ||
CSS | ||
|
||
it { should report_lint line: 2, count: 2 } | ||
end | ||
|
||
context 'when neither parens are space padded' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: (value); | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when parens are multi-line' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( | ||
value | ||
); | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when parens are multi-line with tabs' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( | ||
value | ||
); | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when the number of spaces has been explicitly set' do | ||
let(:linter_config) { { 'spaces' => 1 } } | ||
|
||
context 'when the opening parens is followed by a space' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( value); | ||
} | ||
CSS | ||
|
||
it { should report_lint line: 2 } | ||
end | ||
|
||
context 'when the closing parens is preceded by a space' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: (value ); | ||
} | ||
CSS | ||
|
||
it { should report_lint line: 2 } | ||
end | ||
|
||
context 'when neither parens are space padded' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: (value); | ||
} | ||
CSS | ||
|
||
it { should report_lint line: 2, count: 2 } | ||
end | ||
|
||
context 'when both parens are space padded' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( value ); | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when parens are multi-line' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( | ||
value | ||
); | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when parens are multi-line with tabs' do | ||
let(:css) { <<-CSS } | ||
p { | ||
property: ( | ||
value | ||
); | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
end | ||
end |