Skip to content

Commit

Permalink
fix: skip expanded shorthan if invalid and not variable or function
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed Oct 29, 2020
1 parent 5a47606 commit 0d69d33
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import stylelint from 'stylelint'
import shortCSS from 'shortcss'
import cssValues from 'css-values'

import {
validProperties, validOptions, expected, getTypes, getIgnoredVariablesOrFunctions, getIgnoredKeywords, getIgnoredValues, getAutoFixFunc,
Expand Down Expand Up @@ -161,7 +162,7 @@ const ruleFunction = (properties, options, context = {}) => (root, result) => {
const longhandValue = expandedProps[longhandProp]

if (!failedFlag && (longhandProp === propFilter || (propFilter instanceof RegExp && propFilter.test(longhandProp)))) {
failedFlag = lintDeclStrictValue(node, longhandProp, longhandValue)
failedFlag = lintDeclStrictValue(node, longhandProp, longhandValue, true)
}
})
}
Expand All @@ -174,11 +175,11 @@ const ruleFunction = (properties, options, context = {}) => (root, result) => {
* @callback
* @param {object} node - A Declaration-Node from PostCSS AST-Parser.
* @param {string} [longhandProp] - A Declaration-Node from PostCSS AST-Parser.
* @param isExpanded
* @param {string} [longhandValue] - A Declaration-Node from PostCSS AST-Parser.
*
* @returns {boolean} Returns `true` if invalid declaration found, else `false`.
*/
function lintDeclStrictValue(node, longhandProp, longhandValue) {
function lintDeclStrictValue(node, longhandProp, longhandValue, isExpanded = false) {
const { value: nodeValue, prop: nodeProp } = node
const value = longhandValue || nodeValue

Expand Down Expand Up @@ -208,6 +209,11 @@ const ruleFunction = (properties, options, context = {}) => (root, result) => {
}
}

// test expanded shorthands are valid
if (isExpanded && ignoreVariables && !validVar && ignoreFunctions && !validFunc && cssValues(longhandProp, longhandValue) !== true) {
return false
}

// test keywords
if (ignoreKeywords && (!validVar || !validFunc)) {
let reKeyword = reKeywords[property]
Expand Down

0 comments on commit 0d69d33

Please sign in to comment.