From 153335747ab6fcfa0b4c9c84604a0db0ad585007 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 12:38:24 -0700 Subject: [PATCH 01/11] boilerplate --- src/rules/index.js | 2 ++ src/rules/no-non-numeric-dimensions/README.md | 1 + .../__tests__/index.js | 8 +++++++ src/rules/no-non-numeric-dimensions/index.js | 23 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 src/rules/no-non-numeric-dimensions/README.md create mode 100644 src/rules/no-non-numeric-dimensions/__tests__/index.js create mode 100644 src/rules/no-non-numeric-dimensions/index.js diff --git a/src/rules/index.js b/src/rules/index.js index f316b694..c6f4f809 100644 --- a/src/rules/index.js +++ b/src/rules/index.js @@ -33,6 +33,7 @@ import functionNoQuotedStrings from "./function-quote-no-quoted-strings-inside"; import mediaFeatureValueDollarVariable from "./media-feature-value-dollar-variable"; import noDollarVariables from "./no-dollar-variables"; import noDuplicateDollarVariables from "./no-duplicate-dollar-variables"; +import noNonNumericDimensions from "./no-non-numeric-dimensions"; import operatorNoNewlineAfter from "./operator-no-newline-after"; import operatorNoNewlineBefore from "./operator-no-newline-before"; import operatorNoUnspaced from "./operator-no-unspaced"; @@ -77,6 +78,7 @@ export default { "media-feature-value-dollar-variable": mediaFeatureValueDollarVariable, "no-dollar-variables": noDollarVariables, "no-duplicate-dollar-variables": noDuplicateDollarVariables, + "no-non-numeric-dimensions": noNonNumericDimensions, "operator-no-newline-after": operatorNoNewlineAfter, "operator-no-newline-before": operatorNoNewlineBefore, "operator-no-unspaced": operatorNoUnspaced, diff --git a/src/rules/no-non-numeric-dimensions/README.md b/src/rules/no-non-numeric-dimensions/README.md new file mode 100644 index 00000000..245fd6a7 --- /dev/null +++ b/src/rules/no-non-numeric-dimensions/README.md @@ -0,0 +1 @@ +# at-non-numeric-dimensinos \ No newline at end of file diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js new file mode 100644 index 00000000..4f7b09d9 --- /dev/null +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -0,0 +1,8 @@ +import rule, { ruleName, messages } from ".."; + +testRule(rule, { + ruleName, + config: [true], + syntax: "scss", + accept: [] +}); diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js new file mode 100644 index 00000000..5a9e7cff --- /dev/null +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -0,0 +1,23 @@ +import { utils } from "stylelint"; +import { namespace, isNativeCssFunction } from "../../utils"; +import valueParser from "postcss-value-parser"; + +export const ruleName = namespace("function-quote-no-quoted-strings-inside"); + +export const messages = utils.ruleMessages(ruleName, { + rejected: "Expected `$value * 1px` instead of `#{value}px" +}); + +function rule(primary, _, context) { + return (root, result) => { + const validOptions = utils.validateOptions(result, ruleName, { + actual: primary + }); + + if (!validOptions) { + return; + } + }; +} + +export default rule; From aea2b6aaf77b941e614a16501b42688bcb455b00 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 12:43:17 -0700 Subject: [PATCH 02/11] basic tests (for now) --- .../__tests__/index.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index 4f7b09d9..161b43e8 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -4,5 +4,25 @@ testRule(rule, { ruleName, config: [true], syntax: "scss", - accept: [] + accept: [ + { + code: ` + p { + padding: "1" * 1px; + } + `, + description: "Accepts proper value interpolation" + } + ], + reject: [ + { + code: ` + p { + padding: #{value}px; + } + `, + messages: messages.rejected, + description: "Rejects interpolation with a unit" + } + ] }); From 27771dab941ea952d3beef1320ff2f1a69e7d380 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 14:28:29 -0700 Subject: [PATCH 03/11] tests pass --- .../__tests__/index.js | 45 ++++++-- src/rules/no-non-numeric-dimensions/index.js | 105 +++++++++++++++++- 2 files changed, 137 insertions(+), 13 deletions(-) diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index 161b43e8..54a3faea 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -1,4 +1,4 @@ -import rule, { ruleName, messages } from ".."; +import rule, { ruleName, messages, units } from ".."; testRule(rule, { ruleName, @@ -7,22 +7,49 @@ testRule(rule, { accept: [ { code: ` - p { - padding: "1" * 1px; - } - `, - description: "Accepts proper value interpolation" + p { + padding: "1" * 1em; + } + `, + description: "Accepts proper value interpolation with em" } ], reject: [ { code: ` p { - padding: #{value}px; + padding: #{value}em; } `, messages: messages.rejected, - description: "Rejects interpolation with a unit" + description: "Rejects interpolation with em" + } + ], + acceptBlah: loopOverUnits({ + code: ` + p { + padding: "1" * 1%unit%; } - ] + `, + description: "Accepts proper value interpolation with %unit%" + }), + rejectBlah: loopOverUnits({ + code: ` + p { + padding: #{value}%unit%; + } + `, + messages: messages.rejected, + description: "Rejects interpolation with %unit%" + }) }); + +function loopOverUnits(codeBlock) { + units.map(unit => { + return { + code: codeBlock.code.replace("%unit%", unit), + description: codeBlock.description.replace("%unit%", unit), + messages: codeBlock.messages + }; + }); +} diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js index 5a9e7cff..d8583837 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -1,14 +1,78 @@ import { utils } from "stylelint"; -import { namespace, isNativeCssFunction } from "../../utils"; +import { namespace } from "../../utils"; import valueParser from "postcss-value-parser"; -export const ruleName = namespace("function-quote-no-quoted-strings-inside"); +export const ruleName = namespace("no-non-numeric-dimensions"); export const messages = utils.ruleMessages(ruleName, { rejected: "Expected `$value * 1px` instead of `#{value}px" }); -function rule(primary, _, context) { +export const units = [ + // Font-relative lengths: + // https://www.w3.org/TR/css-values-4/#font-relative-lengths + "em", + "ex", + "cap", + "ch", + "ic", + "rem", + "lh", + "rlh", + + // Viewport-relative lengths: + // https://www.w3.org/TR/css-values-4/#viewport-relative-lengths + "vw", + "vh", + "vi", + "vb", + "vmin", + "vmax", + + // Absolute lengths: + // https://www.w3.org/TR/css-values-4/#absolute-lengths + "cm", + "mm", + "Q", + "in", + "pc", + "pt", + "px", + + // Angle units: + // https://www.w3.org/TR/css-values-4/#angles + "deg", + "grad", + "rad", + "turn", + + // Duration units: + // https://www.w3.org/TR/css-values-4/#time + "s", + "ms", + + // Frequency units: + // https://www.w3.org/TR/css-values-4/#frequency + "Hz", + "kHz", + + // Resolution units: + // https://www.w3.org/TR/css-values-4/#resolution + "dpi", + "dpcm", + "dppx", + "x", + + // Flexible lengths: + // https://www.w3.org/TR/css-grid-1/#fr-unit + "fr", + + // Percentage: + // https://www.w3.org/TR/css-values-4/#percentages + "%" +]; + +export default function rule(primary) { return (root, result) => { const validOptions = utils.validateOptions(result, ruleName, { actual: primary @@ -17,7 +81,40 @@ function rule(primary, _, context) { if (!validOptions) { return; } + + root.walkDecls(decl => { + valueParser(decl.value).walk(node => { + // All words are non-quoted, while strings are quoted. + // If quoted, it's probably a deliberate non-numeric dimension. + if (node.type !== "word") { + return; + } + + if (!isInterpolated(node.value)) { + return; + } + + utils.report({ + ruleName, + result, + message: messages.rejected, + node: decl + }); + }); + }); }; } -export default rule; +function isInterpolated(value) { + let boolean = false; + + units.forEach(unit => { + const regex = new RegExp("#{[a-z_-]*}" + unit); + + if (value.match(regex)) { + boolean = true; + } + }); + + return boolean; +} From 92abedd94525efcaae6b9c750b2f42fbcad961e1 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 14:40:03 -0700 Subject: [PATCH 04/11] looping over rules and giving better error messages --- .../__tests__/index.js | 38 ++++++------------- src/rules/no-non-numeric-dimensions/index.js | 2 +- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index 54a3faea..5b1a6675 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -4,28 +4,7 @@ testRule(rule, { ruleName, config: [true], syntax: "scss", - accept: [ - { - code: ` - p { - padding: "1" * 1em; - } - `, - description: "Accepts proper value interpolation with em" - } - ], - reject: [ - { - code: ` - p { - padding: #{value}em; - } - `, - messages: messages.rejected, - description: "Rejects interpolation with em" - } - ], - acceptBlah: loopOverUnits({ + accept: loopOverUnits({ code: ` p { padding: "1" * 1%unit%; @@ -33,7 +12,7 @@ testRule(rule, { `, description: "Accepts proper value interpolation with %unit%" }), - rejectBlah: loopOverUnits({ + reject: loopOverUnits({ code: ` p { padding: #{value}%unit%; @@ -45,11 +24,16 @@ testRule(rule, { }); function loopOverUnits(codeBlock) { - units.map(unit => { - return { + return units.map(unit => { + const block = { code: codeBlock.code.replace("%unit%", unit), - description: codeBlock.description.replace("%unit%", unit), - messages: codeBlock.messages + description: codeBlock.description.replace("%unit%", unit) }; + + if (codeBlock.messages) { + block["messages"] = codeBlock.messages.call(unit); + } + + return block; }); } diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js index d8583837..ca24c07e 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -5,7 +5,7 @@ import valueParser from "postcss-value-parser"; export const ruleName = namespace("no-non-numeric-dimensions"); export const messages = utils.ruleMessages(ruleName, { - rejected: "Expected `$value * 1px` instead of `#{value}px" + rejected: unit => `Expected "$value * 1${unit}" instead of "#{value}${unit}"` }); export const units = [ From 39c299e8017b6fc15a591f1e4eb4a540e28cc5aa Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 15:03:26 -0700 Subject: [PATCH 05/11] test fixes + better README --- src/rules/no-non-numeric-dimensions/README.md | 97 ++++++++++++++++++- .../__tests__/index.js | 2 +- src/rules/no-non-numeric-dimensions/index.js | 2 +- 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/src/rules/no-non-numeric-dimensions/README.md b/src/rules/no-non-numeric-dimensions/README.md index 245fd6a7..222b8ceb 100644 --- a/src/rules/no-non-numeric-dimensions/README.md +++ b/src/rules/no-non-numeric-dimensions/README.md @@ -1 +1,96 @@ -# at-non-numeric-dimensinos \ No newline at end of file +# at-non-numeric-dimensions + +Interpolating a value with a unit (e.g. `#{$value}px`) results in a +_string_ value, not as numeric value. This value then cannot be used in +numerical operations. It is better to use arithmetic to apply a unit to a +number (e.g. `$value * 1px`). + +This rule requires that all interpolation for values should be in the format `$value * 1` instead of `#{value}` + +```scss +$value: 4; + +p { + padding: #{value}px; +// ↑ ↑ +// should be $value * 1px +} +``` + +## Options + +### `true` + +The following patterns are considered violations: + +```scss +$value: 4; + +p { + padding: #{value}px; +} +``` + +The following patterns are _not_ considered violations: + +```scss +$value: 4; + +p { + padding: $value * 1px; +} +``` + +## List of units +Font-relative lengths ([link](https://www.w3.org/TR/css-values-4/#font-relative-lengths)) +* em +* ex +* cap +* ch +* ic +* rem +* lh +* rlh + +Viewport-relative lengths ([link](https://www.w3.org/TR/css-values-4/#viewport-relative-lengths)) +* vw +* vh +* vi +* vb +* vmin +* vmax + +Absolute lengths ([link](https://www.w3.org/TR/css-values-4/#absolute-lengths)) +* cm +* mm +* Q +* in +* pc +* pt +* px + +Angle units ([link](https://www.w3.org/TR/css-values-4/#angles)) +* deg +* grad +* rad +* turn + +Duration units ([link](https://www.w3.org/TR/css-values-4/#time)) +* s +* ms + +Frequency units ([link](https://www.w3.org/TR/css-values-4/#frequency)) +* Hz +* kHz + +Resolution units ([link](https://www.w3.org/TR/css-values-4/#resolution)) +* dpi +* dpcm +* dppx +* x + +Flexible lengths ([link](https://www.w3.org/TR/css-grid-1/#fr-unit)) +* fr + +Percentage ([link](https://www.w3.org/TR/css-values-4/#percentages)) +* % \ No newline at end of file diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index 5b1a6675..a50b84d3 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -15,7 +15,7 @@ testRule(rule, { reject: loopOverUnits({ code: ` p { - padding: #{value}%unit%; + padding: #{$value}%unit%; } `, messages: messages.rejected, diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js index ca24c07e..3ef12bca 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -109,7 +109,7 @@ function isInterpolated(value) { let boolean = false; units.forEach(unit => { - const regex = new RegExp("#{[a-z_-]*}" + unit); + const regex = new RegExp("#{[$a-z_-]*}" + unit); if (value.match(regex)) { boolean = true; From b9c8dc8e5c22c980c7e44e97cd5f7a0dc809d08f Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 15:16:20 -0700 Subject: [PATCH 06/11] most tests working --- .../__tests__/index.js | 19 +++++++++++++++++-- src/rules/no-non-numeric-dimensions/index.js | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index a50b84d3..cd899016 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -11,7 +11,16 @@ testRule(rule, { } `, description: "Accepts proper value interpolation with %unit%" - }), + }).concat([ + { + code: "$pad: 2; $doublePad: px#{$pad}px;", + description: "does not report when a unit is preceded by another string" + }, + { + code: "$pad: 2; $doublePad: #{$pad}pxx;", + description: "does not report lint when no understood units are used" + } + ]), reject: loopOverUnits({ code: ` p { @@ -20,7 +29,13 @@ testRule(rule, { `, messages: messages.rejected, description: "Rejects interpolation with %unit%" - }) + }).concat([ + { + code: "$pad: 2; $padAndMore: #{$pad + 5}px;", + description: "reports lint when expression used in interpolation", + messages: messages.rejected("px") + } + ]) }); function loopOverUnits(codeBlock) { diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js index 3ef12bca..62072f0c 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -109,7 +109,7 @@ function isInterpolated(value) { let boolean = false; units.forEach(unit => { - const regex = new RegExp("#{[$a-z_-]*}" + unit); + const regex = new RegExp("^#{[$a-z_0-9 +-]*}" + unit + ";?$"); if (value.match(regex)) { boolean = true; From a0b1d96e8ac2ea8a81993a9963dcd00b1be3ca68 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 12 Aug 2019 15:35:03 -0700 Subject: [PATCH 07/11] things work --- src/rules/no-non-numeric-dimensions/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js index 62072f0c..b81ebc7e 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -108,6 +108,13 @@ export default function rule(primary) { function isInterpolated(value) { let boolean = false; + // ValueParser breaks up interpolation with math into multiple, fragmented + // segments (#{$value, +, 2}px). The easiest way to detect this is to look for a fragmented + // interpolated section. + if (value.match(/^#{\$[a-z]*$/)) { + return true; + } + units.forEach(unit => { const regex = new RegExp("^#{[$a-z_0-9 +-]*}" + unit + ";?$"); From 7367536c50a13a46b36a4a433d487ae9d3306100 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 14 Aug 2019 15:09:23 -0700 Subject: [PATCH 08/11] PR suggestions --- src/rules/no-non-numeric-dimensions/README.md | 3 --- src/rules/no-non-numeric-dimensions/__tests__/index.js | 2 +- src/rules/no-non-numeric-dimensions/index.js | 9 +++------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/rules/no-non-numeric-dimensions/README.md b/src/rules/no-non-numeric-dimensions/README.md index 222b8ceb..089fc78f 100644 --- a/src/rules/no-non-numeric-dimensions/README.md +++ b/src/rules/no-non-numeric-dimensions/README.md @@ -91,6 +91,3 @@ Resolution units ([link](https://www.w3.org/TR/css-values-4/#resolution)) Flexible lengths ([link](https://www.w3.org/TR/css-grid-1/#fr-unit)) * fr - -Percentage ([link](https://www.w3.org/TR/css-values-4/#percentages)) -* % \ No newline at end of file diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index cd899016..c9c524dc 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -7,7 +7,7 @@ testRule(rule, { accept: loopOverUnits({ code: ` p { - padding: "1" * 1%unit%; + padding: 1 * 1%unit%; } `, description: "Accepts proper value interpolation with %unit%" diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/no-non-numeric-dimensions/index.js index b81ebc7e..190b8644 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/no-non-numeric-dimensions/index.js @@ -5,7 +5,8 @@ import valueParser from "postcss-value-parser"; export const ruleName = namespace("no-non-numeric-dimensions"); export const messages = utils.ruleMessages(ruleName, { - rejected: unit => `Expected "$value * 1${unit}" instead of "#{value}${unit}"` + rejected: unit => + `Expected "$value * 1${unit}" instead of "#{value}${unit}". Consider writing "value" in terms of ${unit} originally.` }); export const units = [ @@ -65,11 +66,7 @@ export const units = [ // Flexible lengths: // https://www.w3.org/TR/css-grid-1/#fr-unit - "fr", - - // Percentage: - // https://www.w3.org/TR/css-values-4/#percentages - "%" + "fr" ]; export default function rule(primary) { From aaa3da2e08a337c93e7390c470468229c49b5312 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 14 Aug 2019 15:13:45 -0700 Subject: [PATCH 09/11] test for quotes --- src/rules/no-non-numeric-dimensions/__tests__/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index c9c524dc..fc9317d3 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -19,6 +19,11 @@ testRule(rule, { { code: "$pad: 2; $doublePad: #{$pad}pxx;", description: "does not report lint when no understood units are used" + }, + { + code: `$pad: "2"; + $string: "#{$pad}px";`, + description: "does not report lint when no understood units are used" } ]), reject: loopOverUnits({ From 15d9ca73531f7e9da9d798e8431b8bef6eda2dd6 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 14 Aug 2019 15:25:58 -0700 Subject: [PATCH 10/11] copy and paste error --- src/rules/no-non-numeric-dimensions/__tests__/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/no-non-numeric-dimensions/__tests__/index.js index fc9317d3..b01c8e82 100644 --- a/src/rules/no-non-numeric-dimensions/__tests__/index.js +++ b/src/rules/no-non-numeric-dimensions/__tests__/index.js @@ -23,7 +23,7 @@ testRule(rule, { { code: `$pad: "2"; $string: "#{$pad}px";`, - description: "does not report lint when no understood units are used" + description: "does not report lint when string is quoted" } ]), reject: loopOverUnits({ From 66a08a1dc246639453ccb0b9ebecab4623feea2c Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 26 Aug 2019 13:38:48 -0700 Subject: [PATCH 11/11] rule namechange --- .../README.md | 2 +- .../__tests__/index.js | 0 .../index.js | 2 +- src/rules/index.js | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/rules/{no-non-numeric-dimensions => dimension-no-non-numeric-values}/README.md (97%) rename src/rules/{no-non-numeric-dimensions => dimension-no-non-numeric-values}/__tests__/index.js (100%) rename src/rules/{no-non-numeric-dimensions => dimension-no-non-numeric-values}/index.js (97%) diff --git a/src/rules/no-non-numeric-dimensions/README.md b/src/rules/dimension-no-non-numeric-values/README.md similarity index 97% rename from src/rules/no-non-numeric-dimensions/README.md rename to src/rules/dimension-no-non-numeric-values/README.md index 089fc78f..985444f9 100644 --- a/src/rules/no-non-numeric-dimensions/README.md +++ b/src/rules/dimension-no-non-numeric-values/README.md @@ -1,4 +1,4 @@ -# at-non-numeric-dimensions +# dimension-no-non-numeric-values Interpolating a value with a unit (e.g. `#{$value}px`) results in a _string_ value, not as numeric value. This value then cannot be used in diff --git a/src/rules/no-non-numeric-dimensions/__tests__/index.js b/src/rules/dimension-no-non-numeric-values/__tests__/index.js similarity index 100% rename from src/rules/no-non-numeric-dimensions/__tests__/index.js rename to src/rules/dimension-no-non-numeric-values/__tests__/index.js diff --git a/src/rules/no-non-numeric-dimensions/index.js b/src/rules/dimension-no-non-numeric-values/index.js similarity index 97% rename from src/rules/no-non-numeric-dimensions/index.js rename to src/rules/dimension-no-non-numeric-values/index.js index 190b8644..13c3738c 100644 --- a/src/rules/no-non-numeric-dimensions/index.js +++ b/src/rules/dimension-no-non-numeric-values/index.js @@ -2,7 +2,7 @@ import { utils } from "stylelint"; import { namespace } from "../../utils"; import valueParser from "postcss-value-parser"; -export const ruleName = namespace("no-non-numeric-dimensions"); +export const ruleName = namespace("dimension-no-non-numeric-values"); export const messages = utils.ruleMessages(ruleName, { rejected: unit => diff --git a/src/rules/index.js b/src/rules/index.js index c6f4f809..3b0edbc1 100644 --- a/src/rules/index.js +++ b/src/rules/index.js @@ -19,6 +19,7 @@ import atEachKeyValue from "./at-each-key-value-single-line"; import atRuleNoUnknown from "./at-rule-no-unknown"; import declarationNestedProperties from "./declaration-nested-properties"; import declarationNestedPropertiesNoDividedGroups from "./declaration-nested-properties-no-divided-groups"; +import dimensionNoNonNumeric from "./dimension-no-non-numeric-values"; import dollarVariableColonNewlineAfter from "./dollar-variable-colon-newline-after"; import dollarVariableColonSpaceAfter from "./dollar-variable-colon-space-after"; import dollarVariableColonSpaceBefore from "./dollar-variable-colon-space-before"; @@ -33,7 +34,6 @@ import functionNoQuotedStrings from "./function-quote-no-quoted-strings-inside"; import mediaFeatureValueDollarVariable from "./media-feature-value-dollar-variable"; import noDollarVariables from "./no-dollar-variables"; import noDuplicateDollarVariables from "./no-duplicate-dollar-variables"; -import noNonNumericDimensions from "./no-non-numeric-dimensions"; import operatorNoNewlineAfter from "./operator-no-newline-after"; import operatorNoNewlineBefore from "./operator-no-newline-before"; import operatorNoUnspaced from "./operator-no-unspaced"; @@ -64,6 +64,7 @@ export default { "at-rule-no-unknown": atRuleNoUnknown, "declaration-nested-properties": declarationNestedProperties, "declaration-nested-properties-no-divided-groups": declarationNestedPropertiesNoDividedGroups, + "dimension-no-non-numeric-values": dimensionNoNonNumeric, "dollar-variable-colon-newline-after": dollarVariableColonNewlineAfter, "dollar-variable-colon-space-after": dollarVariableColonSpaceAfter, "dollar-variable-colon-space-before": dollarVariableColonSpaceBefore, @@ -78,7 +79,6 @@ export default { "media-feature-value-dollar-variable": mediaFeatureValueDollarVariable, "no-dollar-variables": noDollarVariables, "no-duplicate-dollar-variables": noDuplicateDollarVariables, - "no-non-numeric-dimensions": noNonNumericDimensions, "operator-no-newline-after": operatorNoNewlineAfter, "operator-no-newline-before": operatorNoNewlineBefore, "operator-no-unspaced": operatorNoUnspaced,