Skip to content

Commit f142793

Browse files
committed
🐛 Allow custom properties as variables
1 parent 31d8343 commit f142793

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/rules/variable-for-property.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ var whitelistedValues = ['inherit', 'initial', 'transparent', 'none', 'currentCo
1414
*/
1515
var isValidProperty = function (propertyElem) {
1616
if (propertyElem) {
17-
if (propertyElem.type === 'variable') {
17+
if (propertyElem.is('variable')) {
1818
return true;
1919
}
20-
else if (propertyElem.type === 'ident' && whitelistedValues.indexOf(propertyElem.content) !== -1) {
20+
else if (propertyElem.is('ident') && whitelistedValues.indexOf(propertyElem.content) !== -1) {
2121
return true;
2222
}
2323
}
@@ -46,9 +46,14 @@ var isIgnoredType = function (propertyElem) {
4646
* @returns {boolean} Whether the property is an ignored type or not
4747
*/
4848
var isIgnoredFunction = function (propertyElem, allowMap, functionWhitelist) {
49-
if (propertyElem && propertyElem.type === 'function') {
49+
if (propertyElem && propertyElem.is('function')) {
5050
var funcIdent = propertyElem.first('ident');
5151

52+
// allow custom properties as values
53+
if (funcIdent.content === 'var') {
54+
return true;
55+
}
56+
5257
if (allowMap && funcIdent.content === 'map-get') {
5358
return true;
5459
}

tests/sass/variable-for-property.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@
4646
4747
.func-name-test
4848
color: my-map-func(blue, light)
49+
50+
.custom-prop
51+
// ensure custom properties are valid
52+
color: var(--my-prop)

tests/sass/variable-for-property.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@
5151
.func-name-test {
5252
color: my-map-func(blue, light);
5353
}
54+
55+
.custom-prop {
56+
color: var(--my-prop); // ensure custom properties are valid
57+
}

0 commit comments

Comments
 (0)