@mslmio/eslint-config 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
const CLASS_FNS = new Set(["cn", "clsx", "cva", "classNames", "twMerge", "twJoin"]);
|
|
2
2
|
const COLOR_RE = /^(#|rgba?\(|hsla?\(|oklch\(|oklab\(|lab\(|lch\(|color-mix\(|currentColor|transparent)/i;
|
|
3
|
-
const LENGTH_RE = /(^|[\d.])(rem|px|em|ex|ch|vw|vh|vmin|vmax|pt|pc|%)\b|^(calc|clamp|min|max
|
|
4
|
-
|
|
3
|
+
const LENGTH_RE = /(^|[\d.])(rem|px|em|ex|ch|vw|vh|vmin|vmax|pt|pc|%)\b|^(calc|clamp|min|max)\(|^[\d.]+$/;
|
|
4
|
+
// The type hints Tailwind resolves `text-` to a font size for. Any other hint names a color.
|
|
5
|
+
const SIZE_HINT_RE = /^(length|percentage|absolute-size|relative-size):/;
|
|
6
|
+
const HINT_RE = /^[a-z-]+:/;
|
|
7
|
+
// `text-[...]`, or the `text-(...)` variable shorthand, with an optional `/leading` modifier.
|
|
8
|
+
const TEXT_ARB_RE = /\btext-(?:\[([^\]]+)\]|\(([^)]+)\))(\/\S+)?/g;
|
|
5
9
|
|
|
6
10
|
export default {
|
|
7
11
|
meta: {
|
|
@@ -13,9 +17,9 @@ export default {
|
|
|
13
17
|
schema: [{ type: "object", properties: { docsUrl: { type: "string" } }, additionalProperties: false }],
|
|
14
18
|
messages: {
|
|
15
19
|
needsLeading:
|
|
16
|
-
"`
|
|
20
|
+
"`{{value}}` sets a font SIZE only, so line height comes from whatever ancestor " +
|
|
17
21
|
"set one - which differs between hosts and renders the same row at two heights. State it: " +
|
|
18
|
-
"`
|
|
22
|
+
"`{{value}}/[<leading>]` or an explicit `leading-*`.{{docs}}",
|
|
19
23
|
},
|
|
20
24
|
},
|
|
21
25
|
create(context) {
|
|
@@ -29,10 +33,10 @@ export default {
|
|
|
29
33
|
}
|
|
30
34
|
for (const part of parts) {
|
|
31
35
|
for (const m of part.matchAll(TEXT_ARB_RE)) {
|
|
32
|
-
if (m[
|
|
36
|
+
if (m[3] || !isLength(m[1] ?? m[2])) {
|
|
33
37
|
continue;
|
|
34
38
|
}
|
|
35
|
-
context.report({ node: node, messageId: "needsLeading", data: { value: m[
|
|
39
|
+
context.report({ node: node, messageId: "needsLeading", data: { value: m[0], docs: docs } });
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
};
|
|
@@ -74,7 +78,13 @@ function collectStrings(node, seen) {
|
|
|
74
78
|
|
|
75
79
|
function isLength(value) {
|
|
76
80
|
const v = value.trim();
|
|
77
|
-
if (
|
|
81
|
+
if (SIZE_HINT_RE.test(v)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
// An unhinted variable is a COLOR: Tailwind reads `text-[var(--chart-2)]` and `text-(--chart-2)`
|
|
85
|
+
// as `color`. Calling it a size once got it "fixed" to `text-[var(--chart-2)]/[1.5]`, which
|
|
86
|
+
// compiles to a 150% color-mix - invalid, so the text silently lost its color.
|
|
87
|
+
if (HINT_RE.test(v) || v.startsWith("var(") || v.startsWith("--") || COLOR_RE.test(v)) {
|
|
78
88
|
return false;
|
|
79
89
|
}
|
|
80
90
|
return LENGTH_RE.test(v);
|