Skip to content

Commit 5d2ee86

Browse files
author
Shane da Silva
committed
Add extra_properties option to PropertySpelling
There are a lot of CSS properties, and the lack of a definitive list (as well as the constant introduction of new experimental properties) makes it impractical to ensure our list is up-to-date at any given time. To address this, add an `extra_properties` config option to the `PropertySpelling` linter so that developers can add additional properties to the whitelist without needing to submit a pull request. Change-Id: I60f250cb704f2245e66885caada8929c37485076 Reviewed-on: https://gerrit.causes.com/32423 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane@causes.com>
1 parent 7bc4cff commit 5d2ee86

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# SCSS-Lint Changelog
22

3+
## master (unreleased)
4+
5+
* Add `extra_properties` option to `PropertySpelling` linter so additional
6+
CSS properties can be added to the whitelist
7+
38
## 0.15.0
49

510
* Fix bug where `SelectorDepth` could incorrectly report a lint for selectors

README.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Any lint can be disabled by using the `--exclude_linter` flag.
156156
generated CSS, whereas `/* ... */` comments do.
157157

158158
Furthermore, comments should be concise, and using `/* ... */`
159-
encourages multi-line comments can tend to not be concise.
159+
encourages multi-line comments which tend to not be concise.
160160

161161
* Write `@extend` statements first in rule sets, followed by property
162162
declarations and then other nested rule sets.
@@ -465,9 +465,36 @@ Any lint can be disabled by using the `--exclude_linter` flag.
465465
### Other Lints
466466

467467
* Reports `@debug` statements (which you probably left behind accidentally)
468+
468469
* Reports when you define the same property twice in a single rule set
470+
469471
* Reports when you have an empty rule set
470472

473+
* Reports when you use an unknown CSS property (ignoring vendor-prefixed
474+
properties)
475+
476+
```scss
477+
diplay: none; // "display" is spelled incorrectly
478+
```
479+
480+
Since the list of available CSS properties is constantly changing, it's
481+
possible that you might get some false positives here, especially if
482+
you're using experimental CSS features. If that's the case, you can
483+
add additional properties to the whitelist by adding the following
484+
to your `.scss-lint.yml` configuration:
485+
486+
```yaml
487+
linters:
488+
PropertySpelling:
489+
extra_properties:
490+
- some-experimental-property
491+
- another-experimental-property
492+
```
493+
494+
If you're sure the property in question is valid,
495+
[submit a request](https://github.com/causes/scss-lint/issues/new)
496+
to add it to the default whitelist.
497+
471498
## Contributing
472499

473500
We love getting feedback with or without pull requests. If you do add a new

config/default.yml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ linters:
4545

4646
PropertySpelling:
4747
enabled: true
48+
extra_properties: []
4849

4950
SelectorDepth:
5051
enabled: true

lib/scss_lint/linter/property_spelling.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ module SCSSLint
33
class Linter::PropertySpelling < Linter
44
include LinterRegistry
55

6+
def visit_root(node)
7+
@extra_properties = config['extra_properties'].to_set
8+
yield # Continue linting children
9+
end
10+
611
def visit_prop(node)
712
# Ignore properties with interpolation
813
return if node.name.count > 1 || !node.name.first.is_a?(String)
@@ -12,7 +17,7 @@ def visit_prop(node)
1217
# Ignore vendor-prefixed properties
1318
return if name.start_with?('-')
1419

15-
unless KNOWN_PROPERTIES.include?(name)
20+
unless KNOWN_PROPERTIES.include?(name) || @extra_properties.include?(name)
1621
add_lint(node, "Unknown property #{name}")
1722
end
1823
end

spec/scss_lint/linter/property_spelling_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,28 @@
3030

3131
it { should report_lint }
3232
end
33+
34+
context 'when extra properties are specified' do
35+
let(:linter_config) { { 'extra_properties' => ['made-up-property'] } }
36+
37+
context 'with a non-existent property' do
38+
let(:css) { <<-CSS }
39+
p {
40+
peanut-butter: jelly-time;
41+
}
42+
CSS
43+
44+
it { should report_lint }
45+
end
46+
47+
context 'with a property listed as an extra property' do
48+
let(:css) { <<-CSS }
49+
p {
50+
made-up-property: value;
51+
}
52+
CSS
53+
54+
it { should_not report_lint }
55+
end
56+
end
3357
end

0 commit comments

Comments
 (0)