Skip to content

Commit 7a2ecad

Browse files
authored
fix: make relative-font-units unit matching case-insensitive (#222)
1 parent c564397 commit 7a2ecad

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

src/rules/relative-font-units.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export default {
103103

104104
if (
105105
(value.type === "Dimension" &&
106-
!allowedFontUnits.includes(value.unit)) ||
106+
!allowedFontUnits.includes(
107+
value.unit.toLowerCase(),
108+
)) ||
107109
(value.type === "Identifier" &&
108110
disallowedFontSizeKeywords.has(
109111
value.name.toLowerCase(),
@@ -161,7 +163,7 @@ export default {
161163
check:
162164
dimensionNode &&
163165
!allowedFontUnits.includes(
164-
dimensionNode.unit,
166+
dimensionNode.unit.toLowerCase(),
165167
),
166168
loc: dimensionNode?.loc,
167169
},

tests/rules/relative-font-units.test.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ ruleTester.run("relative-font-units", rule, {
2828
"a { font-size: 1rem; }",
2929
"a { font: 2rem Arial, sans-serif; }",
3030
"a { font: 1.2rem/2 Arial, sans-serif; }",
31+
"a { font-size: 1REM; }",
32+
"a { font-size: 1Rem; }",
33+
"a { font-size: 1rEm; }",
34+
"a { font: 2REM Arial, sans-serif; }",
35+
"a { font: 1.2REM/2 Arial, sans-serif; }",
3136
"a { font-size: var(--foo); }",
3237
"a { font: var(--foo) Arial; }",
3338
"a { font-size: calc(10px + 2px); }",
@@ -221,6 +226,76 @@ ruleTester.run("relative-font-units", rule, {
221226
},
222227
],
223228
},
229+
{
230+
code: "a { font-size: 1EM; }",
231+
options: [{ allowUnits: ["em"] }],
232+
},
233+
{
234+
code: "a { font: 2EM Arial, sans-serif; }",
235+
options: [{ allowUnits: ["em"] }],
236+
},
237+
{
238+
code: "a { font-size: 2CAP; }",
239+
options: [{ allowUnits: ["cap"] }],
240+
},
241+
{
242+
code: "a { font-size: 20CH; }",
243+
options: [{ allowUnits: ["ch"] }],
244+
},
245+
{
246+
code: "a { font-size: 3EX; }",
247+
options: [{ allowUnits: ["ex"] }],
248+
},
249+
{
250+
code: "a { font-size: 2IC; }",
251+
options: [{ allowUnits: ["ic"] }],
252+
},
253+
{
254+
code: "a { font-size: 1LH; }",
255+
options: [{ allowUnits: ["lh"] }],
256+
},
257+
{
258+
code: "a { font-size: 2RCAP; }",
259+
options: [{ allowUnits: ["rcap"] }],
260+
},
261+
{
262+
code: "a { font-size: 20RCH; }",
263+
options: [{ allowUnits: ["rch"] }],
264+
},
265+
{
266+
code: "a { font-size: 2REX; }",
267+
options: [{ allowUnits: ["rex"] }],
268+
},
269+
{
270+
code: "a { font-size: 1.5RIC; }",
271+
options: [{ allowUnits: ["ric"] }],
272+
},
273+
{
274+
code: "a { font-size: 1RLH; }",
275+
options: [{ allowUnits: ["rlh"] }],
276+
},
277+
{
278+
code: dedent`
279+
a {
280+
font-size: 1REM;
281+
}
282+
b {
283+
font-size: 1Em;
284+
}
285+
`,
286+
options: [{ allowUnits: ["rem", "em"] }],
287+
},
288+
{
289+
code: dedent`
290+
a {
291+
font: 2REM Arial, sans-serif;
292+
}
293+
b {
294+
font: 1.5EM "Helvetica", sans-serif;
295+
}
296+
`,
297+
options: [{ allowUnits: ["rem", "em"] }],
298+
},
224299
{
225300
code: "a { font-size: smaller; }",
226301
options: [
@@ -491,6 +566,40 @@ ruleTester.run("relative-font-units", rule, {
491566
},
492567
],
493568
},
569+
{
570+
code: "a { font-size: 1PX; }",
571+
errors: [{ messageId: "allowedFontUnits" }],
572+
},
573+
{
574+
code: "a { font-size: 1IN; }",
575+
errors: [{ messageId: "allowedFontUnits" }],
576+
},
577+
{
578+
code: "a { font-size: 1CM; }",
579+
errors: [{ messageId: "allowedFontUnits" }],
580+
},
581+
{
582+
code: "a { font-size: 1MM; }",
583+
errors: [{ messageId: "allowedFontUnits" }],
584+
},
585+
{
586+
code: "a { font-size: 1PT; }",
587+
errors: [{ messageId: "allowedFontUnits" }],
588+
},
589+
{
590+
code: "a { font-size: 1PC; }",
591+
errors: [{ messageId: "allowedFontUnits" }],
592+
},
593+
{
594+
code: "a { font-size: 1EM; }",
595+
options: [{ allowUnits: ["rem"] }],
596+
errors: [{ messageId: "allowedFontUnits" }],
597+
},
598+
{
599+
code: "a { font: 2EM Arial, sans-serif; }",
600+
options: [{ allowUnits: ["rem"] }],
601+
errors: [{ messageId: "allowedFontUnits" }],
602+
},
494603
{
495604
code: "a { font-size: xx-small; }",
496605
errors: [

0 commit comments

Comments
 (0)