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.
Closes sds#109 Change-Id: I8f7a16aadfff132385cd18fcbe03050f0f97d63f Reviewed-on: http://gerrit.causes.com/37417 Tested-by: jenkins <[email protected]> Reviewed-by: Shane da Silva <[email protected]>
- Loading branch information
Showing
5 changed files
with
209 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,23 @@ | ||
module SCSSLint | ||
# Checks identical root selectors. | ||
class Linter::DuplicateRoot < Linter | ||
include LinterRegistry | ||
|
||
def visit_root(node) | ||
# Root rules are evaluated per document, so use new hashes for eash file | ||
@roots = Hash.new | ||
yield # Continue linting children | ||
end | ||
|
||
def visit_rule(node) | ||
# Check to see if we've seen this rule before | ||
if @roots.has_key?(node.rule) | ||
add_lint(node.line, | ||
"Root #{node.rule} already seen at #{@roots[node.rule]}") | ||
else | ||
@roots[node.rule] = node.line | ||
end | ||
return # Only check one level deep | ||
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,146 @@ | ||
require 'spec_helper' | ||
|
||
describe SCSSLint::Linter::DuplicateRoot do | ||
context 'when single root' do | ||
let(:css) { <<-CSS } | ||
p { | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when different roots' do | ||
let(:css) { <<-CSS } | ||
p { | ||
background: #000; | ||
margin: 5px; | ||
} | ||
a { | ||
background: #000; | ||
margin: 5px; | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when different roots with matching inner rules' do | ||
let(:css) { <<-CSS } | ||
p { | ||
background: #000; | ||
margin: 5px; | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
a { | ||
background: #000; | ||
margin: 5px; | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when multi-selector roots and parital rule match' do | ||
let(:css) { <<-CSS } | ||
p, a { | ||
background: #000; | ||
margin: 5px; | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
a { | ||
background: #000; | ||
margin: 5px; | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when nested and unnested selectors match' do | ||
let(:css) { <<-CSS } | ||
a.current { | ||
background: #000; | ||
margin: 5px; | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
a { | ||
&.current { | ||
background: #000; | ||
margin: 5px; | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
} | ||
CSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when same class roots' do | ||
let(:css) { <<-CSS } | ||
.warn { | ||
font-weight: bold; | ||
} | ||
.warn { | ||
color: #f00; | ||
@extend .warn; | ||
a { | ||
color: #ccc; | ||
} | ||
} | ||
CSS | ||
|
||
it { should report_lint } | ||
end | ||
|
||
context 'when same compond selector roots' do | ||
let(:css) { <<-CSS } | ||
.warn .alert { | ||
font-weight: bold; | ||
} | ||
.warn .alert { | ||
color: #f00; | ||
@extend .warn; | ||
a { | ||
color: #ccc; | ||
} | ||
} | ||
CSS | ||
|
||
it { should report_lint } | ||
end | ||
|
||
context 'when same class roots separated by another class' do | ||
let(:css) { <<-CSS } | ||
.warn { | ||
font-weight: bold; | ||
} | ||
.foo { | ||
color: red; | ||
} | ||
.warn { | ||
color: #f00; | ||
@extend .warn; | ||
a { | ||
color: #ccc; | ||
} | ||
} | ||
CSS | ||
|
||
it { should report_lint } | ||
end | ||
end |