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.
- Loading branch information
1 parent
8c4d946
commit 6264103
Showing
4 changed files
with
131 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,30 @@ | ||
module SCSSLint | ||
# Checks for explicitly transitioned properties instead of transition all. | ||
class Linter::TransitionAll < Linter | ||
include LinterRegistry | ||
|
||
TRANSITION_PROPERTIES = %w[ | ||
transition | ||
transition-property | ||
] | ||
|
||
def visit_prop(node) | ||
property = node.name.first.to_s | ||
return unless TRANSITION_PROPERTIES.include?(property) | ||
|
||
check_transition(node, property, node.value.to_sass) | ||
end | ||
|
||
private | ||
|
||
def check_transition(node, property, value) | ||
return unless offset = value =~ /\ball\b/ | ||
|
||
pos = node.value_source_range.start_pos.after(value[0, offset]) | ||
|
||
add_lint(Location.new(pos.line, pos.offset, 3), | ||
"#{property} should contain explicit properties " \ | ||
'instead of using the keyword all') | ||
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,81 @@ | ||
require 'spec_helper' | ||
|
||
describe SCSSLint::Linter::TransitionAll do | ||
context 'when transition-property is not set' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
} | ||
SCSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when transition-property is set to none' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
transition-property: none; | ||
} | ||
SCSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when transition-property is not set to all' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
transition-property: color; | ||
} | ||
SCSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when transition-property is set to all' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
transition-property: all; | ||
} | ||
SCSS | ||
|
||
it { should report_lint line: 2 } | ||
end | ||
|
||
context 'when transition shorthand for transition-property is not set' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
} | ||
SCSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when transition shorthand for transition-property is set to none' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
transition: none; | ||
} | ||
SCSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when transition shorthand for transition-property is not set to all' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
transition: color 1s linear; | ||
} | ||
SCSS | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when transition shorthand for transition-property is set to all' do | ||
let(:scss) { <<-SCSS } | ||
p { | ||
transition: all 1s linear; | ||
} | ||
SCSS | ||
|
||
it { should report_lint line: 2 } | ||
end | ||
end |