diff --git a/CHANGELOG.md b/CHANGELOG.md index a479ba52..7e4de14e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # HEAD +- Fixed: `map-keys-quotes` ignore math operators inside map values. - Fixed: `operator-no-unspaced` was looking for operators inside `@forward` and `@use`. # 3.12.0 diff --git a/src/rules/map-keys-quotes/__tests__/index.js b/src/rules/map-keys-quotes/__tests__/index.js index a0fb993b..56611265 100644 --- a/src/rules/map-keys-quotes/__tests__/index.js +++ b/src/rules/map-keys-quotes/__tests__/index.js @@ -45,6 +45,69 @@ testRule(rule, { ); `, description: "accepts numbers (nested)" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": $variable * 2, + ); + `, + description: "accepts * operator inside a value" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": $variable*2, + ); + `, + description: "accepts * operator without spaces inside a value" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": $variable - 2, + ); + `, + description: "accepts - operator inside a value" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": $variable + 2, + ); + `, + description: "accepts + operator inside a value" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": $variable / 2, + ); + `, + description: "accepts / operator inside a value" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": $variable % 2, + ); + `, + description: "accepts % operator inside a value" + }, + { + code: ` + $map: ( + "key-one": 0, + "key-two": (1+2), + ); + `, + description: "accepts parens inside a value" } ], diff --git a/src/rules/map-keys-quotes/index.js b/src/rules/map-keys-quotes/index.js index 64a3fe47..93b74346 100644 --- a/src/rules/map-keys-quotes/index.js +++ b/src/rules/map-keys-quotes/index.js @@ -8,6 +8,8 @@ export const messages = utils.ruleMessages(ruleName, { expected: "Expected keys in map to be quoted." }); +const mathOperators = ["+", "/", "-", "*", "%"]; + function rule(primary) { return (root, result) => { const validOptions = utils.validateOptions(result, ruleName, { @@ -34,6 +36,10 @@ function rule(primary) { const mapKeys = returnMapKeys(node.nodes); mapKeys.forEach(map_key => { + if (mathOperators.indexOf(map_key.value) > -1) { + return; + } + if (map_key.type === "word" && isNaN(map_key.value)) { utils.report({ message: messages.expected,