@tenphi/eslint-plugin-tasty 1.6.0 → 1.7.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 +73 -2
- package/dist/context.js +7 -0
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js.map +1 -1
- package/dist/rules/valid-color-token.js +4 -6
- package/dist/rules/valid-color-token.js.map +1 -1
- package/dist/rules/valid-custom-property.js +4 -6
- package/dist/rules/valid-custom-property.js.map +1 -1
- package/dist/style-values.js +19 -11
- package/dist/style-values.js.map +1 -1
- package/dist/type-aware-jsx.d.ts +9 -0
- package/dist/type-aware-jsx.js +275 -0
- package/dist/type-aware-jsx.js.map +1 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -388,8 +388,79 @@ Individual props are detected by name: a known Tasty or CSS property, or an entr
|
|
|
388
388
|
in `config.styles`, on an uppercase component or member tag (`<UI.Box>`). This is
|
|
389
389
|
a heuristic, so an unrelated component with a matching non-style prop can need a
|
|
390
390
|
rule suppression. Native HTML/SVG attributes and React's singular `style` prop
|
|
391
|
-
are excluded. Bindings, calls, spreads, and interpolated templates are not evaluated
|
|
392
|
-
these checks do not require
|
|
391
|
+
are excluded. Bindings, calls, spreads, and interpolated templates are not evaluated.
|
|
392
|
+
By default, these checks do not require TypeScript type services.
|
|
393
|
+
|
|
394
|
+
### Experimental type-aware JSX props
|
|
395
|
+
|
|
396
|
+
Opt into type analysis to distinguish semantic component props from style props.
|
|
397
|
+
Install TypeScript 5.6–5.9 as a dev dependency, then add the same setting to either
|
|
398
|
+
ESLint or Oxlint:
|
|
399
|
+
|
|
400
|
+
```js
|
|
401
|
+
settings: {
|
|
402
|
+
tasty: {
|
|
403
|
+
typeAwareJSX: true,
|
|
404
|
+
// Or: typeAwareJSX: { project: './tsconfig.json' },
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
`true` finds the nearest `tsconfig.json` above the linted file. An explicit
|
|
410
|
+
`project` path resolves relative to the linter's working directory. Use the
|
|
411
|
+
project that includes your source files, rather than a solution config that
|
|
412
|
+
only references other projects. The setting belongs in the **linter config**,
|
|
413
|
+
not `tasty.config.*`. Set it to `false` or omit it to keep the existing behavior.
|
|
414
|
+
|
|
415
|
+
The resolver uses JSX's contextual prop type and follows property declarations:
|
|
416
|
+
|
|
417
|
+
- Props inherited or picked from Tasty's `Styles` remain validated, including
|
|
418
|
+
indexed aliases such as `Styles['gap']` and explicit `StyleValue` types.
|
|
419
|
+
- Declared component props such as `position: 'before' | 'after'` or
|
|
420
|
+
`prefix: ReactNode` are excluded from JSX value checks.
|
|
421
|
+
- Missing components, unresolved types, `any`, generics, index signatures,
|
|
422
|
+
excluded files, and broad primitive types retain the existing name heuristic.
|
|
423
|
+
If a union combines a style declaration and a semantic declaration, the style
|
|
424
|
+
check takes precedence.
|
|
425
|
+
|
|
426
|
+
For example, `<TabDropIndicator position="after" />` no longer needs an ignore
|
|
427
|
+
when its prop is declared as `'before' | 'after'`. `<Box position="after" />`
|
|
428
|
+
still reports an error when `Box` inherits Tasty's positioning props. Style
|
|
429
|
+
objects continue to be checked regardless of this setting.
|
|
430
|
+
|
|
431
|
+
This is declaration-based classification, not a proof of what a component does
|
|
432
|
+
at runtime. A manually narrowed style prop must retain its Tasty type origin,
|
|
433
|
+
for example `position?: Styles['position']`, to avoid being treated as semantic.
|
|
434
|
+
Custom style wrappers that erase that origin need further work. Unresolved Tasty
|
|
435
|
+
types leave all checks on; the project must load Tasty's declarations through
|
|
436
|
+
its imports. Invalid project configuration or missing TypeScript produces an
|
|
437
|
+
error when a candidate JSX prop has a visible value to check.
|
|
438
|
+
|
|
439
|
+
The resolver creates its **own TypeScript program** inside the JS plugin. It
|
|
440
|
+
works with Oxlint without `--type-aware` and does not access Oxlint's Go checker
|
|
441
|
+
or ESLint parser services. TypeScript loads only when enabled. Value rules share
|
|
442
|
+
the program and per-file classification; at most three projects are retained
|
|
443
|
+
per process. Current lint-buffer text is used, and changes to loaded source
|
|
444
|
+
files or compiler configs invalidate the cache. Newly linted files are discovered;
|
|
445
|
+
restart the linter after dependency installation or changes to otherwise
|
|
446
|
+
unreferenced files. Other unsaved editor buffers are read from disk.
|
|
447
|
+
|
|
448
|
+
Expect compiler startup time and memory costs, especially on a large project.
|
|
449
|
+
The implementation checks loaded file timestamps once per lint traversal.
|
|
450
|
+
Changing the active unsaved buffer rebuilds the program while reusing unchanged
|
|
451
|
+
parsed files. Opaque values such as bindings and calls do not trigger analysis.
|
|
452
|
+
This mode is experimental and disabled in both presets.
|
|
453
|
+
|
|
454
|
+
Local validation against UI Kit's `TabButton.tsx` and `Item.stories.tsx` removed
|
|
455
|
+
the two ordering-prop and eight content-prop collisions. Oxlint reported their
|
|
456
|
+
ten ignore directives as unused while retaining the same eighteen other style
|
|
457
|
+
diagnostics. A fresh process checking these two files with three value rules
|
|
458
|
+
took about 0.82 seconds without analysis and 6.55 seconds with it on the test
|
|
459
|
+
machine (TypeScript 5.9.3, Oxlint 1.83.0). Reusing parsed files reduced switching
|
|
460
|
+
changed lint buffers from about 4.0 seconds to 0.35 seconds in a separate local
|
|
461
|
+
test retaining the full 1,386-file compiler graph. Cold CLI startup still creates
|
|
462
|
+
and binds that graph. These are local measurements, not a whole-project benchmark
|
|
463
|
+
or a performance guarantee.
|
|
393
464
|
|
|
394
465
|
Automatic `var()` / `calc()` rewrites and Tasty semantic transition advice need
|
|
395
466
|
additional component evidence: a local `const` created by an imported `tasty()` or
|
package/dist/context.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_IMPORT_SOURCES, KNOWN_CSS_PROPERTIES, KNOWN_TASTY_PROPERTIES, SPECIAL_STYLE_KEYS } from "./constants.js";
|
|
2
2
|
import { loadConfig } from "./config.js";
|
|
3
3
|
import { getKeyName, unwrapExpression } from "./utils.js";
|
|
4
|
+
import { finishJSXAnalysis, jsxPropKind } from "./type-aware-jsx.js";
|
|
4
5
|
|
|
5
6
|
//#region src/context.ts
|
|
6
7
|
/** One listener per object; context recognition remains the caller's gate. */
|
|
@@ -146,6 +147,12 @@ var TastyContext = class {
|
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
isComponentJSXProp(node) {
|
|
151
|
+
return jsxPropKind(this.context, node) === "component";
|
|
152
|
+
}
|
|
153
|
+
finishJSXAnalysis() {
|
|
154
|
+
finishJSXAnalysis(this.context);
|
|
155
|
+
}
|
|
149
156
|
getImport(localName) {
|
|
150
157
|
return this.imports.get(localName);
|
|
151
158
|
}
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport type { RuleContext } from '@typescript-eslint/utils/ts-eslint';\nimport type { ResolvedConfig, StyleFunctionConfig } from './types.js';\nimport { loadConfig } from './config.js';\nimport {\n DEFAULT_IMPORT_SOURCES,\n KNOWN_CSS_PROPERTIES,\n KNOWN_TASTY_PROPERTIES,\n SPECIAL_STYLE_KEYS,\n} from './constants.js';\nimport { getKeyName, unwrapExpression } from './utils.js';\n\n/**\n * Every object is considered, then TastyContext gates it by its actual context.\n * Narrow ancestry selectors miss nested shared styles and wrapped JSX values.\n */\nexport const STYLE_OBJECT_SELECTORS = ['ObjectExpression'] as const;\n\n/** One listener per object; context recognition remains the caller's gate. */\nexport function styleObjectListeners(\n handler: (node: TSESTree.ObjectExpression) => void,\n): Record<string, (node: TSESTree.ObjectExpression) => void> {\n return { ObjectExpression: handler };\n}\n\nexport interface StyleContext {\n type: 'tasty' | 'tastyStatic' | 'useStyles' | 'useGlobalStyles';\n isStaticCall: boolean;\n isSelectorMode: boolean;\n isExtending: boolean;\n /**\n * Local name of the component this layer extends, when there is one and it is\n * an identifier. `null` covers every other case — a base definition, a\n * selector, or a layer whose base cannot be read off the AST — so a rule that\n * cares must treat `null` as \"unknown\", not as \"not extending\".\n */\n baseComponent: string | null;\n}\n\nexport interface TastyImport {\n localName: string;\n importedName: string;\n source: string;\n}\n\n/**\n * Whether a type annotation names tasty's `Styles` anywhere inside it.\n *\n * Walks the annotation rather than matching only the outermost reference, so a\n * wrapped tasty type (`Styles | undefined`, `Record<string, Styles>`,\n * `{ root: Styles }`) is recognised while `CSSProperties` in the same positions is\n * not. Deliberately name-based: the plugin has no type checker, and requiring one\n * would make every rule type-aware.\n */\nfunction referencesStylesType(node: TSESTree.TypeNode): boolean {\n const stack: TSESTree.Node[] = [node];\n\n while (stack.length) {\n const current = stack.pop()!;\n\n if (\n current.type === 'TSTypeReference' &&\n current.typeName.type === 'Identifier' &&\n /^Styles$/i.test(current.typeName.name)\n ) {\n return true;\n }\n\n for (const value of Object.values(\n current as unknown as Record<string, unknown>,\n )) {\n if (Array.isArray(value)) {\n for (const item of value) {\n if (item && typeof item === 'object' && 'type' in item) {\n stack.push(item as TSESTree.Node);\n }\n }\n } else if (value && typeof value === 'object' && 'type' in value) {\n // Skip `parent` — it points back up the tree and would loop forever.\n if (value !== (current as TSESTree.Node).parent) {\n stack.push(value as TSESTree.Node);\n }\n }\n }\n }\n\n return false;\n}\n\n/**\n * Whether a key could plausibly be a tasty style key.\n *\n * Covers every top-level shape tasty accepts: a style property, a sub-element\n * (capitalised), an at-rule or state/custom-property/colour key (`@`, `&`, `$`,\n * `#`), and the default-state key.\n */\nfunction isPlausibleStyleKey(key: string): boolean {\n if (key === '' || key === '_') return true;\n if (/^[A-Z]/.test(key)) return true;\n if (/^[@&$#]/.test(key)) return true;\n if (SPECIAL_STYLE_KEYS.has(key)) return true;\n\n return KNOWN_TASTY_PROPERTIES.has(key) || KNOWN_CSS_PROPERTIES.has(key);\n}\n\n/**\n * Whether an object is a map of named CSS blocks rather than a tasty styles object.\n *\n * The shape is unmistakable — `{ table: {…}, th: {…}, td: {…} }`, `{ root: {…},\n * toolbar: {…} }` — and it is what a React inline-style map looks like when it\n * carries no type annotation to opt it out. Every key is a block name that is not a\n * style key, and every value is an object.\n *\n * Requiring *every* value to be an object literal is what keeps this from swallowing\n * the case it would hurt most: `const styles = { colour: 'red' }` has a string value,\n * so it is not treated as a block map and `known-property` still reports the typo.\n * Otherwise the rule that catches a misspelled property would be silenced by the\n * misspelling.\n */\nfunction isNamedCssBlockMap(node: TSESTree.ObjectExpression): boolean {\n if (node.properties.length === 0) return false;\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) return false;\n\n const key = getKeyName(prop.key);\n\n if (key === null || isPlausibleStyleKey(key)) return false;\n if (prop.value.type !== 'ObjectExpression') return false;\n }\n\n return true;\n}\n\n/**\n * The component a `styles` JSX prop overrides — `<Card styles={…} />` -> `Card`.\n * A namespaced tag (`<UI.Card />`) resolves to its root object, since that is the\n * name an import can be matched against.\n */\nfunction jsxStylesPropTarget(node: TSESTree.ObjectExpression): string | null {\n let wrapped: TSESTree.Node = node;\n while (wrapped.parent && unwrapExpression(wrapped.parent) === node) {\n wrapped = wrapped.parent;\n }\n const container = wrapped.parent;\n if (container?.type !== 'JSXExpressionContainer') return null;\n\n const attribute = container.parent;\n if (attribute?.type !== 'JSXAttribute') return null;\n\n const element = attribute.parent;\n if (element?.type !== 'JSXOpeningElement') return null;\n\n let name: TSESTree.JSXTagNameExpression = element.name;\n while (name.type === 'JSXMemberExpression') name = name.object;\n\n return name.type === 'JSXIdentifier' ? name.name : null;\n}\n\n/**\n * The identifier a base-component argument resolves to — `tasty(UI.Card, {…})`\n * -> `UI`, which is what the import map is keyed by.\n *\n * Type assertions are stripped on the way down. Reading `Button as any` as an\n * unknown base would quietly promote an imported component to \"owned\", which is\n * the reading that produces a warning the author cannot act on.\n */\nfunction baseComponentName(node: TSESTree.Node): string | null {\n let current = unwrapExpression(node);\n\n while (current.type === 'MemberExpression') {\n current = unwrapExpression(current.object);\n }\n\n return current.type === 'Identifier' ? current.name : null;\n}\n\n/**\n * Whether `source` is inside this project. Relative and absolute specifiers are,\n * as are the conventional in-repo aliases (`~/`, `#internal`, `@/`) — `@` alone\n * is not, since `@scope/pkg` is a published package.\n */\nfunction isInRepoSource(source: string): boolean {\n return (\n source.startsWith('.') ||\n source.startsWith('/') ||\n source.startsWith('~') ||\n source.startsWith('#') ||\n source.startsWith('@/')\n );\n}\n\n/** Matches a source against an `ownedSources` pattern, where `*` is any run of characters. */\nfunction matchesSourcePattern(pattern: string, source: string): boolean {\n const escaped = pattern.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n return new RegExp(`^${escaped.replace(/\\\\\\*/g, '.*')}$`).test(source);\n}\n\nconst TASTY_FUNCTION_NAMES = new Set([\n 'tasty',\n 'tastyStatic',\n 'useStyles',\n 'useGlobalStyles',\n 'configure',\n]);\n\n/**\n * Context tracker for a single file's lint pass.\n * Tracks which imports come from tasty and provides\n * helpers to determine if a node is in a tasty style context.\n */\nexport class TastyContext {\n readonly config: ResolvedConfig;\n private imports = new Map<string, TastyImport>();\n private moduleSources = new Map<string, string>();\n private importSources: Set<string>;\n\n constructor(\n private context: RuleContext<string, unknown[]>,\n config?: ResolvedConfig,\n ) {\n this.config = config ?? loadConfig(context.filename);\n this.importSources = new Set([\n ...DEFAULT_IMPORT_SOURCES,\n ...this.config.importSources,\n ]);\n }\n\n trackImport(node: TSESTree.ImportDeclaration): void {\n const source = node.source.value;\n\n // Every import is recorded, tasty or not. Where a *base component* comes\n // from is what tells a rule whether the file it would send the author to\n // edit is even theirs — see `isOwnedComponent`.\n for (const specifier of node.specifiers) {\n this.moduleSources.set(specifier.local.name, source);\n }\n\n if (!this.importSources.has(source) || node.importKind === 'type') return;\n\n for (const specifier of node.specifiers) {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.importKind !== 'type'\n ) {\n const importedName =\n specifier.imported.type === 'Identifier'\n ? specifier.imported.name\n : specifier.imported.value;\n if (\n TASTY_FUNCTION_NAMES.has(importedName) ||\n Object.hasOwn(this.config.styleFunctions ?? {}, importedName)\n ) {\n this.imports.set(specifier.local.name, {\n localName: specifier.local.name,\n importedName,\n source,\n });\n }\n }\n }\n }\n\n getImport(localName: string): TastyImport | undefined {\n return this.imports.get(localName);\n }\n\n /**\n * Whether the base component an extension layer sits on top of lives in a file\n * this project can edit — so a rule can decide whether pointing the author at\n * the base's own definition is advice they can act on.\n *\n * A name that was never imported is declared in this very file, and an unknown\n * base (`null`) counts as owned as well: staying quiet is for a base that is\n * demonstrably someone else's, never for one the plugin merely failed to read.\n */\n isOwnedComponent(localName: string | null): boolean {\n if (localName === null) return true;\n\n const source = this.moduleSources.get(localName);\n if (source === undefined) return true;\n if (isInRepoSource(source)) return true;\n\n // `ownedSources` is optional on the public `ResolvedConfig`, so a config\n // built by a consumer rather than by `loadConfig` may not carry it.\n return (this.config.ownedSources ?? []).some((pattern) =>\n matchesSourcePattern(pattern, source),\n );\n }\n\n isTastyCall(node: TSESTree.CallExpression): TastyImport | undefined {\n const callee = unwrapExpression(node.callee);\n if (callee.type !== 'Identifier') return undefined;\n const imp = this.imports.get(callee.name);\n if (!imp) return undefined;\n\n // A parameter or local declaration can shadow the imported helper. Only\n // the import binding carries evidence that the call accepts Tasty styles.\n let scope = this.context.sourceCode.getScope(callee);\n while (scope) {\n const variable = scope.set.get(callee.name);\n if (variable) {\n return variable.defs.some((def) => def.type === 'ImportBinding')\n ? imp\n : undefined;\n }\n if (!scope.upper) break;\n scope = scope.upper;\n }\n return undefined;\n }\n\n /** Local factory results, const aliases, and configured component imports. */\n isTastyJSXComponent(node: TSESTree.Node, name: string): boolean {\n const visited = new Set<TSESTree.VariableDeclarator>();\n const resolve = (reference: TSESTree.Node, localName: string): boolean => {\n let scope = this.context.sourceCode.getScope(reference);\n while (scope) {\n const variable = scope.set.get(localName);\n if (variable) {\n return variable.defs.some((def) => {\n if (def.type === 'ImportBinding') {\n return (\n def.parent.type === 'ImportDeclaration' &&\n def.parent.importKind !== 'type' &&\n this.importSources.has(def.parent.source.value) &&\n (def.node.type !== 'ImportSpecifier' ||\n def.node.importKind !== 'type')\n );\n }\n if (def.type !== 'Variable') return false;\n const declaration = def.node;\n if (\n declaration.id.type !== 'Identifier' ||\n declaration.parent.kind !== 'const' ||\n !declaration.init ||\n visited.has(declaration)\n )\n return false;\n visited.add(declaration);\n const init = unwrapExpression(declaration.init);\n if (init.type === 'Identifier') return resolve(init, init.name);\n if (init.type === 'MemberExpression' && !init.computed) {\n let member: TSESTree.Node = init;\n while (member.type === 'MemberExpression') {\n if (member.computed) return false;\n member = unwrapExpression(member.object);\n }\n const root = baseComponentName(init);\n return root !== null && resolve(init, root);\n }\n if (init.type !== 'CallExpression') return false;\n const imp = this.isTastyCall(init);\n return (\n imp?.importedName === 'tasty' ||\n (imp !== undefined &&\n this.config.styleFunctions?.[imp.importedName]?.kind ===\n 'options')\n );\n });\n }\n if (!scope.upper) break;\n scope = scope.upper;\n }\n return false;\n };\n return resolve(node, name);\n }\n\n /**\n * Determines whether an object expression is a tasty style object\n * by walking up the AST to find a recognized call expression.\n */\n isStyleObject(node: TSESTree.ObjectExpression): boolean {\n return this.getStyleContext(node) !== null;\n }\n\n private getSubElementParent(\n node: TSESTree.ObjectExpression,\n ): TSESTree.ObjectExpression | null {\n let wrapped: TSESTree.Node = node;\n while (wrapped.parent && unwrapExpression(wrapped.parent) === node) {\n wrapped = wrapped.parent;\n }\n const parent = wrapped.parent;\n if (parent?.type !== 'Property' || parent.computed) return null;\n const key = getKeyName(parent.key);\n return key &&\n /^[A-Z]/.test(key) &&\n parent.parent.type === 'ObjectExpression'\n ? parent.parent\n : null;\n }\n\n /** Follow only sub-elements of recognized styles, never a variants container. */\n getRootStyleObject(\n node: TSESTree.ObjectExpression,\n ): TSESTree.ObjectExpression {\n let current = node;\n while (true) {\n const parent = this.getSubElementParent(current);\n if (!parent || !this.isStyleObject(parent)) return current;\n current = parent;\n }\n }\n\n /** Include helper calls nested inside a real sub-element, but not variant names. */\n isInsideSubElement(node: TSESTree.Node): boolean {\n let current = node.parent;\n while (current) {\n if (current.type === 'Property' && !current.computed) {\n const key = getKeyName(current.key);\n if (\n key &&\n /^[A-Z]/.test(key) &&\n current.parent.type === 'ObjectExpression' &&\n this.isStyleObject(current.parent)\n ) {\n return true;\n }\n }\n current = current.parent;\n }\n return false;\n }\n\n getStyleContext(node: TSESTree.Node): StyleContext | null {\n // Sub-element objects inherit their parent style object's context\n if (node.type === 'ObjectExpression') {\n const parent = this.getSubElementParent(node);\n if (parent) {\n const inherited = this.getStyleContext(parent);\n if (inherited) return inherited;\n }\n }\n\n // An object assigned to a `styles` key (or a `styles` JSX prop) is a style\n // object on its own terms — no enclosing tasty call or `styles`-ish variable\n // name required. Checked before the walk, which would otherwise climb past it\n // to an unrelated call or declaration and reject the whole thing.\n if (node.type === 'ObjectExpression' && this.isStylesPropertyValue(node)) {\n // A `styles` prop is an override layer by construction: the component it\n // is handed to already carries its own styles and this object lands on\n // top of them. A Storybook `args.styles` is the same prop by another name,\n // but the component behind `args` is not on the AST path, so its base\n // stays unknown.\n return {\n type: 'tasty',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: true,\n baseComponent: jsxStylesPropTarget(node),\n };\n }\n\n let current: TSESTree.Node | undefined = node;\n\n while (current) {\n if (current.type === 'CallExpression') {\n const imp = this.isTastyCall(current);\n if (!imp) return null;\n\n const name = imp.importedName;\n const isStaticCall = name === 'tastyStatic';\n\n if (name === 'tasty') {\n return this.getTastyCallContext(current, node);\n }\n\n if (name === 'tastyStatic') {\n return this.getTastyStaticCallContext(current, node);\n }\n\n if (name === 'useStyles') {\n if (current.arguments[0] === node) {\n return {\n type: 'useStyles',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n }\n\n if (name === 'useGlobalStyles') {\n if (current.arguments[1] === node) {\n return {\n type: 'useGlobalStyles',\n isStaticCall,\n isSelectorMode: true,\n isExtending: false,\n baseComponent: null,\n };\n }\n }\n\n // Built-in signatures always take precedence over configured ones.\n const custom = this.config.styleFunctions?.[name];\n if (!TASTY_FUNCTION_NAMES.has(name) && custom) {\n return this.getCustomCallContext(current, node, custom);\n }\n\n return null;\n }\n\n if (this.isStyleVariableDeclaration(current, node)) {\n return {\n type: 'tasty',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n\n current = current.parent;\n }\n\n return null;\n }\n\n private isStyleVariableDeclaration(\n current: TSESTree.Node,\n targetNode: TSESTree.Node,\n ): boolean {\n if (\n current.type !== 'VariableDeclarator' ||\n current.id.type !== 'Identifier'\n ) {\n return false;\n }\n\n let init: TSESTree.Node | null | undefined = current.init;\n while (\n init?.type === 'TSAsExpression' ||\n init?.type === 'TSSatisfiesExpression' ||\n init?.type === 'TSTypeAssertion' ||\n init?.type === 'TSNonNullExpression'\n ) {\n init = (init as TSESTree.TSAsExpression).expression;\n }\n\n if (init !== targetNode) return false;\n\n const name = current.id.name;\n\n if (/^[A-Z][A-Z0-9_]*$/.test(name)) return false;\n\n // An explicit type annotation is authoritative, in both directions. The name\n // heuristic below is a guess; a declared type is the author stating what the\n // object is, so it wins.\n //\n // This matters because the rewrites these rules offer are only valid *inside*\n // tasty: `#purple.05` and `$font-sans` are correct tasty declarations and\n // meaningless as raw CSS. A `const styles: Record<string, CSSProperties>`\n // handed to React's `style={…}` was matched on name alone, so its plain CSS\n // longhands were reported as tasty violations — and `--fix` rewrote real\n // `var(--shadow-sm-color)` to `#shadow-sm`, which nothing resolves there, so\n // the browser dropped the declaration.\n const annotated = this.stylesTypeAnnotation(current);\n\n if (annotated !== null) return annotated;\n\n // Only `styles` and `*Styles` count. The singular `style` is conventionally\n // a DOM inline-style object (`el.style`, `CSSProperties`, `setStyle(el, …)`)\n // holding raw CSS longhands, not tasty syntax — matching it reported those\n // longhands as tasty violations.\n if (name === 'styles' || name.endsWith('Styles')) {\n // The name is the weakest evidence there is, so let an unmistakable shape\n // overrule it. Without an annotation to go on, a map of named CSS blocks was\n // reported as tasty — `known-property` on every HTML tag name, each block read\n // as a state map — and `--fix` offered rewrites that are only valid inside\n // tasty.\n return !(\n targetNode.type === 'ObjectExpression' && isNamedCssBlockMap(targetNode)\n );\n }\n\n return false;\n }\n\n private getCustomCallContext(\n call: TSESTree.CallExpression,\n targetNode: TSESTree.Node,\n config: StyleFunctionConfig,\n ): StyleContext | null {\n const { argument, kind } = config;\n if (argument !== 'all' && (!Number.isInteger(argument) || argument < 0)) {\n return null;\n }\n // A preceding spread makes the runtime argument index unknown. Never apply\n // style rewrites to an object that might occupy a different parameter.\n if (\n argument !== 'all' &&\n call.arguments\n .slice(0, argument)\n .some((arg) => arg.type === 'SpreadElement')\n ) {\n return null;\n }\n\n const args =\n argument === 'all' ? call.arguments : [call.arguments[argument]];\n for (const arg of args) {\n if (!arg) continue;\n const value = unwrapExpression(arg);\n if (value.type !== 'ObjectExpression') continue;\n\n const isVariant =\n kind === 'options' && this.isInsideVariantsProperty(value, targetNode);\n const matches =\n kind === 'styles'\n ? value === targetNode\n : kind === 'options' &&\n (this.isInsideStylesProperty(value, targetNode) || isVariant);\n\n if (matches) {\n return {\n type: 'tasty',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: !isVariant && (config.partial ?? false),\n baseComponent: null,\n };\n }\n }\n\n return null;\n }\n\n /**\n * Verdict from the declared type: `true` tasty, `false` explicitly not, `null`\n * when there is no annotation to go on and the caller should fall back to the\n * name.\n *\n * A `Styles` reference anywhere in the annotation counts, so wrappers like\n * `Styles | undefined` and `Record<string, Styles>` opt in — while\n * `CSSProperties`, `Record<string, CSSProperties>` and an inline literal of\n * them opt out.\n */\n private stylesTypeAnnotation(\n node: TSESTree.VariableDeclarator,\n ): boolean | null {\n const annotation = node.id.typeAnnotation?.typeAnnotation;\n\n if (!annotation) return null;\n\n return referencesStylesType(annotation);\n }\n\n private getTastyCallContext(\n call: TSESTree.CallExpression,\n targetNode: TSESTree.Node,\n ) {\n const args = call.arguments;\n\n // tasty({ styles: { ... } }) or tasty(Component, { styles: { ... } })\n const isExtending =\n args.length >= 2 && unwrapExpression(args[0]).type !== 'ObjectExpression';\n const optionsArg = isExtending ? args[1] : args[0];\n\n if (\n optionsArg?.type === 'ObjectExpression' &&\n this.isInsideStylesProperty(optionsArg, targetNode)\n ) {\n return {\n type: 'tasty' as const,\n isStaticCall: false,\n isSelectorMode: false,\n isExtending,\n baseComponent: isExtending ? baseComponentName(args[0]) : null,\n };\n }\n\n // Check if inside variants\n if (\n optionsArg?.type === 'ObjectExpression' &&\n this.isInsideVariantsProperty(optionsArg, targetNode)\n ) {\n return {\n type: 'tasty' as const,\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n\n return null;\n }\n\n private getTastyStaticCallContext(\n call: TSESTree.CallExpression,\n targetNode: TSESTree.Node,\n ) {\n const args = call.arguments;\n\n // tastyStatic({ ... })\n if (args.length === 1 && args[0] === targetNode) {\n return {\n type: 'tastyStatic' as const,\n isStaticCall: true,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n\n // tastyStatic(base, { ... }) or tastyStatic('selector', { ... })\n if (args.length === 2 && args[1] === targetNode) {\n const isSelectorMode = unwrapExpression(args[0]).type === 'Literal';\n return {\n type: 'tastyStatic' as const,\n isStaticCall: true,\n isSelectorMode,\n isExtending: !isSelectorMode,\n baseComponent: isSelectorMode ? null : baseComponentName(args[0]),\n };\n }\n\n return null;\n }\n\n private isInsideStylesProperty(\n optionsObj: TSESTree.ObjectExpression,\n targetNode: TSESTree.Node,\n ): boolean {\n for (const prop of optionsObj.properties) {\n if (\n prop.type === 'Property' &&\n !prop.computed &&\n getKeyName(prop.key) === 'styles' &&\n unwrapExpression(prop.value) === targetNode\n ) {\n return true;\n }\n }\n return false;\n }\n\n private isInsideVariantsProperty(\n optionsObj: TSESTree.ObjectExpression,\n targetNode: TSESTree.Node,\n ): boolean {\n for (const prop of optionsObj.properties) {\n if (\n prop.type === 'Property' &&\n !prop.computed &&\n getKeyName(prop.key) === 'variants'\n ) {\n const variants = unwrapExpression(prop.value);\n if (variants.type !== 'ObjectExpression') continue;\n for (const variantProp of variants.properties) {\n if (\n variantProp.type === 'Property' &&\n unwrapExpression(variantProp.value) === targetNode\n ) {\n return true;\n }\n }\n }\n }\n return false;\n }\n\n /**\n * Whether this object is a `styles` JSX prop value or a Storybook `args.styles`.\n *\n * Both are unambiguous enough to stand on their own without an import-tracked\n * call or a `styles`-ish variable name. A bare `styles` key elsewhere is not —\n * see the selector list for why.\n */\n isStylesPropertyValue(node: TSESTree.ObjectExpression): boolean {\n let wrapped: TSESTree.Node = node;\n while (wrapped.parent && unwrapExpression(wrapped.parent) === node) {\n wrapped = wrapped.parent;\n }\n const parent = wrapped.parent;\n\n if (parent?.type === 'Property' && !parent.computed) {\n if (getKeyName(parent.key) !== 'styles') return false;\n\n // Only inside `args: { … }`.\n const argsObject = parent.parent;\n const argsProperty =\n argsObject?.type === 'ObjectExpression' ? argsObject.parent : undefined;\n\n return (\n argsProperty?.type === 'Property' &&\n !argsProperty.computed &&\n getKeyName(argsProperty.key) === 'args'\n );\n }\n\n if (parent?.type === 'JSXExpressionContainer') {\n const attribute = parent.parent;\n\n return (\n attribute?.type === 'JSXAttribute' &&\n attribute.name.type === 'JSXIdentifier' &&\n (attribute.name.name === 'styles' ||\n attribute.name.name.endsWith('Styles'))\n );\n }\n\n return false;\n }\n\n /**\n * Checks if a property value node is a state mapping object\n * (i.e., an object where keys are state expressions and values are style values).\n */\n isStateMap(\n node: TSESTree.ObjectExpression,\n parentProperty: TSESTree.Property,\n ): boolean {\n const keyName = getKeyName(parentProperty.key);\n if (keyName === null) return false;\n\n // If the key starts with uppercase, it's a sub-element, not a state map\n if (/^[A-Z]/.test(keyName)) return false;\n\n // Special keys are not state maps\n // At-rule blocks are not state maps — their object values are descriptor maps.\n if (SPECIAL_STYLE_KEYS.has(keyName)) return false;\n\n // If the object has keys that look like state expressions, it's a state map.\n // A lone `_` (the fallback floor) or `''` (the default) is enough — both are\n // already covered by the string-literal / identifier branches below.\n return node.properties.some((prop) => {\n if (prop.type !== 'Property') return false;\n if (prop.key.type === 'Literal' && prop.key.value === '') return true;\n if (prop.key.type === 'Identifier') return true;\n if (prop.key.type === 'Literal' && typeof prop.key.value === 'string') {\n return true;\n }\n return false;\n });\n }\n\n /**\n * Checks if a key represents a sub-element (starts with uppercase).\n */\n isSubElementKey(key: string): boolean {\n return /^[A-Z]/.test(key);\n }\n\n /**\n * Checks if a key represents a nested selector (starts with &).\n */\n isNestedSelectorKey(key: string): boolean {\n return key.startsWith('&');\n }\n\n /**\n * Checks if a key is a custom CSS property definition ($name or $$name).\n */\n isCustomPropertyKey(key: string): boolean {\n return key.startsWith('$');\n }\n\n /**\n * Checks if a key is a color token definition (#name or ##name).\n */\n isColorTokenKey(key: string): boolean {\n return key.startsWith('#');\n }\n\n /**\n * Checks if a key is a special @ property (@keyframes, @property, ...).\n */\n isSpecialKey(key: string): boolean {\n return key.startsWith('@');\n }\n}\n"],"mappings":";;;;;;AAmBA,SAAgB,qBACd,SAC2D;AAC3D,QAAO,EAAE,kBAAkB,SAAS;;;;;;;;;;;AAgCtC,SAAS,qBAAqB,MAAkC;CAC9D,MAAM,QAAyB,CAAC,KAAK;AAErC,QAAO,MAAM,QAAQ;EACnB,MAAM,UAAU,MAAM,KAAK;AAE3B,MACE,QAAQ,SAAS,qBACjB,QAAQ,SAAS,SAAS,gBAC1B,YAAY,KAAK,QAAQ,SAAS,KAAK,CAEvC,QAAO;AAGT,OAAK,MAAM,SAAS,OAAO,OACzB,QACD,CACC,KAAI,MAAM,QAAQ,MAAM,EACtB;QAAK,MAAM,QAAQ,MACjB,KAAI,QAAQ,OAAO,SAAS,YAAY,UAAU,KAChD,OAAM,KAAK,KAAsB;aAG5B,SAAS,OAAO,UAAU,YAAY,UAAU,OAEzD;OAAI,UAAW,QAA0B,OACvC,OAAM,KAAK,MAAuB;;;AAM1C,QAAO;;;;;;;;;AAUT,SAAS,oBAAoB,KAAsB;AACjD,KAAI,QAAQ,MAAM,QAAQ,IAAK,QAA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S;AACpC,OAAI,KAAK,SAAS,WAAY,QAAO;AACrC,OAAI,KAAK,IAAI,SAAS,aAAa,KAAK,IAAI,UAAU,GAAI,QAAO;AACjE,OAAI,KAAK,IAAI,SAAS,aAAc,QAAO;AAC3C,OAAI,KAAK,IAAI,SAAS,aAAa,OAAO,KAAK,IAAI,UAAU,SAC3D,QAAO;AAET,UAAO;IACP;;;;;CAMJ,gBAAgB,KAAsB;AACpC,SAAO,SAAS,KAAK,IAAI;;;;;CAM3B,oBAAoB,KAAsB;AACxC,SAAO,IAAI,WAAW,IAAI;;;;;CAM5B,oBAAoB,KAAsB;AACxC,SAAO,IAAI,WAAW,IAAI;;;;;CAM5B,gBAAgB,KAAsB;AACpC,SAAO,IAAI,WAAW,IAAI;;;;;CAM5B,aAAa,KAAsB;AACjC,SAAO,IAAI,WAAW,IAAI"}
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport type { RuleContext } from '@typescript-eslint/utils/ts-eslint';\nimport type { ResolvedConfig, StyleFunctionConfig } from './types.js';\nimport { loadConfig } from './config.js';\nimport {\n DEFAULT_IMPORT_SOURCES,\n KNOWN_CSS_PROPERTIES,\n KNOWN_TASTY_PROPERTIES,\n SPECIAL_STYLE_KEYS,\n} from './constants.js';\nimport { getKeyName, unwrapExpression } from './utils.js';\nimport { finishJSXAnalysis, jsxPropKind } from './type-aware-jsx.js';\n\n/**\n * Every object is considered, then TastyContext gates it by its actual context.\n * Narrow ancestry selectors miss nested shared styles and wrapped JSX values.\n */\nexport const STYLE_OBJECT_SELECTORS = ['ObjectExpression'] as const;\n\n/** One listener per object; context recognition remains the caller's gate. */\nexport function styleObjectListeners(\n handler: (node: TSESTree.ObjectExpression) => void,\n): Record<string, (node: TSESTree.ObjectExpression) => void> {\n return { ObjectExpression: handler };\n}\n\nexport interface StyleContext {\n type: 'tasty' | 'tastyStatic' | 'useStyles' | 'useGlobalStyles';\n isStaticCall: boolean;\n isSelectorMode: boolean;\n isExtending: boolean;\n /**\n * Local name of the component this layer extends, when there is one and it is\n * an identifier. `null` covers every other case — a base definition, a\n * selector, or a layer whose base cannot be read off the AST — so a rule that\n * cares must treat `null` as \"unknown\", not as \"not extending\".\n */\n baseComponent: string | null;\n}\n\nexport interface TastyImport {\n localName: string;\n importedName: string;\n source: string;\n}\n\n/**\n * Whether a type annotation names tasty's `Styles` anywhere inside it.\n *\n * Walks the annotation rather than matching only the outermost reference, so a\n * wrapped tasty type (`Styles | undefined`, `Record<string, Styles>`,\n * `{ root: Styles }`) is recognised while `CSSProperties` in the same positions is\n * not. Deliberately name-based: the plugin has no type checker, and requiring one\n * would make every rule type-aware.\n */\nfunction referencesStylesType(node: TSESTree.TypeNode): boolean {\n const stack: TSESTree.Node[] = [node];\n\n while (stack.length) {\n const current = stack.pop()!;\n\n if (\n current.type === 'TSTypeReference' &&\n current.typeName.type === 'Identifier' &&\n /^Styles$/i.test(current.typeName.name)\n ) {\n return true;\n }\n\n for (const value of Object.values(\n current as unknown as Record<string, unknown>,\n )) {\n if (Array.isArray(value)) {\n for (const item of value) {\n if (item && typeof item === 'object' && 'type' in item) {\n stack.push(item as TSESTree.Node);\n }\n }\n } else if (value && typeof value === 'object' && 'type' in value) {\n // Skip `parent` — it points back up the tree and would loop forever.\n if (value !== (current as TSESTree.Node).parent) {\n stack.push(value as TSESTree.Node);\n }\n }\n }\n }\n\n return false;\n}\n\n/**\n * Whether a key could plausibly be a tasty style key.\n *\n * Covers every top-level shape tasty accepts: a style property, a sub-element\n * (capitalised), an at-rule or state/custom-property/colour key (`@`, `&`, `$`,\n * `#`), and the default-state key.\n */\nfunction isPlausibleStyleKey(key: string): boolean {\n if (key === '' || key === '_') return true;\n if (/^[A-Z]/.test(key)) return true;\n if (/^[@&$#]/.test(key)) return true;\n if (SPECIAL_STYLE_KEYS.has(key)) return true;\n\n return KNOWN_TASTY_PROPERTIES.has(key) || KNOWN_CSS_PROPERTIES.has(key);\n}\n\n/**\n * Whether an object is a map of named CSS blocks rather than a tasty styles object.\n *\n * The shape is unmistakable — `{ table: {…}, th: {…}, td: {…} }`, `{ root: {…},\n * toolbar: {…} }` — and it is what a React inline-style map looks like when it\n * carries no type annotation to opt it out. Every key is a block name that is not a\n * style key, and every value is an object.\n *\n * Requiring *every* value to be an object literal is what keeps this from swallowing\n * the case it would hurt most: `const styles = { colour: 'red' }` has a string value,\n * so it is not treated as a block map and `known-property` still reports the typo.\n * Otherwise the rule that catches a misspelled property would be silenced by the\n * misspelling.\n */\nfunction isNamedCssBlockMap(node: TSESTree.ObjectExpression): boolean {\n if (node.properties.length === 0) return false;\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) return false;\n\n const key = getKeyName(prop.key);\n\n if (key === null || isPlausibleStyleKey(key)) return false;\n if (prop.value.type !== 'ObjectExpression') return false;\n }\n\n return true;\n}\n\n/**\n * The component a `styles` JSX prop overrides — `<Card styles={…} />` -> `Card`.\n * A namespaced tag (`<UI.Card />`) resolves to its root object, since that is the\n * name an import can be matched against.\n */\nfunction jsxStylesPropTarget(node: TSESTree.ObjectExpression): string | null {\n let wrapped: TSESTree.Node = node;\n while (wrapped.parent && unwrapExpression(wrapped.parent) === node) {\n wrapped = wrapped.parent;\n }\n const container = wrapped.parent;\n if (container?.type !== 'JSXExpressionContainer') return null;\n\n const attribute = container.parent;\n if (attribute?.type !== 'JSXAttribute') return null;\n\n const element = attribute.parent;\n if (element?.type !== 'JSXOpeningElement') return null;\n\n let name: TSESTree.JSXTagNameExpression = element.name;\n while (name.type === 'JSXMemberExpression') name = name.object;\n\n return name.type === 'JSXIdentifier' ? name.name : null;\n}\n\n/**\n * The identifier a base-component argument resolves to — `tasty(UI.Card, {…})`\n * -> `UI`, which is what the import map is keyed by.\n *\n * Type assertions are stripped on the way down. Reading `Button as any` as an\n * unknown base would quietly promote an imported component to \"owned\", which is\n * the reading that produces a warning the author cannot act on.\n */\nfunction baseComponentName(node: TSESTree.Node): string | null {\n let current = unwrapExpression(node);\n\n while (current.type === 'MemberExpression') {\n current = unwrapExpression(current.object);\n }\n\n return current.type === 'Identifier' ? current.name : null;\n}\n\n/**\n * Whether `source` is inside this project. Relative and absolute specifiers are,\n * as are the conventional in-repo aliases (`~/`, `#internal`, `@/`) — `@` alone\n * is not, since `@scope/pkg` is a published package.\n */\nfunction isInRepoSource(source: string): boolean {\n return (\n source.startsWith('.') ||\n source.startsWith('/') ||\n source.startsWith('~') ||\n source.startsWith('#') ||\n source.startsWith('@/')\n );\n}\n\n/** Matches a source against an `ownedSources` pattern, where `*` is any run of characters. */\nfunction matchesSourcePattern(pattern: string, source: string): boolean {\n const escaped = pattern.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n return new RegExp(`^${escaped.replace(/\\\\\\*/g, '.*')}$`).test(source);\n}\n\nconst TASTY_FUNCTION_NAMES = new Set([\n 'tasty',\n 'tastyStatic',\n 'useStyles',\n 'useGlobalStyles',\n 'configure',\n]);\n\n/**\n * Context tracker for a single file's lint pass.\n * Tracks which imports come from tasty and provides\n * helpers to determine if a node is in a tasty style context.\n */\nexport class TastyContext {\n readonly config: ResolvedConfig;\n private imports = new Map<string, TastyImport>();\n private moduleSources = new Map<string, string>();\n private importSources: Set<string>;\n\n constructor(\n private context: RuleContext<string, unknown[]>,\n config?: ResolvedConfig,\n ) {\n this.config = config ?? loadConfig(context.filename);\n this.importSources = new Set([\n ...DEFAULT_IMPORT_SOURCES,\n ...this.config.importSources,\n ]);\n }\n\n trackImport(node: TSESTree.ImportDeclaration): void {\n const source = node.source.value;\n\n // Every import is recorded, tasty or not. Where a *base component* comes\n // from is what tells a rule whether the file it would send the author to\n // edit is even theirs — see `isOwnedComponent`.\n for (const specifier of node.specifiers) {\n this.moduleSources.set(specifier.local.name, source);\n }\n\n if (!this.importSources.has(source) || node.importKind === 'type') return;\n\n for (const specifier of node.specifiers) {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.importKind !== 'type'\n ) {\n const importedName =\n specifier.imported.type === 'Identifier'\n ? specifier.imported.name\n : specifier.imported.value;\n if (\n TASTY_FUNCTION_NAMES.has(importedName) ||\n Object.hasOwn(this.config.styleFunctions ?? {}, importedName)\n ) {\n this.imports.set(specifier.local.name, {\n localName: specifier.local.name,\n importedName,\n source,\n });\n }\n }\n }\n }\n\n isComponentJSXProp(node: TSESTree.JSXAttribute): boolean {\n return jsxPropKind(this.context, node) === 'component';\n }\n\n finishJSXAnalysis(): void {\n finishJSXAnalysis(this.context);\n }\n\n getImport(localName: string): TastyImport | undefined {\n return this.imports.get(localName);\n }\n\n /**\n * Whether the base component an extension layer sits on top of lives in a file\n * this project can edit — so a rule can decide whether pointing the author at\n * the base's own definition is advice they can act on.\n *\n * A name that was never imported is declared in this very file, and an unknown\n * base (`null`) counts as owned as well: staying quiet is for a base that is\n * demonstrably someone else's, never for one the plugin merely failed to read.\n */\n isOwnedComponent(localName: string | null): boolean {\n if (localName === null) return true;\n\n const source = this.moduleSources.get(localName);\n if (source === undefined) return true;\n if (isInRepoSource(source)) return true;\n\n // `ownedSources` is optional on the public `ResolvedConfig`, so a config\n // built by a consumer rather than by `loadConfig` may not carry it.\n return (this.config.ownedSources ?? []).some((pattern) =>\n matchesSourcePattern(pattern, source),\n );\n }\n\n isTastyCall(node: TSESTree.CallExpression): TastyImport | undefined {\n const callee = unwrapExpression(node.callee);\n if (callee.type !== 'Identifier') return undefined;\n const imp = this.imports.get(callee.name);\n if (!imp) return undefined;\n\n // A parameter or local declaration can shadow the imported helper. Only\n // the import binding carries evidence that the call accepts Tasty styles.\n let scope = this.context.sourceCode.getScope(callee);\n while (scope) {\n const variable = scope.set.get(callee.name);\n if (variable) {\n return variable.defs.some((def) => def.type === 'ImportBinding')\n ? imp\n : undefined;\n }\n if (!scope.upper) break;\n scope = scope.upper;\n }\n return undefined;\n }\n\n /** Local factory results, const aliases, and configured component imports. */\n isTastyJSXComponent(node: TSESTree.Node, name: string): boolean {\n const visited = new Set<TSESTree.VariableDeclarator>();\n const resolve = (reference: TSESTree.Node, localName: string): boolean => {\n let scope = this.context.sourceCode.getScope(reference);\n while (scope) {\n const variable = scope.set.get(localName);\n if (variable) {\n return variable.defs.some((def) => {\n if (def.type === 'ImportBinding') {\n return (\n def.parent.type === 'ImportDeclaration' &&\n def.parent.importKind !== 'type' &&\n this.importSources.has(def.parent.source.value) &&\n (def.node.type !== 'ImportSpecifier' ||\n def.node.importKind !== 'type')\n );\n }\n if (def.type !== 'Variable') return false;\n const declaration = def.node;\n if (\n declaration.id.type !== 'Identifier' ||\n declaration.parent.kind !== 'const' ||\n !declaration.init ||\n visited.has(declaration)\n )\n return false;\n visited.add(declaration);\n const init = unwrapExpression(declaration.init);\n if (init.type === 'Identifier') return resolve(init, init.name);\n if (init.type === 'MemberExpression' && !init.computed) {\n let member: TSESTree.Node = init;\n while (member.type === 'MemberExpression') {\n if (member.computed) return false;\n member = unwrapExpression(member.object);\n }\n const root = baseComponentName(init);\n return root !== null && resolve(init, root);\n }\n if (init.type !== 'CallExpression') return false;\n const imp = this.isTastyCall(init);\n return (\n imp?.importedName === 'tasty' ||\n (imp !== undefined &&\n this.config.styleFunctions?.[imp.importedName]?.kind ===\n 'options')\n );\n });\n }\n if (!scope.upper) break;\n scope = scope.upper;\n }\n return false;\n };\n return resolve(node, name);\n }\n\n /**\n * Determines whether an object expression is a tasty style object\n * by walking up the AST to find a recognized call expression.\n */\n isStyleObject(node: TSESTree.ObjectExpression): boolean {\n return this.getStyleContext(node) !== null;\n }\n\n private getSubElementParent(\n node: TSESTree.ObjectExpression,\n ): TSESTree.ObjectExpression | null {\n let wrapped: TSESTree.Node = node;\n while (wrapped.parent && unwrapExpression(wrapped.parent) === node) {\n wrapped = wrapped.parent;\n }\n const parent = wrapped.parent;\n if (parent?.type !== 'Property' || parent.computed) return null;\n const key = getKeyName(parent.key);\n return key &&\n /^[A-Z]/.test(key) &&\n parent.parent.type === 'ObjectExpression'\n ? parent.parent\n : null;\n }\n\n /** Follow only sub-elements of recognized styles, never a variants container. */\n getRootStyleObject(\n node: TSESTree.ObjectExpression,\n ): TSESTree.ObjectExpression {\n let current = node;\n while (true) {\n const parent = this.getSubElementParent(current);\n if (!parent || !this.isStyleObject(parent)) return current;\n current = parent;\n }\n }\n\n /** Include helper calls nested inside a real sub-element, but not variant names. */\n isInsideSubElement(node: TSESTree.Node): boolean {\n let current = node.parent;\n while (current) {\n if (current.type === 'Property' && !current.computed) {\n const key = getKeyName(current.key);\n if (\n key &&\n /^[A-Z]/.test(key) &&\n current.parent.type === 'ObjectExpression' &&\n this.isStyleObject(current.parent)\n ) {\n return true;\n }\n }\n current = current.parent;\n }\n return false;\n }\n\n getStyleContext(node: TSESTree.Node): StyleContext | null {\n // Sub-element objects inherit their parent style object's context\n if (node.type === 'ObjectExpression') {\n const parent = this.getSubElementParent(node);\n if (parent) {\n const inherited = this.getStyleContext(parent);\n if (inherited) return inherited;\n }\n }\n\n // An object assigned to a `styles` key (or a `styles` JSX prop) is a style\n // object on its own terms — no enclosing tasty call or `styles`-ish variable\n // name required. Checked before the walk, which would otherwise climb past it\n // to an unrelated call or declaration and reject the whole thing.\n if (node.type === 'ObjectExpression' && this.isStylesPropertyValue(node)) {\n // A `styles` prop is an override layer by construction: the component it\n // is handed to already carries its own styles and this object lands on\n // top of them. A Storybook `args.styles` is the same prop by another name,\n // but the component behind `args` is not on the AST path, so its base\n // stays unknown.\n return {\n type: 'tasty',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: true,\n baseComponent: jsxStylesPropTarget(node),\n };\n }\n\n let current: TSESTree.Node | undefined = node;\n\n while (current) {\n if (current.type === 'CallExpression') {\n const imp = this.isTastyCall(current);\n if (!imp) return null;\n\n const name = imp.importedName;\n const isStaticCall = name === 'tastyStatic';\n\n if (name === 'tasty') {\n return this.getTastyCallContext(current, node);\n }\n\n if (name === 'tastyStatic') {\n return this.getTastyStaticCallContext(current, node);\n }\n\n if (name === 'useStyles') {\n if (current.arguments[0] === node) {\n return {\n type: 'useStyles',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n }\n\n if (name === 'useGlobalStyles') {\n if (current.arguments[1] === node) {\n return {\n type: 'useGlobalStyles',\n isStaticCall,\n isSelectorMode: true,\n isExtending: false,\n baseComponent: null,\n };\n }\n }\n\n // Built-in signatures always take precedence over configured ones.\n const custom = this.config.styleFunctions?.[name];\n if (!TASTY_FUNCTION_NAMES.has(name) && custom) {\n return this.getCustomCallContext(current, node, custom);\n }\n\n return null;\n }\n\n if (this.isStyleVariableDeclaration(current, node)) {\n return {\n type: 'tasty',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n\n current = current.parent;\n }\n\n return null;\n }\n\n private isStyleVariableDeclaration(\n current: TSESTree.Node,\n targetNode: TSESTree.Node,\n ): boolean {\n if (\n current.type !== 'VariableDeclarator' ||\n current.id.type !== 'Identifier'\n ) {\n return false;\n }\n\n let init: TSESTree.Node | null | undefined = current.init;\n while (\n init?.type === 'TSAsExpression' ||\n init?.type === 'TSSatisfiesExpression' ||\n init?.type === 'TSTypeAssertion' ||\n init?.type === 'TSNonNullExpression'\n ) {\n init = (init as TSESTree.TSAsExpression).expression;\n }\n\n if (init !== targetNode) return false;\n\n const name = current.id.name;\n\n if (/^[A-Z][A-Z0-9_]*$/.test(name)) return false;\n\n // An explicit type annotation is authoritative, in both directions. The name\n // heuristic below is a guess; a declared type is the author stating what the\n // object is, so it wins.\n //\n // This matters because the rewrites these rules offer are only valid *inside*\n // tasty: `#purple.05` and `$font-sans` are correct tasty declarations and\n // meaningless as raw CSS. A `const styles: Record<string, CSSProperties>`\n // handed to React's `style={…}` was matched on name alone, so its plain CSS\n // longhands were reported as tasty violations — and `--fix` rewrote real\n // `var(--shadow-sm-color)` to `#shadow-sm`, which nothing resolves there, so\n // the browser dropped the declaration.\n const annotated = this.stylesTypeAnnotation(current);\n\n if (annotated !== null) return annotated;\n\n // Only `styles` and `*Styles` count. The singular `style` is conventionally\n // a DOM inline-style object (`el.style`, `CSSProperties`, `setStyle(el, …)`)\n // holding raw CSS longhands, not tasty syntax — matching it reported those\n // longhands as tasty violations.\n if (name === 'styles' || name.endsWith('Styles')) {\n // The name is the weakest evidence there is, so let an unmistakable shape\n // overrule it. Without an annotation to go on, a map of named CSS blocks was\n // reported as tasty — `known-property` on every HTML tag name, each block read\n // as a state map — and `--fix` offered rewrites that are only valid inside\n // tasty.\n return !(\n targetNode.type === 'ObjectExpression' && isNamedCssBlockMap(targetNode)\n );\n }\n\n return false;\n }\n\n private getCustomCallContext(\n call: TSESTree.CallExpression,\n targetNode: TSESTree.Node,\n config: StyleFunctionConfig,\n ): StyleContext | null {\n const { argument, kind } = config;\n if (argument !== 'all' && (!Number.isInteger(argument) || argument < 0)) {\n return null;\n }\n // A preceding spread makes the runtime argument index unknown. Never apply\n // style rewrites to an object that might occupy a different parameter.\n if (\n argument !== 'all' &&\n call.arguments\n .slice(0, argument)\n .some((arg) => arg.type === 'SpreadElement')\n ) {\n return null;\n }\n\n const args =\n argument === 'all' ? call.arguments : [call.arguments[argument]];\n for (const arg of args) {\n if (!arg) continue;\n const value = unwrapExpression(arg);\n if (value.type !== 'ObjectExpression') continue;\n\n const isVariant =\n kind === 'options' && this.isInsideVariantsProperty(value, targetNode);\n const matches =\n kind === 'styles'\n ? value === targetNode\n : kind === 'options' &&\n (this.isInsideStylesProperty(value, targetNode) || isVariant);\n\n if (matches) {\n return {\n type: 'tasty',\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: !isVariant && (config.partial ?? false),\n baseComponent: null,\n };\n }\n }\n\n return null;\n }\n\n /**\n * Verdict from the declared type: `true` tasty, `false` explicitly not, `null`\n * when there is no annotation to go on and the caller should fall back to the\n * name.\n *\n * A `Styles` reference anywhere in the annotation counts, so wrappers like\n * `Styles | undefined` and `Record<string, Styles>` opt in — while\n * `CSSProperties`, `Record<string, CSSProperties>` and an inline literal of\n * them opt out.\n */\n private stylesTypeAnnotation(\n node: TSESTree.VariableDeclarator,\n ): boolean | null {\n const annotation = node.id.typeAnnotation?.typeAnnotation;\n\n if (!annotation) return null;\n\n return referencesStylesType(annotation);\n }\n\n private getTastyCallContext(\n call: TSESTree.CallExpression,\n targetNode: TSESTree.Node,\n ) {\n const args = call.arguments;\n\n // tasty({ styles: { ... } }) or tasty(Component, { styles: { ... } })\n const isExtending =\n args.length >= 2 && unwrapExpression(args[0]).type !== 'ObjectExpression';\n const optionsArg = isExtending ? args[1] : args[0];\n\n if (\n optionsArg?.type === 'ObjectExpression' &&\n this.isInsideStylesProperty(optionsArg, targetNode)\n ) {\n return {\n type: 'tasty' as const,\n isStaticCall: false,\n isSelectorMode: false,\n isExtending,\n baseComponent: isExtending ? baseComponentName(args[0]) : null,\n };\n }\n\n // Check if inside variants\n if (\n optionsArg?.type === 'ObjectExpression' &&\n this.isInsideVariantsProperty(optionsArg, targetNode)\n ) {\n return {\n type: 'tasty' as const,\n isStaticCall: false,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n\n return null;\n }\n\n private getTastyStaticCallContext(\n call: TSESTree.CallExpression,\n targetNode: TSESTree.Node,\n ) {\n const args = call.arguments;\n\n // tastyStatic({ ... })\n if (args.length === 1 && args[0] === targetNode) {\n return {\n type: 'tastyStatic' as const,\n isStaticCall: true,\n isSelectorMode: false,\n isExtending: false,\n baseComponent: null,\n };\n }\n\n // tastyStatic(base, { ... }) or tastyStatic('selector', { ... })\n if (args.length === 2 && args[1] === targetNode) {\n const isSelectorMode = unwrapExpression(args[0]).type === 'Literal';\n return {\n type: 'tastyStatic' as const,\n isStaticCall: true,\n isSelectorMode,\n isExtending: !isSelectorMode,\n baseComponent: isSelectorMode ? null : baseComponentName(args[0]),\n };\n }\n\n return null;\n }\n\n private isInsideStylesProperty(\n optionsObj: TSESTree.ObjectExpression,\n targetNode: TSESTree.Node,\n ): boolean {\n for (const prop of optionsObj.properties) {\n if (\n prop.type === 'Property' &&\n !prop.computed &&\n getKeyName(prop.key) === 'styles' &&\n unwrapExpression(prop.value) === targetNode\n ) {\n return true;\n }\n }\n return false;\n }\n\n private isInsideVariantsProperty(\n optionsObj: TSESTree.ObjectExpression,\n targetNode: TSESTree.Node,\n ): boolean {\n for (const prop of optionsObj.properties) {\n if (\n prop.type === 'Property' &&\n !prop.computed &&\n getKeyName(prop.key) === 'variants'\n ) {\n const variants = unwrapExpression(prop.value);\n if (variants.type !== 'ObjectExpression') continue;\n for (const variantProp of variants.properties) {\n if (\n variantProp.type === 'Property' &&\n unwrapExpression(variantProp.value) === targetNode\n ) {\n return true;\n }\n }\n }\n }\n return false;\n }\n\n /**\n * Whether this object is a `styles` JSX prop value or a Storybook `args.styles`.\n *\n * Both are unambiguous enough to stand on their own without an import-tracked\n * call or a `styles`-ish variable name. A bare `styles` key elsewhere is not —\n * see the selector list for why.\n */\n isStylesPropertyValue(node: TSESTree.ObjectExpression): boolean {\n let wrapped: TSESTree.Node = node;\n while (wrapped.parent && unwrapExpression(wrapped.parent) === node) {\n wrapped = wrapped.parent;\n }\n const parent = wrapped.parent;\n\n if (parent?.type === 'Property' && !parent.computed) {\n if (getKeyName(parent.key) !== 'styles') return false;\n\n // Only inside `args: { … }`.\n const argsObject = parent.parent;\n const argsProperty =\n argsObject?.type === 'ObjectExpression' ? argsObject.parent : undefined;\n\n return (\n argsProperty?.type === 'Property' &&\n !argsProperty.computed &&\n getKeyName(argsProperty.key) === 'args'\n );\n }\n\n if (parent?.type === 'JSXExpressionContainer') {\n const attribute = parent.parent;\n\n return (\n attribute?.type === 'JSXAttribute' &&\n attribute.name.type === 'JSXIdentifier' &&\n (attribute.name.name === 'styles' ||\n attribute.name.name.endsWith('Styles'))\n );\n }\n\n return false;\n }\n\n /**\n * Checks if a property value node is a state mapping object\n * (i.e., an object where keys are state expressions and values are style values).\n */\n isStateMap(\n node: TSESTree.ObjectExpression,\n parentProperty: TSESTree.Property,\n ): boolean {\n const keyName = getKeyName(parentProperty.key);\n if (keyName === null) return false;\n\n // If the key starts with uppercase, it's a sub-element, not a state map\n if (/^[A-Z]/.test(keyName)) return false;\n\n // Special keys are not state maps\n // At-rule blocks are not state maps — their object values are descriptor maps.\n if (SPECIAL_STYLE_KEYS.has(keyName)) return false;\n\n // If the object has keys that look like state expressions, it's a state map.\n // A lone `_` (the fallback floor) or `''` (the default) is enough — both are\n // already covered by the string-literal / identifier branches below.\n return node.properties.some((prop) => {\n if (prop.type !== 'Property') return false;\n if (prop.key.type === 'Literal' && prop.key.value === '') return true;\n if (prop.key.type === 'Identifier') return true;\n if (prop.key.type === 'Literal' && typeof prop.key.value === 'string') {\n return true;\n }\n return false;\n });\n }\n\n /**\n * Checks if a key represents a sub-element (starts with uppercase).\n */\n isSubElementKey(key: string): boolean {\n return /^[A-Z]/.test(key);\n }\n\n /**\n * Checks if a key represents a nested selector (starts with &).\n */\n isNestedSelectorKey(key: string): boolean {\n return key.startsWith('&');\n }\n\n /**\n * Checks if a key is a custom CSS property definition ($name or $$name).\n */\n isCustomPropertyKey(key: string): boolean {\n return key.startsWith('$');\n }\n\n /**\n * Checks if a key is a color token definition (#name or ##name).\n */\n isColorTokenKey(key: string): boolean {\n return key.startsWith('#');\n }\n\n /**\n * Checks if a key is a special @ property (@keyframes, @property, ...).\n */\n isSpecialKey(key: string): boolean {\n return key.startsWith('@');\n }\n}\n"],"mappings":";;;;;;;AAoBA,SAAgB,qBACd,SAC2D;AAC3D,QAAO,EAAE,kBAAkB,SAAS;;;;;;;;;;;AAgCtC,SAAS,qBAAqB,MAAkC;CAC9D,MAAM,QAAyB,CAAC,KAAK;AAErC,QAAO,MAAM,QAAQ;EACnB,MAAM,UAAU,MAAM,KAAK;AAE3B,MACE,QAAQ,SAAS,qBACjB,QAAQ,SAAS,SAAS,gBAC1B,YAAY,KAAK,QAAQ,SAAS,KAAK,CAEvC,QAAO;AAGT,OAAK,MAAM,SAAS,OAAO,OACzB,QACD,CACC,KAAI,MAAM,QAAQ,MAAM,EACtB;QA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S,0BAA0B;GAC7C,MAAM,YAAY,OAAO;AAEzB,UACE,WAAW,SAAS,kBACpB,UAAU,KAAK,SAAS,oBACvB,UAAU,KAAK,SAAS,YACvB,UAAU,KAAK,KAAK,SAAS,SAAS;;AAI5C,SAAO;;;;;;CAOT,WACE,MACA,gBACS;EACT,MAAM,UAAU,WAAW,eAAe,IAAI;AAC9C,MAAI,YAAY,KAAM,QAAO;AAG7B,MAAI,SAAS,KAAK,QAAQ,CAAE,QAAO;AAInC,MAAI,mBAAmB,IAAI,QAAQ,CAAE,QAAO;AAK5C,SAAO,KAAK,WAAW,MAAM,SAAS;AACpC,OAAI,KAAK,SAAS,WAAY,QAAO;AACrC,OAAI,KAAK,IAAI,SAAS,aAAa,KAAK,IAAI,UAAU,GAAI,QAAO;AACjE,OAAI,KAAK,IAAI,SAAS,aAAc,QAAO;AAC3C,OAAI,KAAK,IAAI,SAAS,aAAa,OAAO,KAAK,IAAI,UAAU,SAC3D,QAAO;AAET,UAAO;IACP;;;;;CAMJ,gBAAgB,KAAsB;AACpC,SAAO,SAAS,KAAK,IAAI;;;;;CAM3B,oBAAoB,KAAsB;AACxC,SAAO,IAAI,WAAW,IAAI;;;;;CAM5B,oBAAoB,KAAsB;AACxC,SAAO,IAAI,WAAW,IAAI;;;;;CAM5B,gBAAgB,KAAsB;AACpC,SAAO,IAAI,WAAW,IAAI;;;;;CAM5B,aAAa,KAAsB;AACjC,SAAO,IAAI,WAAW,IAAI"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { recommended, strict } from "./configs.js";
|
|
2
|
+
import { TypeAwareJSXOptions } from "./type-aware-jsx.js";
|
|
2
3
|
import { ResolvedConfig, StyleFunctionConfig, TastyValidationConfig } from "./types.js";
|
|
3
4
|
|
|
4
5
|
//#region src/index.d.ts
|
|
5
6
|
declare const plugin: any;
|
|
6
7
|
//#endregion
|
|
7
|
-
export { type ResolvedConfig, type StyleFunctionConfig, type TastyValidationConfig, plugin as default, recommended, strict };
|
|
8
|
+
export { type ResolvedConfig, type StyleFunctionConfig, type TastyValidationConfig, type TypeAwareJSXOptions, plugin as default, recommended, strict };
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["rules.knownProperty","rules.validValue","rules.validColorToken","rules.validCustomUnit","rules.validStateKey","rules.validStylesStructure","rules.noNestedSelector","rules.noStateInSelector","rules.preferElementSelector","rules.validCustomProperty","rules.validPreset","rules.validRecipe","rules.validBooleanProperty","rules.validDirectionalModifier","rules.validRadiusShape","rules.noImportant","rules.validSubElement","rules.noNestedStateMap","rules.staticNoDynamicValues","rules.staticValidSelector","rules.preferShorthandProperty","rules.validTransition","rules.requireDefaultState","rules.noUnknownStateAlias","rules.noRawColorValues","rules.noRawTransitionDuration","rules.noRawMotionDuration","rules.noStylesProp","rules.noStyleProp","rules.noClassNameProp","rules.consistentTokenUsage","rules.noRuntimeStylesMutation","rules.noStyleSpread","rules.validStateDefinition","rules.noOwnAtRoot","rules.validDefaultStateOrder","rules.preferAutoCalc","rules.preferStateNegation","rules.preferCustomPropertySyntax","rules.preferHide","rules.preferDirectionalShorthand","rules.preferLonghandProperty"],"sources":["../src/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type { TSESLint } from '@typescript-eslint/utils';\nimport * as rules from './rules/index.js';\nimport { recommended, strict } from './configs.js';\n\nconst ruleMap: Record<string, TSESLint.RuleModule<string, unknown[]>> = {\n 'known-property': rules.knownProperty,\n 'valid-value': rules.validValue,\n 'valid-color-token': rules.validColorToken,\n 'valid-custom-unit': rules.validCustomUnit,\n 'valid-state-key': rules.validStateKey,\n 'valid-styles-structure': rules.validStylesStructure,\n 'no-nested-selector': rules.noNestedSelector,\n 'no-state-in-selector': rules.noStateInSelector,\n 'prefer-element-selector': rules.preferElementSelector,\n 'valid-custom-property': rules.validCustomProperty,\n 'valid-preset': rules.validPreset,\n 'valid-recipe': rules.validRecipe,\n 'valid-boolean-property': rules.validBooleanProperty,\n 'valid-directional-modifier': rules.validDirectionalModifier,\n 'valid-radius-shape': rules.validRadiusShape,\n 'no-important': rules.noImportant,\n 'valid-sub-element': rules.validSubElement,\n 'no-nested-state-map': rules.noNestedStateMap,\n 'static-no-dynamic-values': rules.staticNoDynamicValues,\n 'static-valid-selector': rules.staticValidSelector,\n 'prefer-shorthand-property': rules.preferShorthandProperty,\n 'valid-transition': rules.validTransition,\n 'require-default-state': rules.requireDefaultState,\n 'no-unknown-state-alias': rules.noUnknownStateAlias,\n 'no-raw-color-values': rules.noRawColorValues,\n 'no-raw-transition-duration': rules.noRawTransitionDuration,\n 'no-raw-motion-duration': rules.noRawMotionDuration,\n 'no-styles-prop': rules.noStylesProp,\n 'no-style-prop': rules.noStyleProp,\n 'no-classname-prop': rules.noClassNameProp,\n 'consistent-token-usage': rules.consistentTokenUsage,\n 'no-runtime-styles-mutation': rules.noRuntimeStylesMutation,\n 'no-style-spread': rules.noStyleSpread,\n 'valid-state-definition': rules.validStateDefinition,\n 'no-own-at-root': rules.noOwnAtRoot,\n 'valid-default-state-order': rules.validDefaultStateOrder,\n 'prefer-auto-calc': rules.preferAutoCalc,\n 'prefer-state-negation': rules.preferStateNegation,\n 'prefer-custom-property-syntax': rules.preferCustomPropertySyntax,\n 'prefer-hide': rules.preferHide,\n 'prefer-directional-shorthand': rules.preferDirectionalShorthand,\n 'prefer-longhand-property': rules.preferLonghandProperty,\n};\n\n// Read from package.json so `meta.version` cannot drift from the released\n// version, as the previous hardcoded literal had. `../package.json` resolves to\n// the package root from both `src/` and the unbundled `dist/`.\nconst { version } = createRequire(import.meta.url)('../package.json') as {\n version: string;\n};\n\nconst plugin = {\n meta: {\n name: '@tenphi/eslint-plugin-tasty',\n version,\n },\n rules: ruleMap,\n configs: {\n recommended: {\n plugins: {\n get tasty() {\n return plugin;\n },\n },\n rules: recommended,\n },\n strict: {\n plugins: {\n get tasty() {\n return plugin;\n },\n },\n rules: strict,\n },\n },\n} satisfies TSESLint.FlatConfig.Plugin & {\n configs: Record<string, TSESLint.FlatConfig.Config>;\n};\n\nexport default plugin;\n\nexport { recommended, strict } from './configs.js';\nexport type {\n TastyValidationConfig,\n ResolvedConfig,\n StyleFunctionConfig,\n} from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,UAAkE;CACtE,kBAAkBA;CAClB,eAAeC;CACf,qBAAqBC;CACrB,qBAAqBC;CACrB,mBAAmBC;CACnB,0BAA0BC;CAC1B,sBAAsBC;CACtB,wBAAwBC;CACxB,2BAA2BC;CAC3B,yBAAyBC;CACzB,gBAAgBC;CAChB,gBAAgBC;CAChB,0BAA0BC;CAC1B,8BAA8BC;CAC9B,sBAAsBC;CACtB,gBAAgBC;CAChB,qBAAqBC;CACrB,uBAAuBC;CACvB,4BAA4BC;CAC5B,yBAAyBC;CACzB,6BAA6BC;CAC7B,oBAAoBC;CACpB,yBAAyBC;CACzB,0BAA0BC;CAC1B,uBAAuBC;CACvB,8BAA8BC;CAC9B,0BAA0BC;CAC1B,kBAAkBC;CAClB,iBAAiBC;CACjB,qBAAqBC;CACrB,0BAA0BC;CAC1B,8BAA8BC;CAC9B,mBAAmBC;CACnB,0BAA0BC;CAC1B,kBAAkBC;CAClB,6BAA6BC;CAC7B,oBAAoBC;CACpB,yBAAyBC;CACzB,iCAAiCC;CACjC,eAAeC;CACf,gCAAgCC;CAChC,4BAA4BC;CAC7B;AAKD,MAAM,EAAE,YAAY,cAAc,OAAO,KAAK,IAAI,CAAC,kBAAkB;AAIrE,MAAM,SAAS;CACb,MAAM;EACJ,MAAM;EACN;EACD;CACD,OAAO;CACP,SAAS;EACP,aAAa;GACX,SAAS,EACP,IAAI,QAAQ;AACV,WAAO;MAEV;GACD,OAAO;GACR;EACD,QAAQ;GACN,SAAS,EACP,IAAI,QAAQ;AACV,WAAO;MAEV;GACD,OAAO;GACR;EACF;CACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["rules.knownProperty","rules.validValue","rules.validColorToken","rules.validCustomUnit","rules.validStateKey","rules.validStylesStructure","rules.noNestedSelector","rules.noStateInSelector","rules.preferElementSelector","rules.validCustomProperty","rules.validPreset","rules.validRecipe","rules.validBooleanProperty","rules.validDirectionalModifier","rules.validRadiusShape","rules.noImportant","rules.validSubElement","rules.noNestedStateMap","rules.staticNoDynamicValues","rules.staticValidSelector","rules.preferShorthandProperty","rules.validTransition","rules.requireDefaultState","rules.noUnknownStateAlias","rules.noRawColorValues","rules.noRawTransitionDuration","rules.noRawMotionDuration","rules.noStylesProp","rules.noStyleProp","rules.noClassNameProp","rules.consistentTokenUsage","rules.noRuntimeStylesMutation","rules.noStyleSpread","rules.validStateDefinition","rules.noOwnAtRoot","rules.validDefaultStateOrder","rules.preferAutoCalc","rules.preferStateNegation","rules.preferCustomPropertySyntax","rules.preferHide","rules.preferDirectionalShorthand","rules.preferLonghandProperty"],"sources":["../src/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type { TSESLint } from '@typescript-eslint/utils';\nimport * as rules from './rules/index.js';\nimport { recommended, strict } from './configs.js';\n\nconst ruleMap: Record<string, TSESLint.RuleModule<string, unknown[]>> = {\n 'known-property': rules.knownProperty,\n 'valid-value': rules.validValue,\n 'valid-color-token': rules.validColorToken,\n 'valid-custom-unit': rules.validCustomUnit,\n 'valid-state-key': rules.validStateKey,\n 'valid-styles-structure': rules.validStylesStructure,\n 'no-nested-selector': rules.noNestedSelector,\n 'no-state-in-selector': rules.noStateInSelector,\n 'prefer-element-selector': rules.preferElementSelector,\n 'valid-custom-property': rules.validCustomProperty,\n 'valid-preset': rules.validPreset,\n 'valid-recipe': rules.validRecipe,\n 'valid-boolean-property': rules.validBooleanProperty,\n 'valid-directional-modifier': rules.validDirectionalModifier,\n 'valid-radius-shape': rules.validRadiusShape,\n 'no-important': rules.noImportant,\n 'valid-sub-element': rules.validSubElement,\n 'no-nested-state-map': rules.noNestedStateMap,\n 'static-no-dynamic-values': rules.staticNoDynamicValues,\n 'static-valid-selector': rules.staticValidSelector,\n 'prefer-shorthand-property': rules.preferShorthandProperty,\n 'valid-transition': rules.validTransition,\n 'require-default-state': rules.requireDefaultState,\n 'no-unknown-state-alias': rules.noUnknownStateAlias,\n 'no-raw-color-values': rules.noRawColorValues,\n 'no-raw-transition-duration': rules.noRawTransitionDuration,\n 'no-raw-motion-duration': rules.noRawMotionDuration,\n 'no-styles-prop': rules.noStylesProp,\n 'no-style-prop': rules.noStyleProp,\n 'no-classname-prop': rules.noClassNameProp,\n 'consistent-token-usage': rules.consistentTokenUsage,\n 'no-runtime-styles-mutation': rules.noRuntimeStylesMutation,\n 'no-style-spread': rules.noStyleSpread,\n 'valid-state-definition': rules.validStateDefinition,\n 'no-own-at-root': rules.noOwnAtRoot,\n 'valid-default-state-order': rules.validDefaultStateOrder,\n 'prefer-auto-calc': rules.preferAutoCalc,\n 'prefer-state-negation': rules.preferStateNegation,\n 'prefer-custom-property-syntax': rules.preferCustomPropertySyntax,\n 'prefer-hide': rules.preferHide,\n 'prefer-directional-shorthand': rules.preferDirectionalShorthand,\n 'prefer-longhand-property': rules.preferLonghandProperty,\n};\n\n// Read from package.json so `meta.version` cannot drift from the released\n// version, as the previous hardcoded literal had. `../package.json` resolves to\n// the package root from both `src/` and the unbundled `dist/`.\nconst { version } = createRequire(import.meta.url)('../package.json') as {\n version: string;\n};\n\nconst plugin = {\n meta: {\n name: '@tenphi/eslint-plugin-tasty',\n version,\n },\n rules: ruleMap,\n configs: {\n recommended: {\n plugins: {\n get tasty() {\n return plugin;\n },\n },\n rules: recommended,\n },\n strict: {\n plugins: {\n get tasty() {\n return plugin;\n },\n },\n rules: strict,\n },\n },\n} satisfies TSESLint.FlatConfig.Plugin & {\n configs: Record<string, TSESLint.FlatConfig.Config>;\n};\n\nexport default plugin;\n\nexport { recommended, strict } from './configs.js';\nexport type { TypeAwareJSXOptions } from './type-aware-jsx.js';\nexport type {\n TastyValidationConfig,\n ResolvedConfig,\n StyleFunctionConfig,\n} from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,UAAkE;CACtE,kBAAkBA;CAClB,eAAeC;CACf,qBAAqBC;CACrB,qBAAqBC;CACrB,mBAAmBC;CACnB,0BAA0BC;CAC1B,sBAAsBC;CACtB,wBAAwBC;CACxB,2BAA2BC;CAC3B,yBAAyBC;CACzB,gBAAgBC;CAChB,gBAAgBC;CAChB,0BAA0BC;CAC1B,8BAA8BC;CAC9B,sBAAsBC;CACtB,gBAAgBC;CAChB,qBAAqBC;CACrB,uBAAuBC;CACvB,4BAA4BC;CAC5B,yBAAyBC;CACzB,6BAA6BC;CAC7B,oBAAoBC;CACpB,yBAAyBC;CACzB,0BAA0BC;CAC1B,uBAAuBC;CACvB,8BAA8BC;CAC9B,0BAA0BC;CAC1B,kBAAkBC;CAClB,iBAAiBC;CACjB,qBAAqBC;CACrB,0BAA0BC;CAC1B,8BAA8BC;CAC9B,mBAAmBC;CACnB,0BAA0BC;CAC1B,kBAAkBC;CAClB,6BAA6BC;CAC7B,oBAAoBC;CACpB,yBAAyBC;CACzB,iCAAiCC;CACjC,eAAeC;CACf,gCAAgCC;CAChC,4BAA4BC;CAC7B;AAKD,MAAM,EAAE,YAAY,cAAc,OAAO,KAAK,IAAI,CAAC,kBAAkB;AAIrE,MAAM,SAAS;CACb,MAAM;EACJ,MAAM;EACN;EACD;CACD,OAAO;CACP,SAAS;EACP,aAAa;GACX,SAAS,EACP,IAAI,QAAQ;AACV,WAAO;MAEV;GACD,OAAO;GACR;EACD,QAAQ;GACN,SAAS,EACP,IAAI,QAAQ;AACV,WAAO;MAEV;GACD,OAAO;GACR;EACF;CACF"}
|
|
@@ -56,11 +56,9 @@ var valid_color_token_default = createRule({
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
return {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}, { onStyleObject: collectLocalTokens }),
|
|
63
|
-
"Program:exit"() {
|
|
59
|
+
return stringStyleValueListeners(ctx, checkColorTokensInValue, {
|
|
60
|
+
onStyleObject: collectLocalTokens,
|
|
61
|
+
onProgramExit() {
|
|
64
62
|
if (!Array.isArray(ctx.config.tokens) || ctx.config.tokens.length === 0) return;
|
|
65
63
|
for (const { token, baseName, node } of pendingChecks) {
|
|
66
64
|
if (fileColorTokens.has(baseName)) continue;
|
|
@@ -72,7 +70,7 @@ var valid_color_token_default = createRule({
|
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
|
-
};
|
|
73
|
+
});
|
|
76
74
|
}
|
|
77
75
|
});
|
|
78
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-color-token.js","names":[],"sources":["../../src/rules/valid-color-token.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { stringStyleValueListeners } from '../style-values.js';\nimport {\n getKeyName,\n validateColorTokenSyntax,\n isRawHexColor,\n} from '../utils.js';\nimport { scanValueWords } from '../value-words.js';\n\ntype MessageIds = 'invalidSyntax' | 'unknownToken';\n\ninterface PendingExistenceCheck {\n token: string;\n baseName: string;\n node: TSESTree.Node;\n}\n\nexport default createRule<[], MessageIds>({\n name: 'valid-color-token',\n meta: {\n type: 'problem',\n docs: {\n description: 'Validate color token syntax and existence',\n },\n messages: {\n invalidSyntax: \"Invalid color token '{{token}}': {{reason}}.\",\n unknownToken:\n \"Unknown color token '{{token}}'. Declare it as a '#name' key, or add it to 'tokens' in your tasty config.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n const fileColorTokens = new Set<string>();\n const pendingChecks: PendingExistenceCheck[] = [];\n\n function collectLocalTokens(node: TSESTree.ObjectExpression): void {\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n const key = getKeyName(prop.key);\n if (key && key.startsWith('#') && !key.startsWith('##')) {\n fileColorTokens.add(key);\n }\n }\n }\n\n function checkColorTokensInValue(value: string, node: TSESTree.Node): void {\n for (const word of scanValueWords(value)) {\n const token = word.value;\n if (!token.startsWith('#')) continue;\n if (\n token.startsWith('##') &&\n word.isFunction &&\n value[word.offset + token.length] === '('\n )\n continue;\n\n if (isRawHexColor(token)) continue;\n\n const syntaxError = validateColorTokenSyntax(token);\n if (syntaxError) {\n context.report({\n node,\n messageId: 'invalidSyntax',\n data: { token, reason: syntaxError },\n });\n continue;\n }\n\n if (ctx.config.tokens === false) continue;\n\n const baseName = token.startsWith('##')\n ? '#' + token.slice(2).split('.')[0]\n : '#' + token.slice(1).split('.')[0];\n\n if (baseName === '#current') continue;\n\n pendingChecks.push({ token, baseName, node });\n }\n }\n\n return
|
|
1
|
+
{"version":3,"file":"valid-color-token.js","names":[],"sources":["../../src/rules/valid-color-token.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { stringStyleValueListeners } from '../style-values.js';\nimport {\n getKeyName,\n validateColorTokenSyntax,\n isRawHexColor,\n} from '../utils.js';\nimport { scanValueWords } from '../value-words.js';\n\ntype MessageIds = 'invalidSyntax' | 'unknownToken';\n\ninterface PendingExistenceCheck {\n token: string;\n baseName: string;\n node: TSESTree.Node;\n}\n\nexport default createRule<[], MessageIds>({\n name: 'valid-color-token',\n meta: {\n type: 'problem',\n docs: {\n description: 'Validate color token syntax and existence',\n },\n messages: {\n invalidSyntax: \"Invalid color token '{{token}}': {{reason}}.\",\n unknownToken:\n \"Unknown color token '{{token}}'. Declare it as a '#name' key, or add it to 'tokens' in your tasty config.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n const fileColorTokens = new Set<string>();\n const pendingChecks: PendingExistenceCheck[] = [];\n\n function collectLocalTokens(node: TSESTree.ObjectExpression): void {\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n const key = getKeyName(prop.key);\n if (key && key.startsWith('#') && !key.startsWith('##')) {\n fileColorTokens.add(key);\n }\n }\n }\n\n function checkColorTokensInValue(value: string, node: TSESTree.Node): void {\n for (const word of scanValueWords(value)) {\n const token = word.value;\n if (!token.startsWith('#')) continue;\n if (\n token.startsWith('##') &&\n word.isFunction &&\n value[word.offset + token.length] === '('\n )\n continue;\n\n if (isRawHexColor(token)) continue;\n\n const syntaxError = validateColorTokenSyntax(token);\n if (syntaxError) {\n context.report({\n node,\n messageId: 'invalidSyntax',\n data: { token, reason: syntaxError },\n });\n continue;\n }\n\n if (ctx.config.tokens === false) continue;\n\n const baseName = token.startsWith('##')\n ? '#' + token.slice(2).split('.')[0]\n : '#' + token.slice(1).split('.')[0];\n\n if (baseName === '#current') continue;\n\n pendingChecks.push({ token, baseName, node });\n }\n }\n\n return stringStyleValueListeners(ctx, checkColorTokensInValue, {\n onStyleObject: collectLocalTokens,\n onProgramExit() {\n if (\n !Array.isArray(ctx.config.tokens) ||\n ctx.config.tokens.length === 0\n ) {\n return;\n }\n\n for (const { token, baseName, node } of pendingChecks) {\n if (fileColorTokens.has(baseName)) continue;\n if (ctx.config.tokens.includes(baseName)) continue;\n\n context.report({\n node,\n messageId: 'unknownToken',\n data: { token },\n });\n }\n },\n });\n },\n});\n"],"mappings":";;;;;;;AAmBA,gCAAe,WAA2B;CACxC,MAAM;CACN,MAAM;EACJ,MAAM;EACN,MAAM,EACJ,aAAa,6CACd;EACD,UAAU;GACR,eAAe;GACf,cACE;GACH;EACD,QAAQ,EAAE;EACX;CACD,gBAAgB,EAAE;CAClB,OAAO,SAAS;EACd,MAAM,MAAM,IAAI,aAAa,QAAQ;EACrC,MAAM,kCAAkB,IAAI,KAAa;EACzC,MAAM,gBAAyC,EAAE;EAEjD,SAAS,mBAAmB,MAAuC;AACjE,QAAK,MAAM,QAAQ,K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@@ -42,11 +42,9 @@ var valid_custom_property_default = createRule({
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}, { onStyleObject: collectLocalProperties }),
|
|
49
|
-
"Program:exit"() {
|
|
45
|
+
return stringStyleValueListeners(ctx, checkValue, {
|
|
46
|
+
onStyleObject: collectLocalProperties,
|
|
47
|
+
onProgramExit() {
|
|
50
48
|
if (!Array.isArray(ctx.config.tokens) || ctx.config.tokens.length === 0) return;
|
|
51
49
|
for (const { token, baseName, node } of pendingChecks) {
|
|
52
50
|
if (fileCustomProperties.has(baseName)) continue;
|
|
@@ -58,7 +56,7 @@ var valid_custom_property_default = createRule({
|
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
|
-
};
|
|
59
|
+
});
|
|
62
60
|
}
|
|
63
61
|
});
|
|
64
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valid-custom-property.js","names":[],"sources":["../../src/rules/valid-custom-property.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { stringStyleValueListeners } from '../style-values.js';\nimport { getKeyName } from '../utils.js';\nimport { scanValueWords } from '../value-words.js';\n\ntype MessageIds = 'invalidSyntax' | 'unknownProperty';\n\ninterface PendingExistenceCheck {\n token: string;\n baseName: string;\n node: TSESTree.Node;\n}\n\nexport default createRule<[], MessageIds>({\n name: 'valid-custom-property',\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Validate $name custom property references',\n },\n messages: {\n invalidSyntax:\n \"Invalid custom property '{{token}}'. Use '$name' with letters, digits, or hyphens (e.g. $accent-color).\",\n unknownProperty:\n \"Unknown custom property '{{token}}'. Declare it as a '$name' key in this styles object, or add it to your tasty config.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n const fileCustomProperties = new Set<string>();\n const pendingChecks: PendingExistenceCheck[] = [];\n\n function collectLocalProperties(node: TSESTree.ObjectExpression): void {\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n const key = getKeyName(prop.key);\n if (key && key.startsWith('$') && !key.startsWith('$$')) {\n fileCustomProperties.add(key);\n }\n }\n }\n\n function checkValue(value: string, node: TSESTree.Node): void {\n if (ctx.config.tokens === false) return;\n\n for (const word of scanValueWords(value)) {\n // A dynamic color opacity is another custom-property reference.\n const token =\n word.value.startsWith('#') && word.value.includes('.$')\n ? word.value.slice(word.value.indexOf('.$') + 1)\n : word.value;\n if (!token.startsWith('$')) continue;\n if (\n token.startsWith('$$') &&\n word.isFunction &&\n value[word.offset + word.value.length] === '('\n )\n continue;\n const baseName = token.startsWith('$$') ? '$' + token.slice(2) : token;\n\n pendingChecks.push({ token, baseName, node });\n }\n }\n\n return
|
|
1
|
+
{"version":3,"file":"valid-custom-property.js","names":[],"sources":["../../src/rules/valid-custom-property.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext } from '../context.js';\nimport { stringStyleValueListeners } from '../style-values.js';\nimport { getKeyName } from '../utils.js';\nimport { scanValueWords } from '../value-words.js';\n\ntype MessageIds = 'invalidSyntax' | 'unknownProperty';\n\ninterface PendingExistenceCheck {\n token: string;\n baseName: string;\n node: TSESTree.Node;\n}\n\nexport default createRule<[], MessageIds>({\n name: 'valid-custom-property',\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Validate $name custom property references',\n },\n messages: {\n invalidSyntax:\n \"Invalid custom property '{{token}}'. Use '$name' with letters, digits, or hyphens (e.g. $accent-color).\",\n unknownProperty:\n \"Unknown custom property '{{token}}'. Declare it as a '$name' key in this styles object, or add it to your tasty config.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n const fileCustomProperties = new Set<string>();\n const pendingChecks: PendingExistenceCheck[] = [];\n\n function collectLocalProperties(node: TSESTree.ObjectExpression): void {\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n const key = getKeyName(prop.key);\n if (key && key.startsWith('$') && !key.startsWith('$$')) {\n fileCustomProperties.add(key);\n }\n }\n }\n\n function checkValue(value: string, node: TSESTree.Node): void {\n if (ctx.config.tokens === false) return;\n\n for (const word of scanValueWords(value)) {\n // A dynamic color opacity is another custom-property reference.\n const token =\n word.value.startsWith('#') && word.value.includes('.$')\n ? word.value.slice(word.value.indexOf('.$') + 1)\n : word.value;\n if (!token.startsWith('$')) continue;\n if (\n token.startsWith('$$') &&\n word.isFunction &&\n value[word.offset + word.value.length] === '('\n )\n continue;\n const baseName = token.startsWith('$$') ? '$' + token.slice(2) : token;\n\n pendingChecks.push({ token, baseName, node });\n }\n }\n\n return stringStyleValueListeners(ctx, checkValue, {\n onStyleObject: collectLocalProperties,\n onProgramExit() {\n if (\n !Array.isArray(ctx.config.tokens) ||\n ctx.config.tokens.length === 0\n ) {\n return;\n }\n\n for (const { token, baseName, node } of pendingChecks) {\n if (fileCustomProperties.has(baseName)) continue;\n if (ctx.config.tokens.includes(baseName)) continue;\n\n context.report({\n node,\n messageId: 'unknownProperty',\n data: { token },\n });\n }\n },\n });\n },\n});\n"],"mappings":";;;;;;;AAeA,oCAAe,WAA2B;CACxC,MAAM;CACN,MAAM;EACJ,MAAM;EACN,MAAM,EACJ,aAAa,6CACd;EACD,UAAU;GACR,eACE;GACF,iBACE;GACH;EACD,QAAQ,EAAE;EACX;CACD,gBAAgB,EAAE;CAClB,OAAO,SAAS;EACd,MAAM,MAAM,IAAI,aAAa,QAAQ;EACrC,MAAM,uCAAuB,IAAI,KAAa;EAC9C,MAAM,gBAAyC,EAAE;EAEjD,SAAS,uBAAuB,MAAuC;AACrE,QAAK,MAAM,QAAQ,KAAK,YAAY;AAClC,QAAI,KAAK,SAAS,cAAc,KAAK,SAAU;IAC/C,MAAM,MAAM,WAAW,KAAK,IAAI;AAChC,QAAI,OAAO,IAAI,WAAW,IAAI,IAAI,CAAC,IAAI,WAAW,KAAK,CACrD,sBAAqB,IAAI,IAAI;;;EAKnC,SAAS,WAAW,OAAe,MAA2B;AAC5D,OAAI,IAAI,OAAO,WAAW,MAAO;AAEjC,QAAK,MAAM,QAAQ,eAAe,MAAM,EAAE;IAExC,MAAM,QACJ,KAAK,MAAM,WAAW,IAAI,IAAI,KAAK,MAAM,SAAS,KAAK,GACnD,KAAK,MAAM,MAAM,KAAK,MAAM,QAAQ,KAAK,GAAG,EAAE,GAC9C,KAAK;AACX,QAAI,CAAC,MAAM,WAAW,IAAI,CAAE;AAC5B,QACE,MAAM,WAAW,KAAK,IACtB,KAAK,cACL,MAAM,KAAK,SAAS,KAAK,MAAM,YAAY,IAE3C;IACF,MAAM,WAAW,MAAM,WAAW,KAAK,GAAG,MAAM,MAAM,MAAM,EAAE,GAAG;AAEjE,kBAAc,KAAK;KAAE;KAAO;KAAU;KAAM,CAAC;;;AAIjD,SAAO,0BAA0B,KAAK,YAAY;GAChD,eAAe;GACf,gBAAgB;AACd,QACE,CAAC,MAAM,QAAQ,IAAI,OAAO,OAAO,IACjC,IAAI,OAAO,OAAO,WAAW,EAE7B;AAGF,SAAK,MAAM,EAAE,OAAO,UAAU,UAAU,eAAe;AACrD,SAAI,qBAAqB,IAAI,SAAS,CAAE;AACxC,SAAI,IAAI,OAAO,OAAO,SAAS,SAAS,CAAE;AAE1C,aAAQ,OAAO;MACb;MACA,WAAW;MACX,MAAM,EAAE,OAAO;MAChB,CAAC;;;GAGP,CAAC;;CAEL,CAAC"}
|
package/dist/style-values.js
CHANGED
|
@@ -4,31 +4,39 @@ import { getKeyName, getStringValue, unwrapExpression } from "./utils.js";
|
|
|
4
4
|
//#region src/style-values.ts
|
|
5
5
|
/** Visit visible values without evaluating bindings, calls, or interpolations. */
|
|
6
6
|
function styleValueListeners(ctx, check, options = {}) {
|
|
7
|
-
function visit(property, node) {
|
|
7
|
+
function visit(property, node, attribute) {
|
|
8
8
|
node = unwrapExpression(node);
|
|
9
9
|
if (node.type === "ObjectExpression") {
|
|
10
10
|
for (const prop of node.properties) if (prop.type === "Property" && !prop.computed) {
|
|
11
11
|
const value = unwrapExpression(prop.value);
|
|
12
|
-
if (value.type !== "ObjectExpression") visit(property, value);
|
|
12
|
+
if (value.type !== "ObjectExpression") visit(property, value, attribute);
|
|
13
13
|
}
|
|
14
14
|
} else if (node.type === "ConditionalExpression") {
|
|
15
|
-
visit(property, node.consequent);
|
|
16
|
-
visit(property, node.alternate);
|
|
15
|
+
visit(property, node.consequent, attribute);
|
|
16
|
+
visit(property, node.alternate, attribute);
|
|
17
17
|
} else if (node.type === "LogicalExpression") {
|
|
18
18
|
const left = unwrapExpression(node.left);
|
|
19
19
|
const str = getStringValue(left);
|
|
20
20
|
const known = left.type === "Literal" || str !== null;
|
|
21
21
|
const value = left.type === "Literal" ? left.value : str;
|
|
22
22
|
if (node.operator === "&&") {
|
|
23
|
-
if (!known || value) visit(property, node.right);
|
|
24
|
-
} else if (known) visit(property, node.operator === "??" ? value == null ? node.right : left : value ? left : node.right);
|
|
23
|
+
if (!known || value) visit(property, node.right, attribute);
|
|
24
|
+
} else if (known) visit(property, node.operator === "??" ? value == null ? node.right : left : value ? left : node.right, attribute);
|
|
25
25
|
else {
|
|
26
|
-
visit(property, node.left);
|
|
27
|
-
visit(property, node.right);
|
|
26
|
+
visit(property, node.left, attribute);
|
|
27
|
+
visit(property, node.right, attribute);
|
|
28
28
|
}
|
|
29
|
-
} else
|
|
29
|
+
} else {
|
|
30
|
+
const visible = node.type === "Literal" || node.type === "JSXAttribute" || getStringValue(node) !== null || node.type === "UnaryExpression" && node.argument.type === "Literal";
|
|
31
|
+
if (attribute && visible && ctx.isComponentJSXProp(attribute)) return;
|
|
32
|
+
check(property, node);
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
return {
|
|
36
|
+
"Program:exit"() {
|
|
37
|
+
ctx.finishJSXAnalysis();
|
|
38
|
+
options.onProgramExit?.();
|
|
39
|
+
},
|
|
32
40
|
ImportDeclaration(node) {
|
|
33
41
|
ctx.trackImport(node);
|
|
34
42
|
},
|
|
@@ -53,8 +61,8 @@ function styleValueListeners(ctx, check, options = {}) {
|
|
|
53
61
|
if (tag.type !== "JSXIdentifier" || !/^[A-Z]/.test(tag.name)) return;
|
|
54
62
|
if (options.requireTastyJSX && !ctx.isTastyJSXComponent(node, tag.name)) return;
|
|
55
63
|
const value = node.value?.type === "JSXExpressionContainer" ? node.value.expression : node.value;
|
|
56
|
-
if (value) visit(key, value);
|
|
57
|
-
else
|
|
64
|
+
if (value) visit(key, value, node);
|
|
65
|
+
else visit(key, node, node);
|
|
58
66
|
}
|
|
59
67
|
};
|
|
60
68
|
}
|
package/dist/style-values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-values.js","names":[],"sources":["../src/style-values.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport type { TastyContext } from './context.js';\nimport { KNOWN_CSS_PROPERTIES, KNOWN_TASTY_PROPERTIES } from './constants.js';\nimport { getKeyName, getStringValue, unwrapExpression } from './utils.js';\n\ninterface ValueListenerOptions {\n /** Collect declarations before checking their values (token existence rules). */\n onStyleObject?: (node: TSESTree.ObjectExpression) => void;\n /** Rewrites that depend on Tasty semantics need evidence beyond the prop name. */\n requireTastyJSX?: boolean;\n}\n\n/** Visit visible values without evaluating bindings, calls, or interpolations. */\nexport function styleValueListeners(\n ctx: TastyContext,\n check: (property: string, node: TSESTree.Node) => void,\n options: ValueListenerOptions = {},\n) {\n function visit(property: string
|
|
1
|
+
{"version":3,"file":"style-values.js","names":[],"sources":["../src/style-values.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport type { TastyContext } from './context.js';\nimport { KNOWN_CSS_PROPERTIES, KNOWN_TASTY_PROPERTIES } from './constants.js';\nimport { getKeyName, getStringValue, unwrapExpression } from './utils.js';\n\ninterface ValueListenerOptions {\n /** Collect declarations before checking their values (token existence rules). */\n onStyleObject?: (node: TSESTree.ObjectExpression) => void;\n /** Rewrites that depend on Tasty semantics need evidence beyond the prop name. */\n requireTastyJSX?: boolean;\n /** Deferred checks run after all declarations have been collected. */\n onProgramExit?: () => void;\n}\n\n/** Visit visible values without evaluating bindings, calls, or interpolations. */\nexport function styleValueListeners(\n ctx: TastyContext,\n check: (property: string, node: TSESTree.Node) => void,\n options: ValueListenerOptions = {},\n) {\n function visit(\n property: string,\n node: TSESTree.Node,\n attribute?: TSESTree.JSXAttribute,\n ): void {\n node = unwrapExpression(node);\n if (node.type === 'ObjectExpression') {\n // A property value object is a state map, never a sub-element here.\n for (const prop of node.properties) {\n if (prop.type === 'Property' && !prop.computed) {\n const value = unwrapExpression(prop.value);\n if (value.type !== 'ObjectExpression')\n visit(property, value, attribute);\n }\n }\n } else if (node.type === 'ConditionalExpression') {\n visit(property, node.consequent, attribute);\n visit(property, node.alternate, attribute);\n } else if (node.type === 'LogicalExpression') {\n const left = unwrapExpression(node.left);\n const str = getStringValue(left);\n const known = left.type === 'Literal' || str !== null;\n const value = left.type === 'Literal' ? left.value : str;\n if (node.operator === '&&') {\n // The left operand can only be the result when it is falsy.\n if (!known || value) visit(property, node.right, attribute);\n } else if (known) {\n visit(\n property,\n node.operator === '??'\n ? value == null\n ? node.right\n : left\n : value\n ? left\n : node.right,\n attribute,\n );\n } else {\n visit(property, node.left, attribute);\n visit(property, node.right, attribute);\n }\n } else {\n const visible =\n node.type === 'Literal' ||\n node.type === 'JSXAttribute' ||\n getStringValue(node) !== null ||\n (node.type === 'UnaryExpression' && node.argument.type === 'Literal');\n // Opaque values cannot produce a value diagnostic; avoid a compiler pass.\n if (attribute && visible && ctx.isComponentJSXProp(attribute)) return;\n check(property, node);\n }\n }\n\n return {\n 'Program:exit'() {\n ctx.finishJSXAnalysis();\n options.onProgramExit?.();\n },\n ImportDeclaration(node: TSESTree.ImportDeclaration) {\n ctx.trackImport(node);\n },\n ObjectExpression(node: TSESTree.ObjectExpression) {\n if (!ctx.isStyleObject(node)) return;\n options.onStyleObject?.(node);\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n const key = getKeyName(prop.key);\n if (key === null || /^[A-Z@&]/.test(key) || key === '$') continue;\n visit(key, prop.value);\n }\n },\n JSXAttribute(node: TSESTree.JSXAttribute) {\n if (node.name.type !== 'JSXIdentifier') return;\n const key = node.name.name;\n if (\n !KNOWN_TASTY_PROPERTIES.has(key) &&\n !KNOWN_CSS_PROPERTIES.has(key) &&\n !ctx.config.styles.includes(key)\n )\n return;\n\n const opening = node.parent;\n if (opening?.type !== 'JSXOpeningElement') return;\n let tag = opening.name;\n while (tag.type === 'JSXMemberExpression') tag = tag.object;\n // Native HTML/SVG attributes contain CSS, not Tasty's value language.\n if (tag.type !== 'JSXIdentifier' || !/^[A-Z]/.test(tag.name)) return;\n if (options.requireTastyJSX && !ctx.isTastyJSXComponent(node, tag.name))\n return;\n\n const value =\n node.value?.type === 'JSXExpressionContainer'\n ? node.value.expression\n : node.value;\n if (value) visit(key, value, node);\n else visit(key, node, node); // A bare JSX attribute means boolean true.\n },\n };\n}\n\n/** Adapt a node listener to the string-only rules. */\nexport function stringStyleValueListeners(\n ctx: TastyContext,\n check: (value: string, node: TSESTree.Node, property: string) => void,\n options: ValueListenerOptions = {},\n) {\n return styleValueListeners(\n ctx,\n (property, node) => {\n const value = getStringValue(node);\n if (value !== null) check(value, node, property);\n },\n options,\n );\n}\n"],"mappings":";;;;;AAeA,SAAgB,oBACd,KACA,OACA,UAAgC,EAAE,EAClC;CACA,SAAS,MACP,UACA,MACA,WACM;AACN,SAAO,iBAAiB,KAAK;AAC7B,MAAI,KAAK,SAAS,oBAEhB;QAAK,MAAM,QAAQ,KAAK,WACtB,KAAI,KAAK,SAAS,cAAc,CAAC,KAAK,UAAU;IAC9C,MAAM,QAAQ,iBAAiB,KAAK,MAAM;AAC1C,QAAI,MAAM,SAAS,mBACjB,OAAM,UA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AAS,gBAAiB;GACxC,MAAM,MAAM,KAAK,KAAK;AACtB,OACE,CAAC,uBAAuB,IAAI,IAAI,IAChC,CAAC,qBAAqB,IAAI,IAAI,IAC9B,CAAC,IAAI,OAAO,OAAO,SAAS,IAAI,CAEhC;GAEF,MAAM,UAAU,KAAK;AACrB,OAAI,SAAS,SAAS,oBAAqB;GAC3C,IAAI,MAAM,QAAQ;AAClB,UAAO,IAAI,SAAS,sBAAuB,OAAM,IAAI;AAErD,OAAI,IAAI,SAAS,mBAAmB,CAAC,SAAS,KAAK,IAAI,KAAK,CAAE;AAC9D,OAAI,QAAQ,mBAAmB,CAAC,IAAI,oBAAoB,MAAM,IAAI,KAAK,CACrE;GAEF,MAAM,QACJ,KAAK,OAAO,SAAS,2BACjB,KAAK,MAAM,aACX,KAAK;AACX,OAAI,MAAO,OAAM,KAAK,OAAO,KAAK;OAC7B,OAAM,KAAK,MAAM,KAAK;;EAE9B;;;AAIH,SAAgB,0BACd,KACA,OACA,UAAgC,EAAE,EAClC;AACA,QAAO,oBACL,MACC,UAAU,SAAS;EAClB,MAAM,QAAQ,eAAe,KAAK;AAClC,MAAI,UAAU,KAAM,OAAM,OAAO,MAAM,SAAS;IAElD,QACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/type-aware-jsx.d.ts
|
|
2
|
+
/** Experimental, independently managed TypeScript analysis for either linter. */
|
|
3
|
+
interface TypeAwareJSXOptions {
|
|
4
|
+
/** tsconfig path relative to the linter's cwd; otherwise find the nearest one. */
|
|
5
|
+
project?: string;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { TypeAwareJSXOptions };
|
|
9
|
+
//# sourceMappingURL=type-aware-jsx.d.ts.map
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { statSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/type-aware-jsx.ts
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
let typescript;
|
|
8
|
+
const projects = /* @__PURE__ */ new Map();
|
|
9
|
+
const classifiers = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function getTypeScript() {
|
|
11
|
+
if (!typescript) try {
|
|
12
|
+
typescript = require("typescript");
|
|
13
|
+
} catch {
|
|
14
|
+
throw new Error("tasty: typeAwareJSX requires TypeScript. Install typescript as a dev dependency.");
|
|
15
|
+
}
|
|
16
|
+
return typescript;
|
|
17
|
+
}
|
|
18
|
+
function version(filename) {
|
|
19
|
+
try {
|
|
20
|
+
const stat = statSync(filename);
|
|
21
|
+
return `${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}`;
|
|
22
|
+
} catch {
|
|
23
|
+
return "missing";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function changed(versions) {
|
|
27
|
+
for (const [filename, previous] of versions) if (version(filename) !== previous) return true;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function readConfig(T, configPath, configVersions) {
|
|
31
|
+
const config = T.getParsedCommandLineOfConfigFile(configPath, {}, {
|
|
32
|
+
...T.sys,
|
|
33
|
+
readFile(filename) {
|
|
34
|
+
configVersions.set(filename, version(filename));
|
|
35
|
+
return T.sys.readFile(filename);
|
|
36
|
+
},
|
|
37
|
+
onUnRecoverableConfigFileDiagnostic(diagnostic) {
|
|
38
|
+
throw new Error(`tasty: ${T.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (!config || config.errors.length) throw new Error(`tasty: invalid typeAwareJSX project ${configPath}: ${config?.errors.map((d) => T.flattenDiagnosticMessageText(d.messageText, "\n")).join("\n")}`);
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
function readProject(T, configPath) {
|
|
45
|
+
const configVersions = /* @__PURE__ */ new Map();
|
|
46
|
+
return {
|
|
47
|
+
config: readConfig(T, configPath, configVersions),
|
|
48
|
+
configVersions,
|
|
49
|
+
versions: /* @__PURE__ */ new Map(),
|
|
50
|
+
sourceFiles: /* @__PURE__ */ new Map(),
|
|
51
|
+
excludedFiles: /* @__PURE__ */ new Map()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getProgram(T, configPath, filename, text) {
|
|
55
|
+
let project = projects.get(configPath);
|
|
56
|
+
let rootsChanged = false;
|
|
57
|
+
if (!project || changed(project.configVersions)) project = readProject(T, configPath);
|
|
58
|
+
else if (project.program && !project.program.getSourceFile(filename) && project.excludedFiles.get(filename) !== version(filename)) {
|
|
59
|
+
const refreshed = readProject(T, configPath);
|
|
60
|
+
const previousFiles = project.config.fileNames;
|
|
61
|
+
rootsChanged = refreshed.config.fileNames.length !== previousFiles.length || refreshed.config.fileNames.some((file, index) => file !== previousFiles[index]);
|
|
62
|
+
if (rootsChanged) project.config = refreshed.config;
|
|
63
|
+
if (!project.config.fileNames.includes(filename)) project.excludedFiles.set(filename, version(filename));
|
|
64
|
+
else project.excludedFiles.delete(filename);
|
|
65
|
+
}
|
|
66
|
+
projects.delete(configPath);
|
|
67
|
+
projects.set(configPath, project);
|
|
68
|
+
if (projects.size > 3) projects.delete(projects.keys().next().value);
|
|
69
|
+
const sourcesChanged = changed(project.versions);
|
|
70
|
+
const overlay = project.excludedFiles.has(filename) && !project.program?.getSourceFile(filename) && !rootsChanged && !sourcesChanged ? void 0 : T.sys.readFile(filename) === text ? void 0 : {
|
|
71
|
+
filename,
|
|
72
|
+
text
|
|
73
|
+
};
|
|
74
|
+
const overlayChanged = project.overlay?.filename !== overlay?.filename || project.overlay?.text !== overlay?.text;
|
|
75
|
+
if (!project.program || rootsChanged || overlayChanged || sourcesChanged) {
|
|
76
|
+
const host = T.createCompilerHost(project.config.options, true);
|
|
77
|
+
host.getParsedCommandLine = (path) => readConfig(T, path, project.configVersions);
|
|
78
|
+
const readFile = host.readFile;
|
|
79
|
+
host.readFile = (path) => resolve(path) === overlay?.filename ? overlay.text : readFile(path);
|
|
80
|
+
const getSourceFile = host.getSourceFile;
|
|
81
|
+
host.getSourceFile = (path, options, onError, force) => {
|
|
82
|
+
const key = resolve(path);
|
|
83
|
+
const stamp = version(key);
|
|
84
|
+
const overlayText = key === overlay?.filename ? overlay.text : void 0;
|
|
85
|
+
const parseOptions = typeof options === "number" ? { languageVersion: options } : options;
|
|
86
|
+
const parseKey = [
|
|
87
|
+
parseOptions.languageVersion,
|
|
88
|
+
parseOptions.impliedNodeFormat,
|
|
89
|
+
parseOptions.jsDocParsingMode
|
|
90
|
+
].join(":");
|
|
91
|
+
const cached = project.sourceFiles.get(key);
|
|
92
|
+
if (!force && cached?.version === stamp && cached.overlayText === overlayText && cached.parseKey === parseKey) return cached.source;
|
|
93
|
+
const source = getSourceFile(path, options, onError, force);
|
|
94
|
+
if (source) project.sourceFiles.set(key, {
|
|
95
|
+
version: stamp,
|
|
96
|
+
overlayText,
|
|
97
|
+
parseKey,
|
|
98
|
+
source
|
|
99
|
+
});
|
|
100
|
+
else project.sourceFiles.delete(key);
|
|
101
|
+
return source;
|
|
102
|
+
};
|
|
103
|
+
project.program = T.createProgram({
|
|
104
|
+
rootNames: project.config.fileNames,
|
|
105
|
+
options: project.config.options,
|
|
106
|
+
projectReferences: project.config.projectReferences,
|
|
107
|
+
host,
|
|
108
|
+
oldProgram: project.program
|
|
109
|
+
});
|
|
110
|
+
project.overlay = project.program.getSourceFile(filename) ? overlay : void 0;
|
|
111
|
+
if (!project.program.getSourceFile(filename)) project.excludedFiles.set(filename, version(filename));
|
|
112
|
+
project.versions = new Map(project.program.getSourceFiles().map((file) => [file.fileName, version(file.fileName)]));
|
|
113
|
+
const retained = new Set(project.program.getSourceFiles().map((file) => resolve(file.fileName)));
|
|
114
|
+
for (const path of project.sourceFiles.keys()) if (!retained.has(path)) project.sourceFiles.delete(path);
|
|
115
|
+
}
|
|
116
|
+
return project.program;
|
|
117
|
+
}
|
|
118
|
+
function makeClassifier(T, program, filename, text) {
|
|
119
|
+
const source = program.getSourceFile(filename);
|
|
120
|
+
if (!source || source.text !== text) return () => "unknown";
|
|
121
|
+
const checker = program.getTypeChecker();
|
|
122
|
+
const modulePath = T.resolveModuleName("@tenphi/tasty", filename, program.getCompilerOptions(), T.sys).resolvedModule?.resolvedFileName;
|
|
123
|
+
const moduleFile = modulePath && program.getSourceFile(modulePath);
|
|
124
|
+
const module = moduleFile && checker.getSymbolAtLocation(moduleFile);
|
|
125
|
+
const exports = module ? checker.getExportsOfModule(module) : [];
|
|
126
|
+
const styleTypeSymbols = new Set(exports?.filter((s) => [
|
|
127
|
+
"Styles",
|
|
128
|
+
"StyleValue",
|
|
129
|
+
"StyleValueStateMap"
|
|
130
|
+
].includes(s.name)).map((s) => s.flags & T.SymbolFlags.Alias ? checker.getAliasedSymbol(s) : s));
|
|
131
|
+
let symbol = exports?.find((s) => s.name === "Styles");
|
|
132
|
+
if (symbol && symbol.flags & T.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
|
|
133
|
+
const styles = symbol && checker.getDeclaredTypeOfSymbol(symbol);
|
|
134
|
+
if (!styles || styles.flags & (T.TypeFlags.Any | T.TypeFlags.Unknown)) return () => "unknown";
|
|
135
|
+
const styleDeclarations = new Set(styles.getProperties().flatMap((property) => property.declarations ?? []));
|
|
136
|
+
function isStyleDeclaration(declaration) {
|
|
137
|
+
return styleDeclarations.has(declaration) || /[/\\]node_modules[/\\](?:@tenphi[/\\]tasty|csstype)[/\\]/.test(declaration.getSourceFile().fileName);
|
|
138
|
+
}
|
|
139
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
140
|
+
function collect(node) {
|
|
141
|
+
if (T.isJsxAttribute(node)) attributes.set(node.getStart(source), node);
|
|
142
|
+
T.forEachChild(node, collect);
|
|
143
|
+
}
|
|
144
|
+
collect(source);
|
|
145
|
+
function referencesStyles(node, visited = /* @__PURE__ */ new Set(), bindings = /* @__PURE__ */ new Map()) {
|
|
146
|
+
if (visited.has(node)) return false;
|
|
147
|
+
visited.add(node);
|
|
148
|
+
try {
|
|
149
|
+
if (T.isPropertySignature(node) || T.isPropertyDeclaration(node) || T.isParameter(node) || T.isTypeAliasDeclaration(node) || T.isMappedTypeNode(node) || T.isParenthesizedTypeNode(node)) return node.type ? referencesStyles(node.type, visited, bindings) : false;
|
|
150
|
+
if (T.isIndexedAccessTypeNode(node)) {
|
|
151
|
+
const object = checker.getTypeFromTypeNode(node.objectType);
|
|
152
|
+
const index = checker.getTypeFromTypeNode(node.indexType);
|
|
153
|
+
const keys = index.isUnion() ? index.types : [index];
|
|
154
|
+
return object === styles || keys.some((key) => {
|
|
155
|
+
if (!key.isStringLiteral() && !key.isNumberLiteral()) return false;
|
|
156
|
+
return checker.getPropertyOfType(object, String(key.value))?.declarations?.some((declaration) => isStyleDeclaration(declaration) || referencesStyles(declaration, visited, bindings));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (T.isTypeReferenceNode(node) || T.isImportTypeNode(node)) {
|
|
160
|
+
const name = T.isTypeReferenceNode(node) ? node.typeName : node.qualifier;
|
|
161
|
+
let reference = name && checker.getSymbolAtLocation(name);
|
|
162
|
+
if (reference && reference.flags & T.SymbolFlags.Alias) reference = checker.getAliasedSymbol(reference);
|
|
163
|
+
if (reference && styleTypeSymbols.has(reference)) return true;
|
|
164
|
+
if (reference?.declarations?.some(isStyleDeclaration)) return true;
|
|
165
|
+
const bound = reference && bindings.get(reference);
|
|
166
|
+
if (bound) return referencesStyles(bound, visited, bindings);
|
|
167
|
+
if (reference?.declarations?.some((declaration) => {
|
|
168
|
+
if (!T.isTypeAliasDeclaration(declaration)) return false;
|
|
169
|
+
const local = new Map(bindings);
|
|
170
|
+
declaration.typeParameters?.forEach((parameter, index) => {
|
|
171
|
+
const symbol = checker.getSymbolAtLocation(parameter.name);
|
|
172
|
+
const argument = node.typeArguments?.[index] ?? parameter.default;
|
|
173
|
+
if (symbol && argument) local.set(symbol, argument);
|
|
174
|
+
});
|
|
175
|
+
return referencesStyles(declaration.type, visited, local);
|
|
176
|
+
})) return true;
|
|
177
|
+
}
|
|
178
|
+
if (T.isConditionalTypeNode(node)) {
|
|
179
|
+
const parameter = (branch) => {
|
|
180
|
+
if (!T.isTypeReferenceNode(branch)) return void 0;
|
|
181
|
+
const symbol = checker.getSymbolAtLocation(branch.typeName);
|
|
182
|
+
return symbol && symbol.flags & T.SymbolFlags.TypeParameter ? symbol : void 0;
|
|
183
|
+
};
|
|
184
|
+
const trueParameter = parameter(node.trueType);
|
|
185
|
+
const falseParameter = parameter(node.falseType);
|
|
186
|
+
const preservesValue = trueParameter && node.falseType.kind === T.SyntaxKind.NeverKeyword || falseParameter && node.trueType.kind === T.SyntaxKind.NeverKeyword || trueParameter && trueParameter === falseParameter;
|
|
187
|
+
return Boolean(preservesValue) && (referencesStyles(node.trueType, visited, bindings) || referencesStyles(node.falseType, visited, bindings));
|
|
188
|
+
}
|
|
189
|
+
return (T.isUnionTypeNode(node) || T.isIntersectionTypeNode(node)) && node.types.some((part) => referencesStyles(part, visited, bindings));
|
|
190
|
+
} finally {
|
|
191
|
+
visited.delete(node);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function unresolved(type) {
|
|
195
|
+
if (type.flags & (T.TypeFlags.Any | T.TypeFlags.Unknown | T.TypeFlags.TypeParameter | T.TypeFlags.Conditional | T.TypeFlags.IndexedAccess | T.TypeFlags.Never)) return true;
|
|
196
|
+
return type.isUnionOrIntersection() && type.types.some(unresolved);
|
|
197
|
+
}
|
|
198
|
+
function hasPrimitiveFlag(type, flags) {
|
|
199
|
+
return Boolean(type.flags & flags) || type.isIntersection() && type.types.some((part) => hasPrimitiveFlag(part, flags));
|
|
200
|
+
}
|
|
201
|
+
function unresolvedComponentProp(node, name) {
|
|
202
|
+
const tag = node.parent.parent.tagName;
|
|
203
|
+
const component = checker.getTypeAtLocation(tag);
|
|
204
|
+
return [...component.getCallSignatures(), ...component.getConstructSignatures()].some((signature) => {
|
|
205
|
+
const parameter = signature.parameters[0];
|
|
206
|
+
if (!parameter) return false;
|
|
207
|
+
const props = checker.getTypeOfSymbolAtLocation(parameter, tag);
|
|
208
|
+
const property = checker.getPropertyOfType(props, name);
|
|
209
|
+
return property ? unresolved(checker.getTypeOfSymbolAtLocation(property, tag)) : false;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const results = /* @__PURE__ */ new Map();
|
|
213
|
+
return (attribute) => {
|
|
214
|
+
const start = attribute.range[0];
|
|
215
|
+
const cached = results.get(start);
|
|
216
|
+
if (cached) return cached;
|
|
217
|
+
const node = attributes.get(start);
|
|
218
|
+
let kind = "unknown";
|
|
219
|
+
if (node && node.end === attribute.range[1] && T.isIdentifier(node.name)) {
|
|
220
|
+
const props = checker.getContextualType(node.parent);
|
|
221
|
+
const property = props && checker.getPropertyOfType(props, node.name.text);
|
|
222
|
+
const declarations = property?.declarations;
|
|
223
|
+
if (property && declarations?.length) {
|
|
224
|
+
const type = checker.getTypeOfSymbolAtLocation(property, node);
|
|
225
|
+
if (declarations.some((d) => isStyleDeclaration(d) || referencesStyles(d))) kind = "style";
|
|
226
|
+
else if (!unresolved(type) && !(declarations.some((declaration) => unresolved(checker.getTypeAtLocation(declaration))) && unresolvedComponentProp(node, node.name.text))) {
|
|
227
|
+
const nonNullable = checker.getNonNullableType(type);
|
|
228
|
+
const parts = nonNullable.isUnion() ? nonNullable.types : [nonNullable];
|
|
229
|
+
const primitive = T.TypeFlags.StringLike | T.TypeFlags.NumberLike | T.TypeFlags.BooleanLike | T.TypeFlags.BigIntLike;
|
|
230
|
+
const broad = T.TypeFlags.String | T.TypeFlags.Number | T.TypeFlags.Boolean | T.TypeFlags.BigInt;
|
|
231
|
+
if (!(parts.every((part) => hasPrimitiveFlag(part, primitive)) && (Boolean(nonNullable.flags & broad) || parts.some((part) => hasPrimitiveFlag(part, broad)) || parts.every((part) => hasPrimitiveFlag(part, T.TypeFlags.BooleanLike))))) kind = "component";
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
results.set(start, kind);
|
|
236
|
+
return kind;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** No compiler is loaded, or program created, unless the setting is enabled. */
|
|
240
|
+
function jsxPropKind(context, attribute) {
|
|
241
|
+
const option = context.settings.tasty?.typeAwareJSX;
|
|
242
|
+
if (option === void 0 || option === false) return "unknown";
|
|
243
|
+
if (option !== true && (!option || typeof option !== "object" || Array.isArray(option) || option.project !== void 0 && typeof option.project !== "string")) throw new Error("tasty: typeAwareJSX must be true, false, or { project: string }.");
|
|
244
|
+
const filename = resolve(context.cwd, context.filename);
|
|
245
|
+
const explicit = option === true ? void 0 : option.project;
|
|
246
|
+
const sourceCode = context.sourceCode;
|
|
247
|
+
const key = explicit ? resolve(context.cwd, explicit) : "nearest";
|
|
248
|
+
let byProject = classifiers.get(sourceCode);
|
|
249
|
+
if (!byProject) {
|
|
250
|
+
byProject = /* @__PURE__ */ new Map();
|
|
251
|
+
classifiers.set(sourceCode, byProject);
|
|
252
|
+
}
|
|
253
|
+
let cached = byProject.get(key);
|
|
254
|
+
if (!cached || cached.filename !== filename || cached.text !== sourceCode.text) {
|
|
255
|
+
const T = getTypeScript();
|
|
256
|
+
const configPath = explicit ? key : T.findConfigFile(dirname(filename), T.sys.fileExists);
|
|
257
|
+
if (!configPath) throw new Error(`tasty: typeAwareJSX could not find a tsconfig for ${filename}.`);
|
|
258
|
+
const program = getProgram(T, configPath, filename, sourceCode.text);
|
|
259
|
+
cached = {
|
|
260
|
+
filename,
|
|
261
|
+
text: sourceCode.text,
|
|
262
|
+
classify: makeClassifier(T, program, filename, sourceCode.text)
|
|
263
|
+
};
|
|
264
|
+
byProject.set(key, cached);
|
|
265
|
+
}
|
|
266
|
+
return cached.classify(attribute);
|
|
267
|
+
}
|
|
268
|
+
/** A SourceCode object may be reused by ESLint after dependencies change. */
|
|
269
|
+
function finishJSXAnalysis(context) {
|
|
270
|
+
classifiers.delete(context.sourceCode);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
export { finishJSXAnalysis, jsxPropKind };
|
|
275
|
+
//# sourceMappingURL=type-aware-jsx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-aware-jsx.js","names":[],"sources":["../src/type-aware-jsx.ts"],"sourcesContent":["import { statSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, resolve } from 'node:path';\nimport type ts from 'typescript';\nimport type { TSESTree } from '@typescript-eslint/utils';\nimport type { RuleContext } from '@typescript-eslint/utils/ts-eslint';\n\n/** Experimental, independently managed TypeScript analysis for either linter. */\nexport interface TypeAwareJSXOptions {\n /** tsconfig path relative to the linter's cwd; otherwise find the nearest one. */\n project?: string;\n}\n\ntype PropKind = 'style' | 'component' | 'unknown';\ntype TypeScript = typeof ts;\ntype Classifier = (attribute: TSESTree.JSXAttribute) => PropKind;\n\ninterface Project {\n config: ts.ParsedCommandLine;\n configVersions: Map<string, string>;\n program?: ts.Program;\n versions: Map<string, string>;\n overlay?: { filename: string; text: string };\n sourceFiles: Map<\n string,\n {\n version: string;\n overlayText?: string;\n parseKey: string;\n source: ts.SourceFile;\n }\n >;\n excludedFiles: Map<string, string>;\n}\n\nconst require = createRequire(import.meta.url);\nlet typescript: TypeScript | undefined;\nconst projects = new Map<string, Project>();\n// All value rules share one classifier for a file, including in Oxlint.\nconst classifiers = new WeakMap<\n object,\n Map<\n string,\n {\n filename: string;\n text: string;\n classify: Classifier;\n }\n >\n>();\n\nfunction getTypeScript(): TypeScript {\n if (!typescript) {\n try {\n typescript = require('typescript') as TypeScript;\n } catch {\n throw new Error(\n 'tasty: typeAwareJSX requires TypeScript. Install typescript as a dev dependency.',\n );\n }\n }\n return typescript;\n}\n\nfunction version(filename: string): string {\n try {\n const stat = statSync(filename);\n return `${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}`;\n } catch {\n return 'missing';\n }\n}\n\nfunction changed(versions: Map<string, string>): boolean {\n for (const [filename, previous] of versions) {\n if (version(filename) !== previous) return true;\n }\n return false;\n}\n\nfunction readConfig(\n T: TypeScript,\n configPath: string,\n configVersions: Map<string, string>,\n): ts.ParsedCommandLine {\n const config = T.getParsedCommandLineOfConfigFile(\n configPath,\n {},\n {\n ...T.sys,\n readFile(filename) {\n configVersions.set(filename, version(filename));\n return T.sys.readFile(filename);\n },\n onUnRecoverableConfigFileDiagnostic(diagnostic) {\n throw new Error(\n `tasty: ${T.flattenDiagnosticMessageText(diagnostic.messageText, '\\n')}`,\n );\n },\n },\n );\n if (!config || config.errors.length) {\n throw new Error(\n `tasty: invalid typeAwareJSX project ${configPath}: ${config?.errors\n .map((d) => T.flattenDiagnosticMessageText(d.messageText, '\\n'))\n .join('\\n')}`,\n );\n }\n return config;\n}\n\nfunction readProject(T: TypeScript, configPath: string): Project {\n const configVersions = new Map<string, string>();\n return {\n config: readConfig(T, configPath, configVersions),\n configVersions,\n versions: new Map(),\n sourceFiles: new Map(),\n excludedFiles: new Map(),\n };\n}\n\nfunction getProgram(\n T: TypeScript,\n configPath: string,\n filename: string,\n text: string,\n): ts.Program {\n let project = projects.get(configPath);\n let rootsChanged = false;\n if (!project || changed(project.configVersions)) {\n project = readProject(T, configPath);\n } else if (\n project.program &&\n !project.program.getSourceFile(filename) &&\n project.excludedFiles.get(filename) !== version(filename)\n ) {\n const refreshed = readProject(T, configPath);\n const previousFiles = project.config.fileNames;\n rootsChanged =\n refreshed.config.fileNames.length !== previousFiles.length ||\n refreshed.config.fileNames.some(\n (file, index) => file !== previousFiles[index],\n );\n if (rootsChanged) project.config = refreshed.config;\n if (!project.config.fileNames.includes(filename))\n project.excludedFiles.set(filename, version(filename));\n else project.excludedFiles.delete(filename);\n }\n // Bound retained compiler graphs in long-lived editor processes.\n projects.delete(configPath);\n projects.set(configPath, project);\n if (projects.size > 3) projects.delete(projects.keys().next().value!);\n\n const sourcesChanged = changed(project.versions);\n const overlay =\n project.excludedFiles.has(filename) &&\n !project.program?.getSourceFile(filename) &&\n !rootsChanged &&\n !sourcesChanged\n ? undefined\n : T.sys.readFile(filename) === text\n ? undefined\n : { filename, text };\n const overlayChanged =\n project.overlay?.filename !== overlay?.filename ||\n project.overlay?.text !== overlay?.text;\n if (!project.program || rootsChanged || overlayChanged || sourcesChanged) {\n const host = T.createCompilerHost(project.config.options, true);\n host.getParsedCommandLine = (path) =>\n readConfig(T, path, project.configVersions);\n const readFile = host.readFile;\n host.readFile = (path) =>\n resolve(path) === overlay?.filename ? overlay.text : readFile(path);\n const getSourceFile = host.getSourceFile;\n host.getSourceFile = (path, options, onError, force) => {\n const key = resolve(path);\n const stamp = version(key);\n const overlayText = key === overlay?.filename ? overlay.text : undefined;\n const parseOptions =\n typeof options === 'number' ? { languageVersion: options } : options;\n const parseKey = [\n parseOptions.languageVersion,\n parseOptions.impliedNodeFormat,\n parseOptions.jsDocParsingMode,\n ].join(':');\n const cached = project.sourceFiles.get(key);\n if (\n !force &&\n cached?.version === stamp &&\n cached.overlayText === overlayText &&\n cached.parseKey === parseKey\n )\n return cached.source;\n const source = getSourceFile(path, options, onError, force);\n if (source)\n project.sourceFiles.set(key, {\n version: stamp,\n overlayText,\n parseKey,\n source,\n });\n else project.sourceFiles.delete(key);\n return source;\n };\n project.program = T.createProgram({\n rootNames: project.config.fileNames,\n options: project.config.options,\n projectReferences: project.config.projectReferences,\n host,\n oldProgram: project.program,\n });\n project.overlay = project.program.getSourceFile(filename)\n ? overlay\n : undefined;\n if (!project.program.getSourceFile(filename))\n project.excludedFiles.set(filename, version(filename));\n project.versions = new Map(\n project.program\n .getSourceFiles()\n .map((file) => [file.fileName, version(file.fileName)]),\n );\n const retained = new Set(\n project.program.getSourceFiles().map((file) => resolve(file.fileName)),\n );\n for (const path of project.sourceFiles.keys()) {\n if (!retained.has(path)) project.sourceFiles.delete(path);\n }\n }\n return project.program;\n}\n\nfunction makeClassifier(\n T: TypeScript,\n program: ts.Program,\n filename: string,\n text: string,\n): Classifier {\n const source = program.getSourceFile(filename);\n // Excluded files and virtual/transformed source keep the existing heuristic.\n if (!source || source.text !== text) return () => 'unknown';\n const checker = program.getTypeChecker();\n const modulePath = T.resolveModuleName(\n '@tenphi/tasty',\n filename,\n program.getCompilerOptions(),\n T.sys,\n ).resolvedModule?.resolvedFileName;\n const moduleFile = modulePath && program.getSourceFile(modulePath);\n const module = moduleFile && checker.getSymbolAtLocation(moduleFile);\n const exports = module ? checker.getExportsOfModule(module) : [];\n const styleTypeSymbols = new Set(\n exports\n ?.filter((s) =>\n ['Styles', 'StyleValue', 'StyleValueStateMap'].includes(s.name),\n )\n .map((s) =>\n s.flags & T.SymbolFlags.Alias ? checker.getAliasedSymbol(s) : s,\n ),\n );\n let symbol = exports?.find((s) => s.name === 'Styles');\n if (symbol && symbol.flags & T.SymbolFlags.Alias) {\n symbol = checker.getAliasedSymbol(symbol);\n }\n const styles = symbol && checker.getDeclaredTypeOfSymbol(symbol);\n if (!styles || styles.flags & (T.TypeFlags.Any | T.TypeFlags.Unknown)) {\n return () => 'unknown';\n }\n const styleDeclarations = new Set(\n styles.getProperties().flatMap((property) => property.declarations ?? []),\n );\n // A dependency may resolve a different copy of either styling package.\n function isStyleDeclaration(declaration: ts.Declaration): boolean {\n return (\n styleDeclarations.has(declaration) ||\n /[/\\\\]node_modules[/\\\\](?:@tenphi[/\\\\]tasty|csstype)[/\\\\]/.test(\n declaration.getSourceFile().fileName,\n )\n );\n }\n const attributes = new Map<number, ts.JsxAttribute>();\n function collect(node: ts.Node): void {\n if (T.isJsxAttribute(node)) attributes.set(node.getStart(source), node);\n T.forEachChild(node, collect);\n }\n collect(source);\n\n function referencesStyles(\n node: ts.Node,\n visited = new Set<ts.Node>(),\n bindings = new Map<ts.Symbol, ts.TypeNode>(),\n ): boolean {\n if (visited.has(node)) return false;\n visited.add(node);\n try {\n if (\n T.isPropertySignature(node) ||\n T.isPropertyDeclaration(node) ||\n T.isParameter(node) ||\n T.isTypeAliasDeclaration(node) ||\n T.isMappedTypeNode(node) ||\n T.isParenthesizedTypeNode(node)\n )\n return node.type\n ? referencesStyles(node.type, visited, bindings)\n : false;\n if (T.isIndexedAccessTypeNode(node)) {\n const object = checker.getTypeFromTypeNode(node.objectType);\n const index = checker.getTypeFromTypeNode(node.indexType);\n const keys = index.isUnion() ? index.types : [index];\n // Trace the selected property, not unrelated style props on the object.\n return (\n object === styles ||\n keys.some((key) => {\n if (!key.isStringLiteral() && !key.isNumberLiteral()) return false;\n const property = checker.getPropertyOfType(\n object,\n String(key.value),\n );\n return property?.declarations?.some(\n (declaration) =>\n isStyleDeclaration(declaration) ||\n referencesStyles(declaration, visited, bindings),\n );\n })\n );\n }\n if (T.isTypeReferenceNode(node) || T.isImportTypeNode(node)) {\n const name = T.isTypeReferenceNode(node)\n ? node.typeName\n : node.qualifier;\n let reference = name && checker.getSymbolAtLocation(name);\n if (reference && reference.flags & T.SymbolFlags.Alias) {\n reference = checker.getAliasedSymbol(reference);\n }\n if (reference && styleTypeSymbols.has(reference)) return true;\n if (reference?.declarations?.some(isStyleDeclaration)) return true;\n const bound = reference && bindings.get(reference);\n if (bound) return referencesStyles(bound, visited, bindings);\n if (\n reference?.declarations?.some((declaration) => {\n if (!T.isTypeAliasDeclaration(declaration)) return false;\n const local = new Map(bindings);\n declaration.typeParameters?.forEach((parameter, index) => {\n const symbol = checker.getSymbolAtLocation(parameter.name);\n const argument = node.typeArguments?.[index] ?? parameter.default;\n if (symbol && argument) local.set(symbol, argument);\n });\n return referencesStyles(declaration.type, visited, local);\n })\n )\n return true;\n }\n if (T.isConditionalTypeNode(node)) {\n // Extract/Exclude-style filters preserve an input value or return never.\n const parameter = (branch: ts.TypeNode) => {\n if (!T.isTypeReferenceNode(branch)) return undefined;\n const symbol = checker.getSymbolAtLocation(branch.typeName);\n return symbol && symbol.flags & T.SymbolFlags.TypeParameter\n ? symbol\n : undefined;\n };\n const trueParameter = parameter(node.trueType);\n const falseParameter = parameter(node.falseType);\n const preservesValue =\n (trueParameter &&\n node.falseType.kind === T.SyntaxKind.NeverKeyword) ||\n (falseParameter &&\n node.trueType.kind === T.SyntaxKind.NeverKeyword) ||\n (trueParameter && trueParameter === falseParameter);\n return (\n Boolean(preservesValue) &&\n (referencesStyles(node.trueType, visited, bindings) ||\n referencesStyles(node.falseType, visited, bindings))\n );\n }\n // Nested fields, function arguments and conditional constraints are content,\n // not evidence that the prop's value itself originates in a style type.\n return (\n (T.isUnionTypeNode(node) || T.isIntersectionTypeNode(node)) &&\n node.types.some((part) => referencesStyles(part, visited, bindings))\n );\n } finally {\n visited.delete(node);\n }\n }\n\n function unresolved(type: ts.Type): boolean {\n if (\n type.flags &\n (T.TypeFlags.Any |\n T.TypeFlags.Unknown |\n T.TypeFlags.TypeParameter |\n T.TypeFlags.Conditional |\n T.TypeFlags.IndexedAccess |\n T.TypeFlags.Never)\n )\n return true;\n return type.isUnionOrIntersection() && type.types.some(unresolved);\n }\n\n function hasPrimitiveFlag(type: ts.Type, flags: number): boolean {\n return (\n Boolean(type.flags & flags) ||\n (type.isIntersection() &&\n type.types.some((part) => hasPrimitiveFlag(part, flags)))\n );\n }\n\n function unresolvedComponentProp(\n node: ts.JsxAttribute,\n name: string,\n ): boolean {\n const tag = node.parent.parent.tagName;\n const component = checker.getTypeAtLocation(tag);\n return [\n ...component.getCallSignatures(),\n ...component.getConstructSignatures(),\n ].some((signature) => {\n const parameter = signature.parameters[0];\n if (!parameter) return false;\n const props = checker.getTypeOfSymbolAtLocation(parameter, tag);\n const property = checker.getPropertyOfType(props, name);\n return property\n ? unresolved(checker.getTypeOfSymbolAtLocation(property, tag))\n : false;\n });\n }\n\n const results = new Map<number, PropKind>();\n return (attribute) => {\n const start = attribute.range[0];\n const cached = results.get(start);\n if (cached) return cached;\n const node = attributes.get(start);\n let kind: PropKind = 'unknown';\n if (node && node.end === attribute.range[1] && T.isIdentifier(node.name)) {\n const props = checker.getContextualType(node.parent);\n const property =\n props && checker.getPropertyOfType(props, node.name.text);\n const declarations = property?.declarations;\n if (property && declarations?.length) {\n const type = checker.getTypeOfSymbolAtLocation(property, node);\n if (\n declarations.some((d) => isStyleDeclaration(d) || referencesStyles(d))\n ) {\n kind = 'style';\n } else if (\n !unresolved(type) &&\n !(\n declarations.some((declaration) =>\n unresolved(checker.getTypeAtLocation(declaration)),\n ) && unresolvedComponentProp(node, node.name.text)\n )\n ) {\n // Broad primitives may be hand-written style props. Preserve checks.\n const nonNullable = checker.getNonNullableType(type);\n const parts = nonNullable.isUnion()\n ? nonNullable.types\n : [nonNullable];\n const primitive =\n T.TypeFlags.StringLike |\n T.TypeFlags.NumberLike |\n T.TypeFlags.BooleanLike |\n T.TypeFlags.BigIntLike;\n const broad =\n T.TypeFlags.String |\n T.TypeFlags.Number |\n T.TypeFlags.Boolean |\n T.TypeFlags.BigInt;\n const broadPrimitive =\n parts.every((part) => hasPrimitiveFlag(part, primitive)) &&\n (Boolean(nonNullable.flags & broad) ||\n parts.some((part) => hasPrimitiveFlag(part, broad)) ||\n parts.every((part) =>\n hasPrimitiveFlag(part, T.TypeFlags.BooleanLike),\n ));\n if (!broadPrimitive) kind = 'component';\n }\n }\n }\n results.set(start, kind);\n return kind;\n };\n}\n\n/** No compiler is loaded, or program created, unless the setting is enabled. */\nexport function jsxPropKind(\n context: RuleContext<string, unknown[]>,\n attribute: TSESTree.JSXAttribute,\n): PropKind {\n const settings = context.settings.tasty as\n | { typeAwareJSX?: boolean | TypeAwareJSXOptions }\n | undefined;\n const option = settings?.typeAwareJSX;\n if (option === undefined || option === false) return 'unknown';\n if (\n option !== true &&\n (!option ||\n typeof option !== 'object' ||\n Array.isArray(option) ||\n (option.project !== undefined && typeof option.project !== 'string'))\n )\n throw new Error(\n 'tasty: typeAwareJSX must be true, false, or { project: string }.',\n );\n\n const filename = resolve(context.cwd, context.filename);\n const explicit = option === true ? undefined : option.project;\n const sourceCode = context.sourceCode;\n const key = explicit ? resolve(context.cwd, explicit) : 'nearest';\n let byProject = classifiers.get(sourceCode);\n if (!byProject) {\n byProject = new Map();\n classifiers.set(sourceCode, byProject);\n }\n let cached = byProject.get(key);\n if (\n !cached ||\n cached.filename !== filename ||\n cached.text !== sourceCode.text\n ) {\n const T = getTypeScript();\n const configPath = explicit\n ? key\n : T.findConfigFile(dirname(filename), T.sys.fileExists);\n if (!configPath)\n throw new Error(\n `tasty: typeAwareJSX could not find a tsconfig for ${filename}.`,\n );\n const program = getProgram(T, configPath, filename, sourceCode.text);\n cached = {\n filename,\n text: sourceCode.text,\n classify: makeClassifier(T, program, filename, sourceCode.text),\n };\n byProject.set(key, cached);\n }\n return cached.classify(attribute);\n}\n\n/** A SourceCode object may be reused by ESLint after dependencies change. */\nexport function finishJSXAnalysis(\n context: RuleContext<string, unknown[]>,\n): void {\n classifiers.delete(context.sourceCode);\n}\n"],"mappings":";;;;;AAmCA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAC9C,IAAI;AACJ,MAAM,2BAAW,IAAI,KAAsB;AAE3C,MAAM,8BAAc,IAAI,SAUrB;AAEH,SAAS,gBAA4B;AACnC,KAAI,CAAC,WACH,KAAI;AACF,eAAa,QAAQ,aAAa;SAC5B;AACN,QAAM,IAAI,MACR,mFACD;;AAGL,QAAO;;AAGT,SAAS,QAAQ,UAA0B;AACzC,KAAI;EACF,MAAM,OAAO,SAAS,SAAS;AAC/B,SAAO,GAAG,KAAK,QAAQ,GAAG,KAAK,QAAQ,GAAG,KAAK;SACzC;AACN,SAAO;;;AAIX,SAAS,QAAQ,UAAwC;AACvD,MAAK,MAAM,CAAC,UAAU,aAAa,SACjC,KAAI,QAAQ,SAAS,KAAK,SAAU,QAAO;AAE7C,QAAO;;AAGT,SAAS,WACP,GACA,YACA,gBACsB;CACtB,MAAM,SAAS,EAAE,iCACf,YACA,EAAE,EACF;EACE,GAAG,EAAE;EACL,SAAS,UAAU;AACjB,kBAAe,IAAI,UAAU,QAAQ,SAAS,CAAC;AAC/C,UAAO,EAAE,IAAI,SAAS,SAAS;;EAEjC,oCAAoC,YAAY;AAC9C,SAAM,IAA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ugin-tasty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "ESLint plugin for validating tasty() and tastyStatic() style objects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"homepage": "https://github.com/tenphi/eslint-plugin-tasty#readme",
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@tenphi/tasty": ">=3.8.0",
|
|
43
|
-
"eslint": ">=8.0.0"
|
|
43
|
+
"eslint": ">=8.0.0",
|
|
44
|
+
"typescript": ">=5.6.3 <6"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
47
|
"@typescript-eslint/utils": "^8.56.0",
|
|
@@ -67,6 +68,9 @@
|
|
|
67
68
|
"vitest": "^4.0.18"
|
|
68
69
|
},
|
|
69
70
|
"peerDependenciesMeta": {
|
|
71
|
+
"typescript": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
70
74
|
"@tenphi/tasty": {
|
|
71
75
|
"optional": true
|
|
72
76
|
}
|