From c616a2c6767157bbcfdb6c5419d0c5621396445a Mon Sep 17 00:00:00 2001 From: krister Date: Thu, 1 Aug 2019 00:26:12 +0300 Subject: [PATCH 1/2] map-keys-quotes: don't require numbers to be quoted --- CHANGELOG.md | 4 +++ src/rules/map-keys-quotes/__tests__/index.js | 36 +++++++++++++++++++- src/rules/map-keys-quotes/index.js | 4 +-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39f799b4..c6ece128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# HEAD + +- Fixed: `map-keys-quotes` warning for unquoted numeric keys. + # 3.9.2 - Fixed: `selector-no-union-class-name` throwing an error when using nested `@`-rules. diff --git a/src/rules/map-keys-quotes/__tests__/index.js b/src/rules/map-keys-quotes/__tests__/index.js index 3c5ec988..e5cb8a93 100644 --- a/src/rules/map-keys-quotes/__tests__/index.js +++ b/src/rules/map-keys-quotes/__tests__/index.js @@ -1,4 +1,4 @@ -import rule, { ruleName, messages } from ".."; +import rule, { messages, ruleName } from ".."; testRule(rule, { ruleName, @@ -11,6 +11,40 @@ testRule(rule, { $test: ("foo": 14px, "bar": 25px); `, description: "accepts strings without quotes" + }, + { + code: ` + $test: ('foo': 14px, 'bar': 25px); + `, + description: "accepts strings without quotes" + }, + { + code: ` + $colors: ( + 250: #eef9ff, + 300: #bbe7ff, + 350: #b7d3e6, + 500: #1388db, + 750: #0f6bac, + 900: #2e4662 + ); + `, + description: "accepts numbers" + }, + { + code: ` + $colors: ( + 'primary': ( + 250: #eef9ff, + 300: #bbe7ff, + 350: #b7d3e6, + 500: #1388db, + 750: #0f6bac, + 900: #2e4662, + ) + ); + `, + description: "accepts numbers (nested)" } ], diff --git a/src/rules/map-keys-quotes/index.js b/src/rules/map-keys-quotes/index.js index cd08ff61..64a3fe47 100644 --- a/src/rules/map-keys-quotes/index.js +++ b/src/rules/map-keys-quotes/index.js @@ -1,6 +1,6 @@ +import valueParser from "postcss-value-parser"; import { utils } from "stylelint"; import { namespace } from "../../utils"; -import valueParser from "postcss-value-parser"; export const ruleName = namespace("map-keys-quotes"); @@ -34,7 +34,7 @@ function rule(primary) { const mapKeys = returnMapKeys(node.nodes); mapKeys.forEach(map_key => { - if (map_key.type === "word") { + if (map_key.type === "word" && isNaN(map_key.value)) { utils.report({ message: messages.expected, node: decl, From 4ba37df9c4f35726d3f1f2751eb07569be21ec6a Mon Sep 17 00:00:00 2001 From: Krister Kari Date: Fri, 2 Aug 2019 10:22:44 +0300 Subject: [PATCH 2/2] Update src/rules/map-keys-quotes/__tests__/index.js Co-Authored-By: Natalie Weizenbaum --- src/rules/map-keys-quotes/__tests__/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/map-keys-quotes/__tests__/index.js b/src/rules/map-keys-quotes/__tests__/index.js index e5cb8a93..a0fb993b 100644 --- a/src/rules/map-keys-quotes/__tests__/index.js +++ b/src/rules/map-keys-quotes/__tests__/index.js @@ -16,7 +16,7 @@ testRule(rule, { code: ` $test: ('foo': 14px, 'bar': 25px); `, - description: "accepts strings without quotes" + description: "accepts strings with quotes" }, { code: `