@tenphi/eslint-plugin-tasty 1.15.0 → 1.17.0

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/README.md CHANGED
@@ -259,11 +259,11 @@ not matched.
259
259
  | `tasty/no-raw-transition-duration` | warn | Hardcoded `transition` duration (`fill 0.2s`) in Tasty styles or a local `tasty()` component's `transition` prop. Suggests a configured duration token or the implicit per-name timing; zero and delays are left alone |
260
260
  | `tasty/no-runtime-styles-mutation` | warn | Render-time JavaScript in Tasty style values (props, state, hook results, parameters, local bindings, calls, computed keys); use states and tokens instead. Module-scope constants, imports, `undefined` and static `mergeStyles(...)` calls are fixed at load and allowed |
261
261
  | `tasty/no-style-spread` | warn | Object or array spreads inside runtime Tasty styles; recommends `mergeStyles` for multiple root spreads; intentional spreads need a per-line suppression and reason |
262
- | `tasty/no-style-prop` | warn | `style` on recognized Tasty components; use token references and the `tokens` prop. The `elements` option covers every component or element, so it can replace React's `style` restriction ([details](docs/rules/no-style-prop.md)) |
262
+ | `tasty/no-style-prop` | warn | `style` on recognized Tasty components; use token references and the `tokens` prop. The `elements` option covers every component or element, so it can replace React's `style` restriction; `values: 'static'` reports only static styles. Tasty syntax in `style` is always reported ([details](docs/rules/no-style-prop.md)) |
263
263
  | `tasty/no-classname-prop` | warn | `className` on recognized Tasty components; keep styling in Tasty or use `data-element` for sub-elements ([details](docs/rules/no-classname-prop.md)) |
264
264
  | `tasty/no-styles-prop` | warn | Instance `styles` on recognized Tasty components; use `tokens`, `mods`, exposed props/variants, or `tasty(Component, { styles })` ([details](docs/rules/no-styles-prop.md)) |
265
265
  | `tasty/no-protected-restyle` | warn | Restyling a design system's `protectedComponents`: instance `styles` and `*Styles`, appearance style props, and `tasty()` wrappers that restyle them, followed through aliases, wrappers and relative re-exports. Inactive without the config ([details](docs/rules/no-protected-restyle.md)) |
266
- | `tasty/consistent-token-usage` | warn | Nonzero raw pixel lengths, including compounds, expressions and numeric inputs to enhanced length handlers |
266
+ | `tasty/consistent-token-usage` | warn | Nonzero raw pixel lengths, including compounds, expressions and numeric inputs to enhanced length handlers. The `pixels: 'replaceable'` option reports only lengths with an exact unit, such as `8px` → `1x` ([details](docs/rules/consistent-token-usage.md)) |
267
267
  | `tasty/prefer-auto-calc` | warn | `calc(...)` instead of Tasty auto-calc `(...)` |
268
268
  | `tasty/prefer-state-negation` | warn | Top-level `:not(...)` in state keys instead of the `!` prefix (autofixable; nested CSS selectors stay intact) |
269
269
  | `tasty/prefer-custom-property-syntax` | warn | `var(--prop)` / `$x-color` / `transparent` / `currentColor` instead of `$prop` / `#color` / `#clear` / `#current` |
@@ -565,8 +565,11 @@ are checked only for enhanced handlers that convert them to pixels; unitless
565
565
  properties such as `opacity` and `zIndex` are unaffected. Known equivalents still
566
566
  have suggestions (`8px` → `1x`, radius `6px` → `1r`, border `1px` → `1bw`). These
567
567
  assume the conventional scale defaults; review them against your design system.
568
- Other pixels are report-only. Zero, token definitions, quoted CSS text, and URLs
569
- are allowed. Quotes and URLs are also excluded from token and raw-color checks.
568
+ Font size, line height and letter spacing are on the type scale, so they get no
569
+ `x` suggestion.
570
+ Other pixels are report-only. With the `pixels: 'replaceable'` option, they are
571
+ not reported, and only lengths with an exact unit are. Zero, token definitions,
572
+ quoted CSS text, and URLs are allowed. Quotes and URLs are also excluded from token and raw-color checks.
570
573
  Range-based fixes are withheld when JavaScript escapes or JSX entities make
571
574
  source offsets differ from the decoded value.
572
575
 
@@ -17,6 +17,15 @@ import { replaceInStringValue } from "../fix-utils.js";
17
17
  * happened to use.
18
18
  */
19
19
  const BORDER_WIDTH_PROPERTIES = new Set(["border", ...LOGICAL_BORDER_STYLES]);
20
+ /**
21
+ * Lengths on the type scale, which presets set. `x` is the spacing scale, so a
22
+ * `16px` line height equals `2x` only by coincidence and gets no suggestion.
23
+ */
24
+ const TYPE_SCALE_PROPERTIES = new Set([
25
+ "fontSize",
26
+ "lineHeight",
27
+ "letterSpacing"
28
+ ]);
20
29
  /** Enhanced handlers that convert numeric inputs to pixels. Unitless CSS stays out. */
21
30
  const NUMERIC_PIXEL_PROPERTIES = new Set([
22
31
  ...LOGICAL_STYLES,
@@ -81,32 +90,40 @@ var consistent_token_usage_default = createRule({
81
90
  preferToken: "Consider using '{{suggestion}}' instead of '{{raw}}'. For an intentional pixel value, explicitly disable tasty/consistent-token-usage on this line with a reason.",
82
91
  replaceWithToken: "Replace '{{raw}}' with '{{suggestion}}'"
83
92
  },
84
- schema: []
93
+ schema: [{
94
+ type: "object",
95
+ properties: { pixels: {
96
+ type: "string",
97
+ enum: ["all", "replaceable"]
98
+ } },
99
+ additionalProperties: false
100
+ }]
85
101
  },
86
- defaultOptions: [],
87
- create(context) {
102
+ defaultOptions: [{ pixels: "all" }],
103
+ create(context, [{ pixels = "all" }]) {
88
104
  const ctx = new TastyContext(context);
89
105
  function checkValue(property, value, node) {
90
106
  if (/^[#$]/.test(property)) return;
91
- const pixels = /* @__PURE__ */ new Map();
107
+ const lengths = /* @__PURE__ */ new Map();
92
108
  for (const word of scanValueWords(value)) {
93
109
  if (!/^[+-]?(?:\d*\.\d+|\d+\.?\d*)(?:e[+-]?\d+)?px$/i.test(word.value)) continue;
94
110
  const amount = Number(word.value.slice(0, -2));
95
111
  if (amount === 0) continue;
96
112
  const raw = word.value;
97
113
  const canonical = `${amount}px`;
98
- const suggestion = property === "radius" && amount === 6 ? "1r" : BORDER_WIDTH_PROPERTIES.has(property) && amount === 1 ? "1bw" : PX_TO_UNIT[canonical];
99
- const edits = pixels.get(raw) ?? [];
114
+ const suggestion = property === "radius" && amount === 6 ? "1r" : BORDER_WIDTH_PROPERTIES.has(property) && amount === 1 ? "1bw" : TYPE_SCALE_PROPERTIES.has(property) ? void 0 : PX_TO_UNIT[canonical];
115
+ const edits = lengths.get(raw) ?? [];
100
116
  edits.push({
101
117
  start: word.offset,
102
118
  end: word.offset + raw.length,
103
119
  replacement: suggestion ?? ""
104
120
  });
105
- pixels.set(raw, edits);
121
+ lengths.set(raw, edits);
106
122
  }
107
- for (const [raw, edits] of pixels) {
123
+ for (const [raw, edits] of lengths) {
108
124
  const suggestion = edits[0].replacement;
109
125
  if (!suggestion) {
126
+ if (pixels === "replaceable") continue;
110
127
  context.report({
111
128
  node,
112
129
  messageId: "rawPixelValue",
@@ -1 +1 @@
1
- {"version":3,"file":"consistent-token-usage.js","names":[],"sources":["../../src/rules/consistent-token-usage.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { styleValueListeners } from '../style-values.js';\nimport { LOGICAL_BORDER_STYLES, LOGICAL_STYLES } from '../constants.js';\nimport { getStringValue } from '../utils.js';\nimport { replaceInStringValue } from '../fix-utils.js';\nimport { scanValueWords } from '../value-words.js';\n\ntype MessageIds = 'preferToken' | 'rawPixelValue' | 'replaceWithToken';\n\n/**\n * Properties whose value carries a border width, so a `1px` in one is the\n * `1bw` token spelled out.\n *\n * The logical axes belong here for the same reason `border` does: they take the\n * same width/style/colour value, parsed by the same `parseBorderValue`. Leaving\n * them out would make the advice depend on which axis vocabulary the author\n * happened to use.\n */\nconst BORDER_WIDTH_PROPERTIES = new Set<string>([\n 'border',\n ...LOGICAL_BORDER_STYLES,\n]);\n\n/** Enhanced handlers that convert numeric inputs to pixels. Unitless CSS stays out. */\nconst NUMERIC_PIXEL_PROPERTIES = new Set<string>([\n ...LOGICAL_STYLES,\n 'gap',\n 'radius',\n 'outlineOffset',\n 'width',\n 'minWidth',\n 'maxWidth',\n 'height',\n 'minHeight',\n 'maxHeight',\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'inset',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'border',\n 'borderTop',\n 'borderRight',\n 'borderBottom',\n 'borderLeft',\n 'scrollPadding',\n 'scrollPaddingTop',\n 'scrollPaddingRight',\n 'scrollPaddingBottom',\n 'scrollPaddingLeft',\n 'scrollMargin',\n 'scrollMarginTop',\n 'scrollMarginRight',\n 'scrollMarginBottom',\n 'scrollMarginLeft',\n]);\n\nconst PX_TO_UNIT: Record<string, string> = {\n '8px': '1x',\n '16px': '2x',\n '24px': '3x',\n '32px': '4x',\n '40px': '5x',\n '48px': '6x',\n '56px': '7x',\n '64px': '8x',\n};\n\nexport default createRule<[], MessageIds>({\n name: 'consistent-token-usage',\n meta: {\n type: 'suggestion',\n hasSuggestions: true,\n docs: {\n description:\n 'Suggest using design tokens and custom units instead of raw CSS values',\n },\n messages: {\n rawPixelValue:\n \"Use a design token or custom unit instead of raw pixel value '{{raw}}'. For an intentional pixel value, explicitly disable tasty/consistent-token-usage on this line with a reason.\",\n preferToken:\n \"Consider using '{{suggestion}}' instead of '{{raw}}'. For an intentional pixel value, explicitly disable tasty/consistent-token-usage on this line with a reason.\",\n replaceWithToken: \"Replace '{{raw}}' with '{{suggestion}}'\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n\n function checkValue(\n property: string,\n value: string,\n node: TSESTree.Node,\n ): void {\n // Definitions establish the scale itself; quoted text and URLs are opaque.\n if (/^[#$]/.test(property)) return;\n const pixels = new Map<\n string,\n { start: number; end: number; replacement: string }[]\n >();\n for (const word of scanValueWords(value)) {\n if (!/^[+-]?(?:\\d*\\.\\d+|\\d+\\.?\\d*)(?:e[+-]?\\d+)?px$/i.test(word.value))\n continue;\n const amount = Number(word.value.slice(0, -2));\n if (amount === 0) continue;\n const raw = word.value;\n const canonical = `${amount}px`;\n const suggestion =\n property === 'radius' && amount === 6\n ? '1r'\n : BORDER_WIDTH_PROPERTIES.has(property) && amount === 1\n ? '1bw'\n : PX_TO_UNIT[canonical];\n const edits = pixels.get(raw) ?? [];\n edits.push({\n start: word.offset,\n end: word.offset + raw.length,\n replacement: suggestion ?? '',\n });\n pixels.set(raw, edits);\n }\n for (const [raw, edits] of pixels) {\n const suggestion = edits[0].replacement;\n if (!suggestion) {\n context.report({ node, messageId: 'rawPixelValue', data: { raw } });\n continue;\n }\n context.report({\n node,\n messageId: 'preferToken',\n data: { suggestion, raw },\n suggest: [\n {\n messageId: 'replaceWithToken',\n data: { raw, suggestion },\n fix: (fixer) =>\n getStringValue(node) === null\n ? fixer.replaceText(node, `'${suggestion}'`)\n : replaceInStringValue(\n fixer,\n node,\n edits,\n context.sourceCode,\n ),\n },\n ],\n });\n }\n }\n\n return styleValueListeners(ctx, (property, node) => {\n const value = getStringValue(node);\n if (value !== null) {\n checkValue(property, value, node);\n } else if (NUMERIC_PIXEL_PROPERTIES.has(property)) {\n if (node.type === 'Literal' && typeof node.value === 'number') {\n checkValue(property, `${node.value}px`, node);\n } else if (\n node.type === 'UnaryExpression' &&\n (node.operator === '-' || node.operator === '+') &&\n node.argument.type === 'Literal' &&\n typeof node.argument.value === 'number'\n ) {\n const amount =\n node.operator === '-' ? -node.argument.value : node.argument.value;\n checkValue(property, `${amount}px`, node);\n }\n }\n });\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAM,0BAA0B,IAAI,IAAY,CAC9C,UACA,GAAG,sBACJ,CAAC;;AAGF,MAAM,2BAA2B,IAAI,IAAY;CAC/C,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,aAAqC;CACzC,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACT;AAED,qCAAe,WAA2B;CACxC,MAAM;CACN,MAAM;EACJ,MAAM;EACN,gBAAgB;EAChB,MAAM,EACJ,aACE,0EACH;EACD,UAAU;GACR,eACE;G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e,KAAK;AAClC,OAAI,UAAU,KACZ,YAAW,UAAU,OAAO,KAAK;YACxB,yBAAyB,IAAI,SAAS,EAC/C;QAAI,KAAK,SAAS,aAAa,OAAO,KAAK,UAAU,SACnD,YAAW,UAAU,GAAG,KAAK,MAAM,KAAK,KAAK;aAE7C,KAAK,SAAS,sBACb,KAAK,aAAa,OAAO,KAAK,aAAa,QAC5C,KAAK,SAAS,SAAS,aACvB,OAAO,KAAK,SAAS,UAAU,SAI/B,YAAW,UAAU,GADnB,KAAK,aAAa,MAAM,CAAC,KAAK,SAAS,QAAQ,KAAK,SAAS,MAChC,KAAK,KAAK;;IAG7C;;CAEL,CAAC"}
1
+ {"version":3,"file":"consistent-token-usage.js","names":[],"sources":["../../src/rules/consistent-token-usage.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { styleValueListeners } from '../style-values.js';\nimport { LOGICAL_BORDER_STYLES, LOGICAL_STYLES } from '../constants.js';\nimport { getStringValue } from '../utils.js';\nimport { replaceInStringValue } from '../fix-utils.js';\nimport { scanValueWords } from '../value-words.js';\n\ntype MessageIds = 'preferToken' | 'rawPixelValue' | 'replaceWithToken';\n\n/**\n * Which pixel lengths to report: every one, or only those with an exact\n * replacement, so a project can enforce the known units without listing every\n * layout size it chose in pixels.\n */\ntype Pixels = 'all' | 'replaceable';\n\n/**\n * Properties whose value carries a border width, so a `1px` in one is the\n * `1bw` token spelled out.\n *\n * The logical axes belong here for the same reason `border` does: they take the\n * same width/style/colour value, parsed by the same `parseBorderValue`. Leaving\n * them out would make the advice depend on which axis vocabulary the author\n * happened to use.\n */\nconst BORDER_WIDTH_PROPERTIES = new Set<string>([\n 'border',\n ...LOGICAL_BORDER_STYLES,\n]);\n\n/**\n * Lengths on the type scale, which presets set. `x` is the spacing scale, so a\n * `16px` line height equals `2x` only by coincidence and gets no suggestion.\n */\nconst TYPE_SCALE_PROPERTIES = new Set<string>([\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n]);\n\n/** Enhanced handlers that convert numeric inputs to pixels. Unitless CSS stays out. */\nconst NUMERIC_PIXEL_PROPERTIES = new Set<string>([\n ...LOGICAL_STYLES,\n 'gap',\n 'radius',\n 'outlineOffset',\n 'width',\n 'minWidth',\n 'maxWidth',\n 'height',\n 'minHeight',\n 'maxHeight',\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'inset',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'border',\n 'borderTop',\n 'borderRight',\n 'borderBottom',\n 'borderLeft',\n 'scrollPadding',\n 'scrollPaddingTop',\n 'scrollPaddingRight',\n 'scrollPaddingBottom',\n 'scrollPaddingLeft',\n 'scrollMargin',\n 'scrollMarginTop',\n 'scrollMarginRight',\n 'scrollMarginBottom',\n 'scrollMarginLeft',\n]);\n\nconst PX_TO_UNIT: Record<string, string> = {\n '8px': '1x',\n '16px': '2x',\n '24px': '3x',\n '32px': '4x',\n '40px': '5x',\n '48px': '6x',\n '56px': '7x',\n '64px': '8x',\n};\n\nexport default createRule<[{ pixels?: Pixels }], MessageIds>({\n name: 'consistent-token-usage',\n meta: {\n type: 'suggestion',\n hasSuggestions: true,\n docs: {\n description:\n 'Suggest using design tokens and custom units instead of raw CSS values',\n },\n messages: {\n rawPixelValue:\n \"Use a design token or custom unit instead of raw pixel value '{{raw}}'. For an intentional pixel value, explicitly disable tasty/consistent-token-usage on this line with a reason.\",\n preferToken:\n \"Consider using '{{suggestion}}' instead of '{{raw}}'. For an intentional pixel value, explicitly disable tasty/consistent-token-usage on this line with a reason.\",\n replaceWithToken: \"Replace '{{raw}}' with '{{suggestion}}'\",\n },\n schema: [\n {\n type: 'object',\n properties: {\n pixels: { type: 'string', enum: ['all', 'replaceable'] },\n },\n additionalProperties: false,\n },\n ],\n },\n defaultOptions: [{ pixels: 'all' }],\n create(context, [{ pixels = 'all' }]) {\n const ctx = new TastyContext(context);\n\n function checkValue(\n property: string,\n value: string,\n node: TSESTree.Node,\n ): void {\n // Definitions establish the scale itself; quoted text and URLs are opaque.\n if (/^[#$]/.test(property)) return;\n const lengths = new Map<\n string,\n { start: number; end: number; replacement: string }[]\n >();\n for (const word of scanValueWords(value)) {\n if (!/^[+-]?(?:\\d*\\.\\d+|\\d+\\.?\\d*)(?:e[+-]?\\d+)?px$/i.test(word.value))\n continue;\n const amount = Number(word.value.slice(0, -2));\n if (amount === 0) continue;\n const raw = word.value;\n const canonical = `${amount}px`;\n const suggestion =\n property === 'radius' && amount === 6\n ? '1r'\n : BORDER_WIDTH_PROPERTIES.has(property) && amount === 1\n ? '1bw'\n : TYPE_SCALE_PROPERTIES.has(property)\n ? undefined\n : PX_TO_UNIT[canonical];\n const edits = lengths.get(raw) ?? [];\n edits.push({\n start: word.offset,\n end: word.offset + raw.length,\n replacement: suggestion ?? '',\n });\n lengths.set(raw, edits);\n }\n for (const [raw, edits] of lengths) {\n const suggestion = edits[0].replacement;\n if (!suggestion) {\n if (pixels === 'replaceable') continue;\n context.report({ node, messageId: 'rawPixelValue', data: { raw } });\n continue;\n }\n context.report({\n node,\n messageId: 'preferToken',\n data: { suggestion, raw },\n suggest: [\n {\n messageId: 'replaceWithToken',\n data: { raw, suggestion },\n fix: (fixer) =>\n getStringValue(node) === null\n ? fixer.replaceText(node, `'${suggestion}'`)\n : replaceInStringValue(\n fixer,\n node,\n edits,\n context.sourceCode,\n ),\n },\n ],\n });\n }\n }\n\n return styleValueListeners(ctx, (property, node) => {\n const value = getStringValue(node);\n if (value !== null) {\n checkValue(property, value, node);\n } else if (NUMERIC_PIXEL_PROPERTIES.has(property)) {\n if (node.type === 'Literal' && typeof node.value === 'number') {\n checkValue(property, `${node.value}px`, node);\n } else if (\n node.type === 'UnaryExpression' &&\n (node.operator === '-' || node.operator === '+') &&\n node.argument.type === 'Literal' &&\n typeof node.argument.value === 'number'\n ) {\n const amount =\n node.operator === '-' ? -node.argument.value : node.argument.value;\n checkValue(property, `${amount}px`, node);\n }\n }\n });\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,MAAM,0BAA0B,IAAI,IAAY,CAC9C,UACA,GAAG,sBACJ,CAAC;;;;;AAMF,MAAM,wBAAwB,IAAI,IAAY;CAC5C;CACA;CACA;CACD,CAAC;;AAGF,MAAM,2BAA2B,IAAI,IAAY;CAC/C,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,aAAqC;CACzC,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACT;AAED,qCAAe,WAA8C;CAC3D,MAAM;CACN,MAAM;EACJ,MAAM;EACN,gBAAgB;EAChB,MAAM,EACJ,aACE,0EACH;EACD,UAAU;GACR,eACE;GACF,aACE;GACF,kBAAkB;GACnB;EACD,QAAQ,CACN;GACE,MAAM;GACN,YAAY,EACV,QAAQ;IAAE,MAAM;IAAU,MAAM,CAAC,OAAO,cAAc;IAAE,EACzD;GACD,sBAAsB;GACvB,CACF;EACF;CACD,gBAAgB,CAAC,EAAE,QAAQ,OAAO,CAAC;CACnC,OAAO,SAAS,CAAC,EAAE,SAAS,UAAU;EACpC,MAAM,MAAM,IAAI,aAAa,QAAQ;EAErC,SAAS,WACP,UACA,OACA,MACM;AAEN,OAAI,QAAQ,KAAK,SAAS,CAAE;GAC5B,MAAM,0BAAU,IAAI,KAGjB;AACH,QAAK,MAAM,QAAQ,eAAe,MAAM,EAAE;AACxC,QAAI,CAAC,iDAAiD,KAAK,KAAK,MAAM,CACpE;IACF,MAAM,SAAS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AK,SAAS,UAAU,SAI/B,YAAW,UAAU,GADnB,KAAK,aAAa,MAAM,CAAC,KAAK,SAAS,QAAQ,KAAK,SAAS,MAChC,KAAK,KAAK;;IAG7C;;CAEL,CAAC"}
@@ -1,5 +1,8 @@
1
1
  import { createRule } from "../create-rule.js";
2
+ import { BUILT_IN_UNITS, CSS_UNITS } from "../constants.js";
3
+ import { extractCustomUnit, getStringValue, isRawHexColor, isStaticValue, unwrapExpression } from "../utils.js";
2
4
  import { TastyContext } from "../context.js";
5
+ import { scanValueWords } from "../value-words.js";
3
6
  import { jsxPropListeners } from "./tasty-component-props.js";
4
7
 
5
8
  //#region src/rules/no-style-prop.ts
@@ -12,6 +15,18 @@ const KINDS = {
12
15
  "element"
13
16
  ])
14
17
  };
18
+ /** `lh` is a Tasty unit and a CSS one, so inline CSS reads it correctly. */
19
+ const INLINE_CSS_UNITS = new Set([...CSS_UNITS, "lh"]);
20
+ /** A word inline CSS cannot read: a Tasty unit, color token or `$` token. */
21
+ function tastySyntaxWord(value, config) {
22
+ for (const { value: word } of scanValueWords(value)) {
23
+ if (/^\$\$?[a-z]/i.test(word)) return word;
24
+ if (/^##?[a-z]/i.test(word) && !isRawHexColor(word)) return word;
25
+ const unit = extractCustomUnit(word);
26
+ if (unit !== null && !INLINE_CSS_UNITS.has(unit) && (BUILT_IN_UNITS.has(unit) || Array.isArray(config.units) && config.units.includes(unit))) return word;
27
+ }
28
+ return null;
29
+ }
15
30
  var no_style_prop_default = createRule({
16
31
  name: "no-style-prop",
17
32
  meta: {
@@ -19,25 +34,77 @@ var no_style_prop_default = createRule({
19
34
  docs: { description: "Prefer tokens over React inline style on Tasty components" },
20
35
  messages: {
21
36
  noStyleProp: "Avoid the 'style' prop on Tasty components. Define styles with token references and pass dynamic values through 'tokens' (e.g. tokens={{ $size: value }}). If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.",
22
- noInlineStyle: "Avoid the 'style' prop. Move these styles into Tasty: render a tasty() element, or wrap the component with tasty(Component, { styles }), using token references and passing dynamic values through 'tokens'. If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason."
37
+ noInlineStyle: "Avoid the 'style' prop. Move these styles into Tasty: render a tasty() element, or wrap the component with tasty(Component, { styles }), using token references and passing dynamic values through 'tokens'. If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.",
38
+ staticStyle: "This 'style' is static, so it belongs in Tasty styles: style props or the component's styles on a Tasty component, a tasty() element or tasty(Component, { styles }) elsewhere. If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.",
39
+ tastySyntax: "'{{word}}' is Tasty syntax, but 'style' hands it to the browser unparsed, which drops the declaration. Move this style into Tasty styles."
23
40
  },
24
41
  schema: [{
25
42
  type: "object",
26
- properties: { elements: {
27
- type: "string",
28
- enum: [
29
- "tasty",
30
- "components",
31
- "all"
32
- ]
33
- } },
43
+ properties: {
44
+ elements: {
45
+ type: "string",
46
+ enum: [
47
+ "tasty",
48
+ "components",
49
+ "all"
50
+ ]
51
+ },
52
+ values: {
53
+ type: "string",
54
+ enum: ["all", "static"]
55
+ }
56
+ },
34
57
  additionalProperties: false
35
58
  }]
36
59
  },
37
- defaultOptions: [{ elements: "tasty" }],
38
- create(context, [{ elements = "tasty" }]) {
39
- return jsxPropListeners(new TastyContext(context), KINDS[elements], (name, node, kind) => {
60
+ defaultOptions: [{
61
+ elements: "tasty",
62
+ values: "all"
63
+ }],
64
+ create(context, [{ elements = "tasty", values = "all" }]) {
65
+ const ctx = new TastyContext(context);
66
+ /** The style's own value: the attribute's expression or the spread key's. */
67
+ function styleValue(node) {
68
+ if (node.type === "Property") return unwrapExpression(node.value);
69
+ if (node.value?.type !== "JSXExpressionContainer") return null;
70
+ const expression = node.value.expression;
71
+ return expression.type === "JSXEmptyExpression" ? null : unwrapExpression(expression);
72
+ }
73
+ /** The object a style is written as, inline or through a local `const`. */
74
+ function styleObject(value) {
75
+ if (value?.type === "ObjectExpression") return value;
76
+ if (value?.type !== "Identifier") return null;
77
+ let scope = context.sourceCode.getScope(value);
78
+ while (scope && !scope.set.has(value.name)) scope = scope.upper;
79
+ const variable = scope?.set.get(value.name);
80
+ const def = variable?.defs.length === 1 ? variable.defs[0] : void 0;
81
+ if (def?.type !== "Variable" || def.parent.kind !== "const" || !def.node.init) return null;
82
+ const init = unwrapExpression(def.node.init);
83
+ return init.type === "ObjectExpression" ? init : null;
84
+ }
85
+ return jsxPropListeners(ctx, KINDS[elements], (name, node, kind) => {
40
86
  if (name !== "style") return;
87
+ const object = styleObject(styleValue(node));
88
+ for (const prop of object?.properties ?? []) {
89
+ if (prop.type !== "Property") continue;
90
+ const text = getStringValue(unwrapExpression(prop.value));
91
+ const word = text === null ? null : tastySyntaxWord(text, ctx.config);
92
+ if (word !== null) {
93
+ context.report({
94
+ node,
95
+ messageId: "tastySyntax",
96
+ data: { word }
97
+ });
98
+ return;
99
+ }
100
+ }
101
+ if (values === "static") {
102
+ if (object && isStaticValue(object)) context.report({
103
+ node,
104
+ messageId: "staticStyle"
105
+ });
106
+ return;
107
+ }
41
108
  context.report({
42
109
  node,
43
110
  messageId: kind === "tasty" ? "noStyleProp" : "noInlineStyle"
@@ -1 +1 @@
1
- {"version":3,"file":"no-style-prop.js","names":[],"sources":["../../src/rules/no-style-prop.ts"],"sourcesContent":["import { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport {\n type JSXElementKind,\n jsxPropListeners,\n} from './tasty-component-props.js';\n\ntype Elements = 'tasty' | 'components' | 'all';\n\nconst KINDS: Record<Elements, ReadonlySet<JSXElementKind>> = {\n tasty: new Set(['tasty']),\n components: new Set(['tasty', 'component']),\n all: new Set(['tasty', 'component', 'element']),\n};\n\nexport default createRule<\n [{ elements?: Elements }],\n 'noStyleProp' | 'noInlineStyle'\n>({\n name: 'no-style-prop',\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Prefer tokens over React inline style on Tasty components',\n },\n messages: {\n noStyleProp:\n \"Avoid the 'style' prop on Tasty components. Define styles with token references and pass dynamic values through 'tokens' (e.g. tokens={{ $size: value }}). If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.\",\n noInlineStyle:\n \"Avoid the 'style' prop. Move these styles into Tasty: render a tasty() element, or wrap the component with tasty(Component, { styles }), using token references and passing dynamic values through 'tokens'. If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.\",\n },\n schema: [\n {\n type: 'object',\n properties: {\n elements: { type: 'string', enum: ['tasty', 'components', 'all'] },\n },\n additionalProperties: false,\n },\n ],\n },\n defaultOptions: [{ elements: 'tasty' }],\n create(context, [{ elements = 'tasty' }]) {\n const ctx = new TastyContext(context);\n return jsxPropListeners(ctx, KINDS[elements], (name, node, kind) => {\n if (name !== 'style') return;\n context.report({\n node,\n messageId: kind === 'tasty' ? 'noStyleProp' : 'noInlineStyle',\n });\n });\n },\n});\n"],"mappings":";;;;;AASA,MAAM,QAAuD;CAC3D,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC;CACzB,YAAY,IAAI,IAAI,CAAC,SAAS,YAAY,CAAC;CAC3C,KAAK,IAAI,IAAI;EAAC;EAAS;EAAa;EAAU,CAAC;CAChD;AAED,4BAAe,WAGb;CACA,MAAM;CACN,MAAM;EACJ,MAAM;EACN,MAAM,EACJ,aAAa,6DACd;EACD,UAAU;GACR,aACE;GACF,eACE;GACH;EACD,QAAQ,CACN;GACE,MAAM;GACN,YAAY,EACV,UAAU;IAAE,MAAM;IAAU,MAAM;KAAC;KAAS;KAAc;KAAM;IAAE,EACnE;GACD,sBAAsB;GACvB,CACF;EACF;CACD,gBAAgB,CAAC,EAAE,UAAU,SAAS,CAAC;CACvC,OAAO,SAAS,CAAC,EAAE,WAAW,YAAY;AAExC,SAAO,iBADK,IAAI,aAAa,QAAQ,EACR,MAAM,YAAY,MAAM,MAAM,SAAS;AAClE,OAAI,SAAS,QAAS;AACtB,WAAQ,OAAO;IACb;IACA,WAAW,SAAS,UAAU,gBAAgB;IAC/C,CAAC;IACF;;CAEL,CAAC"}
1
+ {"version":3,"file":"no-style-prop.js","names":[],"sources":["../../src/rules/no-style-prop.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { BUILT_IN_UNITS, CSS_UNITS } from '../constants.js';\nimport type { ResolvedConfig } from '../types.js';\nimport {\n extractCustomUnit,\n getStringValue,\n isRawHexColor,\n isStaticValue,\n unwrapExpression,\n} from '../utils.js';\nimport { scanValueWords } from '../value-words.js';\nimport {\n type JSXElementKind,\n type JSXPropNode,\n jsxPropListeners,\n} from './tasty-component-props.js';\n\ntype Elements = 'tasty' | 'components' | 'all';\ntype Values = 'all' | 'static';\n\nconst KINDS: Record<Elements, ReadonlySet<JSXElementKind>> = {\n tasty: new Set(['tasty']),\n components: new Set(['tasty', 'component']),\n all: new Set(['tasty', 'component', 'element']),\n};\n\n/** `lh` is a Tasty unit and a CSS one, so inline CSS reads it correctly. */\nconst INLINE_CSS_UNITS = new Set([...CSS_UNITS, 'lh']);\n\n/** A word inline CSS cannot read: a Tasty unit, color token or `$` token. */\nfunction tastySyntaxWord(value: string, config: ResolvedConfig): string | null {\n for (const { value: word } of scanValueWords(value)) {\n if (/^\\$\\$?[a-z]/i.test(word)) return word;\n if (/^##?[a-z]/i.test(word) && !isRawHexColor(word)) return word;\n const unit = extractCustomUnit(word);\n if (\n unit !== null &&\n !INLINE_CSS_UNITS.has(unit) &&\n (BUILT_IN_UNITS.has(unit) ||\n (Array.isArray(config.units) && config.units.includes(unit)))\n ) {\n return word;\n }\n }\n return null;\n}\n\nexport default createRule<\n [{ elements?: Elements; values?: Values }],\n 'noStyleProp' | 'noInlineStyle' | 'staticStyle' | 'tastySyntax'\n>({\n name: 'no-style-prop',\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Prefer tokens over React inline style on Tasty components',\n },\n messages: {\n noStyleProp:\n \"Avoid the 'style' prop on Tasty components. Define styles with token references and pass dynamic values through 'tokens' (e.g. tokens={{ $size: value }}). If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.\",\n noInlineStyle:\n \"Avoid the 'style' prop. Move these styles into Tasty: render a tasty() element, or wrap the component with tasty(Component, { styles }), using token references and passing dynamic values through 'tokens'. If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.\",\n staticStyle:\n \"This 'style' is static, so it belongs in Tasty styles: style props or the component's styles on a Tasty component, a tasty() element or tasty(Component, { styles }) elsewhere. If a third-party library requires inline styles, explicitly disable tasty/no-style-prop for this usage with an ESLint comment and a reason.\",\n tastySyntax:\n \"'{{word}}' is Tasty syntax, but 'style' hands it to the browser unparsed, which drops the declaration. Move this style into Tasty styles.\",\n },\n schema: [\n {\n type: 'object',\n properties: {\n elements: { type: 'string', enum: ['tasty', 'components', 'all'] },\n values: { type: 'string', enum: ['all', 'static'] },\n },\n additionalProperties: false,\n },\n ],\n },\n defaultOptions: [{ elements: 'tasty', values: 'all' }],\n create(context, [{ elements = 'tasty', values = 'all' }]) {\n const ctx = new TastyContext(context);\n\n /** The style's own value: the attribute's expression or the spread key's. */\n function styleValue(node: JSXPropNode): TSESTree.Node | null {\n if (node.type === 'Property') return unwrapExpression(node.value);\n if (node.value?.type !== 'JSXExpressionContainer') return null;\n const expression = node.value.expression;\n return expression.type === 'JSXEmptyExpression'\n ? null\n : unwrapExpression(expression);\n }\n\n /** The object a style is written as, inline or through a local `const`. */\n function styleObject(\n value: TSESTree.Node | null,\n ): TSESTree.ObjectExpression | null {\n if (value?.type === 'ObjectExpression') return value;\n if (value?.type !== 'Identifier') return null;\n let scope: ReturnType<typeof context.sourceCode.getScope> | null =\n context.sourceCode.getScope(value);\n while (scope && !scope.set.has(value.name)) scope = scope.upper;\n const variable = scope?.set.get(value.name);\n const def = variable?.defs.length === 1 ? variable.defs[0] : undefined;\n if (\n def?.type !== 'Variable' ||\n def.parent.kind !== 'const' ||\n !def.node.init\n ) {\n return null;\n }\n const init = unwrapExpression(def.node.init);\n return init.type === 'ObjectExpression' ? init : null;\n }\n\n return jsxPropListeners(ctx, KINDS[elements], (name, node, kind) => {\n if (name !== 'style') return;\n const object = styleObject(styleValue(node));\n\n for (const prop of object?.properties ?? []) {\n if (prop.type !== 'Property') continue;\n const text = getStringValue(unwrapExpression(prop.value));\n const word = text === null ? null : tastySyntaxWord(text, ctx.config);\n if (word !== null) {\n context.report({ node, messageId: 'tastySyntax', data: { word } });\n return;\n }\n }\n\n if (values === 'static') {\n if (object && isStaticValue(object)) {\n context.report({ node, messageId: 'staticStyle' });\n }\n return;\n }\n\n context.report({\n node,\n messageId: kind === 'tasty' ? 'noStyleProp' : 'noInlineStyle',\n });\n });\n },\n});\n"],"mappings":";;;;;;;;AAsBA,MAAM,QAAuD;CAC3D,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC;CACzB,YAAY,IAAI,IAAI,CAAC,SAAS,YAAY,CAAC;CAC3C,KAAK,IAAI,IAAI;EAAC;EAAS;EAAa;EAAU,CAAC;CAChD;;AAGD,MAAM,mBAAmB,IAAI,IAAI,CAAC,GAAG,WAAW,KAAK,CAAC;;AAGtD,SAAS,gBAAgB,OAAe,QAAuC;AAC7E,MAAK,MAAM,EAAE,OAAO,UAAU,eAAe,MAAM,EAAE;AACnD,MAAI,eAAe,KAAK,KAAK,CAAE,QAAO;AACtC,MAAI,aAAa,KAAK,KAAK,IAAI,CAAC,cAAc,KAAK,CAAE,QAAO;EAC5D,MAAM,OAAO,kBAAkB,KAAK;AACpC,MACE,SAAS,QACT,CAAC,iBAAiB,IAAI,KAAK,KAC1B,eAAe,IAAI,KAAK,IACtB,MAAM,QAAQ,OAAO,MAAM,IAAI,OAAO,MAAM,SAAS,KAAK,EAE7D,QAAO;;AAGX,QAAO;;AAGT,4BAAe,WAGb;CACA,MAAM;CACN,MAAM;EACJ,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,MAAM,SAAS,YAAY,WAAW,KAAK,CAAC;AAE5C,QAAK,MAAM,QAAQ,QAAQ,cAAc,EAAE,EAAE;AAC3C,QAAI,KAAK,SAAS,WAAY;IAC9B,MAAM,OAAO,eAAe,iBAAiB,KAAK,MAAM,CAAC;IACzD,MAAM,OAAO,SAAS,OAAO,OAAO,gBAAgB,MAAM,IAAI,OAAO;AACrE,QAAI,SAAS,MAAM;AACjB,aAAQ,OAAO;MAAE;MAAM,WAAW;MAAe,MAAM,EAAE,MAAM;MAAE,CAAC;AAClE;;;AAIJ,OAAI,WAAW,UAAU;AACvB,QAAI,UAAU,cAAc,OAAO,CACjC,SAAQ,OAAO;KAAE;KAAM,WAAW;KAAe,CAAC;AAEpD;;AAGF,WAAQ,OAAO;IACb;IACA,WAAW,SAAS,UAAU,gBAAgB;IAC/C,CAAC;IACF;;CAEL,CAAC"}
package/dist/utils.js CHANGED
@@ -87,6 +87,15 @@ function isRawHexColor(value) {
87
87
  return /^[0-9a-fA-F]+$/.test(hex);
88
88
  }
89
89
  /**
90
+ * Extracts custom unit from a value token like "2x", "1.5r", "3cols".
91
+ * Returns the unit name, or null if not a custom-unit value.
92
+ */
93
+ function extractCustomUnit(token) {
94
+ const match = token.match(/^-?[\d.]+([a-zA-Z]+)$/);
95
+ if (!match) return null;
96
+ return match[1];
97
+ }
98
+ /**
90
99
  * Checks if a unit is valid (built-in, CSS, or in config).
91
100
  */
92
101
  function isValidUnit(unit, config) {
@@ -137,5 +146,5 @@ function collectLocalStateAliases(node) {
137
146
  }
138
147
 
139
148
  //#endregion
140
- export { collectLocalStateAliases, getKeyName, getStringValue, isKnownStateAlias, isRawHexColor, isStaticValue, isValidSelector, isValidUnit, unwrapExpression, validateColorTokenSyntax, valueDefinition, wildcardPattern };
149
+ export { collectLocalStateAliases, extractCustomUnit, getKeyName, getStringValue, isKnownStateAlias, isRawHexColor, isStaticValue, isValidSelector, isValidUnit, unwrapExpression, validateColorTokenSyntax, valueDefinition, wildcardPattern };
141
150
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport type { Scope } from '@typescript-eslint/utils/ts-eslint';\nimport {\n BUILT_IN_UNITS,\n CSS_UNITS,\n BUILT_IN_STATE_PREFIXES,\n} from './constants.js';\nimport type { ResolvedConfig } from './types.js';\n\n/** Strip TypeScript wrappers that do not change an expression's runtime value. */\nexport function unwrapExpression(node: TSESTree.Node): TSESTree.Node {\n let current = node;\n\n while (\n current.type === 'TSAsExpression' ||\n current.type === 'TSSatisfiesExpression' ||\n current.type === 'TSNonNullExpression' ||\n current.type === 'TSTypeAssertion' ||\n current.type === 'TSInstantiationExpression'\n ) {\n current = current.expression;\n }\n\n return current;\n}\n\n/** A whole-string pattern in which `*` matches any run of characters. */\n/**\n * A variable's one value definition. TypeScript declares a same-named type or\n * interface (`const Box = tasty(…); type Box = …`) on the same variable, so\n * type definitions are set aside; null for a redeclared or type-only name.\n */\nexport function valueDefinition(\n variable: Scope.Variable,\n): Scope.Definition | null {\n const defs = variable.defs.filter((def) => def.type !== 'Type');\n return defs.length === 1 ? defs[0] : null;\n}\n\nexport function wildcardPattern(pattern: string): RegExp {\n const escaped = pattern.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n return new RegExp(`^${escaped.replace(/\\\\\\*/g, '.*')}$`);\n}\n\n/**\n * Gets the string value of a property key node.\n */\nexport function getKeyName(key: TSESTree.Node): string | null {\n if (key.type === 'Identifier') return key.name;\n if (key.type === 'Literal' && typeof key.value === 'string') return key.value;\n if (key.type === 'Literal' && typeof key.value === 'number')\n return String(key.value);\n return null;\n}\n\n/**\n * Gets the string value of a node if it is a string literal.\n */\nexport function getStringValue(node: TSESTree.Node): string | null {\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {\n return node.quasis[0].value.cooked ?? null;\n }\n return null;\n}\n\n/**\n * Checks if a value node is a static literal.\n */\nexport function isStaticValue(node: TSESTree.Node): boolean {\n node = unwrapExpression(node);\n if (node.type === 'Literal') return true;\n if (\n node.type === 'UnaryExpression' &&\n node.operator === '-' &&\n node.argument.type === 'Literal'\n ) {\n return true;\n }\n if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {\n return true;\n }\n if (node.type === 'ArrayExpression') {\n return node.elements.every((el) => el !== null && isStaticValue(el));\n }\n if (node.type === 'ObjectExpression') {\n return node.properties.every(\n (prop) =>\n prop.type === 'Property' && !prop.computed && isStaticValue(prop.value),\n );\n }\n return false;\n}\n\n/**\n * Validates color token syntax.\n * Returns null if valid, or an error message if invalid.\n */\nexport function validateColorTokenSyntax(token: string): string | null {\n // Strip leading # or ##\n let name = token;\n if (name.startsWith('##')) {\n name = name.slice(2);\n } else if (name.startsWith('#')) {\n name = name.slice(1);\n } else {\n return 'Color token must start with #';\n }\n\n if (name.length === 0) return 'Empty color token name';\n\n // Check for opacity suffix\n const dotIndex = name.indexOf('.');\n if (dotIndex !== -1) {\n const tokenName = name.slice(0, dotIndex);\n const opacitySuffix = name.slice(dotIndex + 1);\n\n if (tokenName.length === 0) return 'Empty color token name before opacity';\n\n if (opacitySuffix.startsWith('$')) {\n // Dynamic opacity from CSS custom property — always valid\n return null;\n }\n\n if (opacitySuffix.length === 0) return 'Trailing dot with no opacity value';\n\n // Tasty reads the digits as a decimal fraction (`.5` and `.50` are 50%,\n // `.150` is 15%), so any digit string is in range.\n if (!/^\\d+$/.test(opacitySuffix)) {\n return /^-\\d+$/.test(opacitySuffix)\n ? 'Opacity cannot be negative'\n : `Invalid opacity value '${opacitySuffix}'`;\n }\n }\n\n return null;\n}\n\n/**\n * Checks if a string looks like a raw hex color (not a token).\n * Hex colors: #fff, #ffff, #ffffff, #ffffffff (3, 4, 6, or 8 hex chars).\n */\nexport function isRawHexColor(value: string): boolean {\n if (!value.startsWith('#')) return false;\n const hex = value.slice(1).split('.')[0];\n if (![3, 4, 6, 8].includes(hex.length)) return false;\n return /^[0-9a-fA-F]+$/.test(hex);\n}\n\n/**\n * Extracts custom unit from a value token like \"2x\", \"1.5r\", \"3cols\".\n * Returns the unit name, or null if not a custom-unit value.\n */\nexport function extractCustomUnit(token: string): string | null {\n const match = token.match(/^-?[\\d.]+([a-zA-Z]+)$/);\n if (!match) return null;\n return match[1];\n}\n\n/**\n * Checks if a unit is valid (built-in, CSS, or in config).\n */\nexport function isValidUnit(unit: string, config: ResolvedConfig): boolean {\n if (config.units === false) return true;\n if (BUILT_IN_UNITS.has(unit)) return true;\n if (CSS_UNITS.has(unit)) return true;\n if (Array.isArray(config.units) && config.units.includes(unit)) return true;\n return false;\n}\n\n/**\n * Checks if a state alias key (starting with @) is known.\n */\nexport function isKnownStateAlias(\n key: string,\n config: ResolvedConfig,\n): boolean {\n // Built-in prefixes\n for (const prefix of BUILT_IN_STATE_PREFIXES) {\n if (key === prefix || key.startsWith(prefix + '(')) return true;\n }\n // Container query shorthand\n if (key.startsWith('@(')) return true;\n // Config aliases\n return config.states.includes(key);\n}\n\n/**\n * Checks if a CSS selector string is basically valid.\n */\nexport function isValidSelector(selector: string): string | null {\n if (selector.length === 0) return 'Selector cannot be empty';\n\n // Check balanced brackets\n let depth = 0;\n for (const char of selector) {\n if (char === '(' || char === '[') depth++;\n if (char === ')' || char === ']') depth--;\n if (depth < 0) return 'Unbalanced brackets in selector';\n }\n if (depth !== 0) return 'Unbalanced brackets in selector';\n\n return null;\n}\n\n/**\n * Finds a property by key name in an object expression.\n */\nexport function findProperty(\n obj: TSESTree.ObjectExpression,\n name: string,\n): TSESTree.Property | undefined {\n for (const prop of obj.properties) {\n if (prop.type === 'Property' && !prop.computed) {\n const keyName = getKeyName(prop.key);\n if (keyName === name) return prop;\n }\n }\n return undefined;\n}\n\n/**\n * Collects local predefined state alias names from a styles ObjectExpression.\n * Local states are top-level `@name` keys with string literal values,\n * mirroring the runtime's `extractLocalPredefinedStates()`.\n */\nexport function collectLocalStateAliases(\n node: TSESTree.ObjectExpression,\n): string[] {\n const aliases: string[] = [];\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n\n const key = getKeyName(prop.key);\n if (key === null) continue;\n if (!/^@[A-Za-z][A-Za-z0-9-]*$/.test(key)) continue;\n\n // Skip built-in prefixes — they are not local state definitions\n if (BUILT_IN_STATE_PREFIXES.has(key)) continue;\n\n // Must have a string value to be a state definition\n if (getStringValue(prop.value) !== null) {\n aliases.push(key);\n }\n }\n\n return aliases;\n}\n"],"mappings":";;;;AAUA,SAAgB,iBAAiB,MAAoC;CACnE,IAAI,UAAU;AAEd,QACE,QAAQ,SAAS,oBACjB,QAAQ,SAAS,2BACjB,QAAQ,SAAS,yBACjB,QAAQ,SAAS,qBACjB,QAAQ,SAAS,4BAEjB,WAAU,QAAQ;AAGpB,QAAO;;;;;;;;AAST,SAAgB,gBACd,UACyB;CACzB,MAAM,OAAO,SAAS,KAAK,QAAQ,QAAQ,IAAI,SAAS,OAAO;AAC/D,QAAO,KAAK,WAAW,IAAI,KAAK,KAAK;;AAGvC,SAAgB,gBAAgB,SAAyB;CACvD,MAAM,UAAU,QAAQ,QAAQ,uBAAuB,OAAO;AAE9D,QAAO,IAAI,OAAO,IAAI,QAAQ,QAAQ,SAAS,KAAK,CAAC,GAAG;;;;;AAM1D,SAAgB,WAAW,KAAmC;AAC5D,KAAI,IAAI,SAAS,aAAc,QAAO,IAAI;AAC1C,KAAI,IAAI,SAAS,aAAa,OAAO,IAAI,UAAU,SAAU,QAAO,IAAI;AACxE,KAAI,IAAI,SAAS,aAAa,OAAO,IAAI,UAAU,SACjD,QAAO,OAAO,IAAI,MAAM;AAC1B,QAAO;;;;;AAMT,SAAgB,eAAe,MAAoC;AACjE,KAAI,KAAK,SAAS,aAAa,OAAO,KAAK,UAAU,SACnD,QAAO,KAAK;AAEd,KAAI,KAAK,SAAS,qBAAqB,KAAK,YAAY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
+ {"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport type { Scope } from '@typescript-eslint/utils/ts-eslint';\nimport {\n BUILT_IN_UNITS,\n CSS_UNITS,\n BUILT_IN_STATE_PREFIXES,\n} from './constants.js';\nimport type { ResolvedConfig } from './types.js';\n\n/** Strip TypeScript wrappers that do not change an expression's runtime value. */\nexport function unwrapExpression(node: TSESTree.Node): TSESTree.Node {\n let current = node;\n\n while (\n current.type === 'TSAsExpression' ||\n current.type === 'TSSatisfiesExpression' ||\n current.type === 'TSNonNullExpression' ||\n current.type === 'TSTypeAssertion' ||\n current.type === 'TSInstantiationExpression'\n ) {\n current = current.expression;\n }\n\n return current;\n}\n\n/** A whole-string pattern in which `*` matches any run of characters. */\n/**\n * A variable's one value definition. TypeScript declares a same-named type or\n * interface (`const Box = tasty(…); type Box = …`) on the same variable, so\n * type definitions are set aside; null for a redeclared or type-only name.\n */\nexport function valueDefinition(\n variable: Scope.Variable,\n): Scope.Definition | null {\n const defs = variable.defs.filter((def) => def.type !== 'Type');\n return defs.length === 1 ? defs[0] : null;\n}\n\nexport function wildcardPattern(pattern: string): RegExp {\n const escaped = pattern.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n return new RegExp(`^${escaped.replace(/\\\\\\*/g, '.*')}$`);\n}\n\n/**\n * Gets the string value of a property key node.\n */\nexport function getKeyName(key: TSESTree.Node): string | null {\n if (key.type === 'Identifier') return key.name;\n if (key.type === 'Literal' && typeof key.value === 'string') return key.value;\n if (key.type === 'Literal' && typeof key.value === 'number')\n return String(key.value);\n return null;\n}\n\n/**\n * Gets the string value of a node if it is a string literal.\n */\nexport function getStringValue(node: TSESTree.Node): string | null {\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {\n return node.quasis[0].value.cooked ?? null;\n }\n return null;\n}\n\n/**\n * Checks if a value node is a static literal.\n */\nexport function isStaticValue(node: TSESTree.Node): boolean {\n node = unwrapExpression(node);\n if (node.type === 'Literal') return true;\n if (\n node.type === 'UnaryExpression' &&\n node.operator === '-' &&\n node.argument.type === 'Literal'\n ) {\n return true;\n }\n if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {\n return true;\n }\n if (node.type === 'ArrayExpression') {\n return node.elements.every((el) => el !== null && isStaticValue(el));\n }\n if (node.type === 'ObjectExpression') {\n return node.properties.every(\n (prop) =>\n prop.type === 'Property' && !prop.computed && isStaticValue(prop.value),\n );\n }\n return false;\n}\n\n/**\n * Validates color token syntax.\n * Returns null if valid, or an error message if invalid.\n */\nexport function validateColorTokenSyntax(token: string): string | null {\n // Strip leading # or ##\n let name = token;\n if (name.startsWith('##')) {\n name = name.slice(2);\n } else if (name.startsWith('#')) {\n name = name.slice(1);\n } else {\n return 'Color token must start with #';\n }\n\n if (name.length === 0) return 'Empty color token name';\n\n // Check for opacity suffix\n const dotIndex = name.indexOf('.');\n if (dotIndex !== -1) {\n const tokenName = name.slice(0, dotIndex);\n const opacitySuffix = name.slice(dotIndex + 1);\n\n if (tokenName.length === 0) return 'Empty color token name before opacity';\n\n if (opacitySuffix.startsWith('$')) {\n // Dynamic opacity from CSS custom property — always valid\n return null;\n }\n\n if (opacitySuffix.length === 0) return 'Trailing dot with no opacity value';\n\n // Tasty reads the digits as a decimal fraction (`.5` and `.50` are 50%,\n // `.150` is 15%), so any digit string is in range.\n if (!/^\\d+$/.test(opacitySuffix)) {\n return /^-\\d+$/.test(opacitySuffix)\n ? 'Opacity cannot be negative'\n : `Invalid opacity value '${opacitySuffix}'`;\n }\n }\n\n return null;\n}\n\n/**\n * Checks if a string looks like a raw hex color (not a token).\n * Hex colors: #fff, #ffff, #ffffff, #ffffffff (3, 4, 6, or 8 hex chars).\n */\nexport function isRawHexColor(value: string): boolean {\n if (!value.startsWith('#')) return false;\n const hex = value.slice(1).split('.')[0];\n if (![3, 4, 6, 8].includes(hex.length)) return false;\n return /^[0-9a-fA-F]+$/.test(hex);\n}\n\n/**\n * Extracts custom unit from a value token like \"2x\", \"1.5r\", \"3cols\".\n * Returns the unit name, or null if not a custom-unit value.\n */\nexport function extractCustomUnit(token: string): string | null {\n const match = token.match(/^-?[\\d.]+([a-zA-Z]+)$/);\n if (!match) return null;\n return match[1];\n}\n\n/**\n * Checks if a unit is valid (built-in, CSS, or in config).\n */\nexport function isValidUnit(unit: string, config: ResolvedConfig): boolean {\n if (config.units === false) return true;\n if (BUILT_IN_UNITS.has(unit)) return true;\n if (CSS_UNITS.has(unit)) return true;\n if (Array.isArray(config.units) && config.units.includes(unit)) return true;\n return false;\n}\n\n/**\n * Checks if a state alias key (starting with @) is known.\n */\nexport function isKnownStateAlias(\n key: string,\n config: ResolvedConfig,\n): boolean {\n // Built-in prefixes\n for (const prefix of BUILT_IN_STATE_PREFIXES) {\n if (key === prefix || key.startsWith(prefix + '(')) return true;\n }\n // Container query shorthand\n if (key.startsWith('@(')) return true;\n // Config aliases\n return config.states.includes(key);\n}\n\n/**\n * Checks if a CSS selector string is basically valid.\n */\nexport function isValidSelector(selector: string): string | null {\n if (selector.length === 0) return 'Selector cannot be empty';\n\n // Check balanced brackets\n let depth = 0;\n for (const char of selector) {\n if (char === '(' || char === '[') depth++;\n if (char === ')' || char === ']') depth--;\n if (depth < 0) return 'Unbalanced brackets in selector';\n }\n if (depth !== 0) return 'Unbalanced brackets in selector';\n\n return null;\n}\n\n/**\n * Finds a property by key name in an object expression.\n */\nexport function findProperty(\n obj: TSESTree.ObjectExpression,\n name: string,\n): TSESTree.Property | undefined {\n for (const prop of obj.properties) {\n if (prop.type === 'Property' && !prop.computed) {\n const keyName = getKeyName(prop.key);\n if (keyName === name) return prop;\n }\n }\n return undefined;\n}\n\n/**\n * Collects local predefined state alias names from a styles ObjectExpression.\n * Local states are top-level `@name` keys with string literal values,\n * mirroring the runtime's `extractLocalPredefinedStates()`.\n */\nexport function collectLocalStateAliases(\n node: TSESTree.ObjectExpression,\n): string[] {\n const aliases: string[] = [];\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n\n const key = getKeyName(prop.key);\n if (key === null) continue;\n if (!/^@[A-Za-z][A-Za-z0-9-]*$/.test(key)) continue;\n\n // Skip built-in prefixes — they are not local state definitions\n if (BUILT_IN_STATE_PREFIXES.has(key)) continue;\n\n // Must have a string value to be a state definition\n if (getStringValue(prop.value) !== null) {\n aliases.push(key);\n }\n }\n\n return aliases;\n}\n"],"mappings":";;;;AAUA,SAAgB,iBAAiB,MAAoC;CACnE,IAAI,UAAU;AAEd,QACE,QAAQ,SAAS,oBACjB,QAAQ,SAAS,2BACjB,QAAQ,SAAS,yBACjB,QAAQ,SAAS,qBACjB,QAAQ,SAAS,4BAEjB,WAAU,QAAQ;AAGpB,QAAO;;;;;;;;AAST,SAAgB,gBACd,UACyB;CACzB,MAAM,OAAO,SAAS,KAAK,QAAQ,QAAQ,IAAI,SAAS,OAAO;AAC/D,QAAO,KAAK,WAAW,IAAI,KAAK,KAAK;;AAGvC,SAAgB,gBAAgB,SAAyB;CACvD,MAAM,UAAU,QAAQ,QAAQ,uBAAuB,OAAO;AAE9D,QAAO,IAAI,OAAO,IAAI,QAAQ,QAAQ,SAAS,KAAK,CAAC,GAAG;;;;;AAM1D,SAAgB,WAAW,KAAmC;AAC5D,KAAI,IAAI,SAAS,aAAc,QAAO,IAAI;AAC1C,KAAI,IAAI,SAAS,aAAa,OAAO,IAAI,UAAU,SAAU,QAAO,IAAI;AACxE,KAAI,IAAI,SAAS,aAAa,OAAO,IAAI,UAAU,SACjD,QAAO,OAAO,IAAI,MAAM;AAC1B,QAAO;;;;;AAMT,SAAgB,eAAe,MAAoC;AACjE,KAAI,KAAK,SAAS,aAAa,OAAO,KAAK,UAAU,SACnD,QAAO,KAAK;AAEd,KAAI,KAAK,SAAS,qBAAqB,KAAK,YAAY,WAAW,EACjE,QAAO,KAAK,OAAO,GAAG,MAAM,UAAU;AAExC,QAAO;;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AAK,MAAM,KAAK,KACjC,SAAQ,KAAK,IAAI;;AAIrB,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/eslint-plugin-tasty",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "ESLint plugin for validating tasty() and tastyStatic() style objects",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,7 +53,7 @@
53
53
  "@changesets/changelog-github": "^0.5.2",
54
54
  "@changesets/cli": "^2.31.1",
55
55
  "@eslint/js": "^10.0.1",
56
- "@tenphi/tasty": "^3.16.0",
56
+ "@tenphi/tasty": "^3.17.1",
57
57
  "@types/node": "^22.0.0",
58
58
  "@types/semver": "^7.8.0",
59
59
  "@typescript-eslint/parser": "^8.56.1",