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

New rule: No non numeric dimensions #357

Merged
3 changes: 0 additions & 3 deletions src/rules/no-non-numeric-dimensions/README.md
Expand Up @@ -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))
* %
7 changes: 6 additions & 1 deletion src/rules/no-non-numeric-dimensions/__tests__/index.js
Expand Up @@ -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%"
Expand All @@ -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"
rambleraptor marked this conversation as resolved.
Show resolved Hide resolved
}
]),
reject: loopOverUnits({
Expand Down
9 changes: 3 additions & 6 deletions src/rules/no-non-numeric-dimensions/index.js
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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) {
Expand Down