Skip to content

Commit

Permalink
Merge pull request #392 from kristerkari/bugfix/map-keys-quotes-ignor…
Browse files Browse the repository at this point in the history
…e-math-operators

map-keys-quotes: ignore math operators inside map values
  • Loading branch information
kristerkari committed Nov 3, 2019
2 parents 23058c9 + 68c3fa1 commit 91993a1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
63 changes: 63 additions & 0 deletions src/rules/map-keys-quotes/__tests__/index.js
Expand Up @@ -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"
}
],

Expand Down
6 changes: 6 additions & 0 deletions src/rules/map-keys-quotes/index.js
Expand Up @@ -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, {
Expand All @@ -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,
Expand Down

0 comments on commit 91993a1

Please sign in to comment.