Skip to content

Commit

Permalink
Ignore inherit and transparent in VariableForProperty
Browse files Browse the repository at this point in the history
These values are somewhat special and shouldn't be considered as
breaking the rules of this linter.
  • Loading branch information
sds committed Apr 21, 2015
1 parent 85f6630 commit 5a8cac9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
multi-line comments, such as copyright notices
* Fix bug where control comments could filter out lints from other files
depending on scan order
* Ignore `inherit` and `transparent` values in `VariableForProperty`

## 0.37.0

Expand Down
3 changes: 3 additions & 0 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,9 @@ linters:
- font
```
Note that values like `inherit` and `transparent` will not be reported, as they
are special kinds of values that convey additional meaning.

Configuration Option | Description
---------------------|---------------------------------------------------------
`properties` | Array of property names to check
Expand Down
12 changes: 11 additions & 1 deletion lib/scss_lint/linter/variable_for_property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ module SCSSLint
class Linter::VariableForProperty < Linter
include LinterRegistry

IGNORED_VALUES = %w[inherit transparent]

def visit_root(_node)
@properties = Set.new(config['properties'])
yield if @properties.any?
end

def visit_prop(node)
property_name = node.name.join
return unless @properties.include? property_name
return unless @properties.include?(property_name)
return if ignored_value?(node.value)
return if node.children.first.is_a?(Sass::Script::Tree::Variable)

add_lint(node, "Property #{property_name} should use " \
'a variable rather than a literal value')
end

private

def ignored_value?(value)
value.respond_to?(:value) &&
IGNORED_VALUES.include?(value.value.to_s)
end
end
end
20 changes: 20 additions & 0 deletions spec/scss_lint/linter/variable_for_property_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@

it { should report_lint line: 3 }
end

context 'when property specifies `inherit`' do
let(:scss) { <<-SCSS }
p {
color: inherit;
}
SCSS

it { should_not report_lint }
end

context 'when property specifies `transparent`' do
let(:scss) { <<-SCSS }
p {
color: transparent;
}
SCSS

it { should_not report_lint }
end
end

context 'when properties are not specified' do
Expand Down

0 comments on commit 5a8cac9

Please sign in to comment.