diff --git a/index.js b/index.js index 066285a..fcfccb8 100644 --- a/index.js +++ b/index.js @@ -67,15 +67,17 @@ function ruleFunc(method, opts, context) { } } - firstInlineDecl.cloneBefore({ - prop, - value: values.length <= 2 ? values.join(' ') : `logical ${values.join(' ')}` - }); - - blockStartDecl.remove(); - inlineStartDecl.remove(); - blockEndDecl.remove(); - inlineEndDecl.remove(); + if (values.length === 1 || hasNoGlobalValue(values)) { + firstInlineDecl.cloneBefore({ + prop, + value: values.length <= 2 ? values.join(' ') : `logical ${values.join(' ')}` + }); + + blockStartDecl.remove(); + inlineStartDecl.remove(); + blockEndDecl.remove(); + inlineEndDecl.remove(); + } } else if (!isDeclReported(blockStartDecl) && !isDeclReported(inlineStartDecl) && !isDeclReported(blockEndDecl) && !isDeclReported(inlineEndDecl)) { reportUnexpectedProperty(firstInlineDecl, prop); @@ -102,15 +104,19 @@ function ruleFunc(method, opts, context) { : inlineStartDecl; if (isAutofix) { - firstInlineDecl.cloneBefore({ - prop, - value: blockStartDecl.value === inlineStartDecl.value - ? blockStartDecl.value - : [ blockStartDecl.value, inlineStartDecl.value ].join(' ') - }); - - blockStartDecl.remove(); - inlineStartDecl.remove(); + const values = blockStartDecl.value === inlineStartDecl.value + ? [blockStartDecl.value] + : [blockStartDecl.value, inlineStartDecl.value] + + if (values.length === 1 || hasNoGlobalValue(values)) { + firstInlineDecl.cloneBefore({ + prop, + value: values.join(' ') + }); + + blockStartDecl.remove(); + inlineStartDecl.remove(); + } } else if (!isDeclReported(blockStartDecl) && !isDeclReported(inlineStartDecl)) { reportUnexpectedProperty(firstInlineDecl, prop); @@ -167,6 +173,11 @@ function ruleFunc(method, opts, context) { }; ruleFunc.ruleName = ruleName; +function hasNoGlobalValue(values) { + const globalValues = ['inherit', 'initial', 'revert', 'revert-layer', 'unset'] + return globalValues.every(globalValue => !values.includes(globalValue)) +} + export default stylelint.createPlugin(ruleName, ruleFunc); const isMethodIndifferent = method => method === 'ignore' || method === false || method === null;