Skip to content

Commit

Permalink
Add TransitionAll linter
Browse files Browse the repository at this point in the history
  • Loading branch information
baileyparker authored and sds committed Aug 19, 2015
1 parent 8c4d946 commit 6264103
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ linters:
TrailingZero:
enabled: false

TransitionAll:
enabled: false

UnnecessaryMantissa:
enabled: true

Expand Down
17 changes: 17 additions & 0 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Below is a list of linters supported by `scss-lint`, ordered alphabetically.
* [TrailingSemicolon](#trailingsemicolon)
* [TrailingWhitespace](#trailingwhitespace)
* [TrailingZero](#trailingzero)
* [TransitionAll](#transitionall)
* [UnnecessaryMantissa](#unnecessarymantissa)
* [UnnecessaryParentReference](#unnecessaryparentreference)
* [UrlFormat](#urlformat)
Expand Down Expand Up @@ -1482,6 +1483,22 @@ margin: .5em;
The extra zeros are unnecessary and just add additional bytes to the resulting
generated CSS.

## TransitionAll

**Disabled by default**

Don't use the `all` keyword to specify transition properties.

**Bad: use of transition all**
```scss
transition: all .5s ease-in;
```

**Good: explicitly specify properties to transition**
```scss
transition: color .5s ease-in, margin-bottom .5s ease-in;
```

## UnnecessaryMantissa

Numeric values should not contain unnecessary fractional portions.
Expand Down
30 changes: 30 additions & 0 deletions lib/scss_lint/linter/transition_all.rb
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
81 changes: 81 additions & 0 deletions spec/scss_lint/linter/transition_all_spec.rb
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

0 comments on commit 6264103

Please sign in to comment.