Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map-keys-quotes: ignore math operators inside map values #392

Merged
merged 1 commit into from Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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