@tenphi/eslint-plugin-tasty 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,16 +4,16 @@ import { TastyContext, styleObjectListeners } from "../context.js";
4
4
  import selectorParser from "postcss-selector-parser";
5
5
 
6
6
  //#region src/rules/valid-sub-element.ts
7
- /** Expressions whose result is visibly not an object. */
8
- const NON_OBJECT_EXPRESSIONS = new Set([
9
- "TemplateLiteral",
10
- "ArrayExpression",
11
- "ArrowFunctionExpression",
12
- "FunctionExpression",
13
- "ClassExpression",
14
- "UnaryExpression",
15
- "BinaryExpression",
16
- "UpdateExpression"
7
+ /** Expressions whose result is visibly not an object, as named in a report. */
8
+ const NON_OBJECT_EXPRESSIONS = new Map([
9
+ ["TemplateLiteral", "a string"],
10
+ ["ArrayExpression", "an array"],
11
+ ["ArrowFunctionExpression", "a function"],
12
+ ["FunctionExpression", "a function"],
13
+ ["ClassExpression", "a class"],
14
+ ["UnaryExpression", "a primitive value"],
15
+ ["BinaryExpression", "a primitive value"],
16
+ ["UpdateExpression", "a number"]
17
17
  ]);
18
18
  const LEGACY_PSEUDO_ELEMENTS = new Set([
19
19
  ":before",
@@ -67,7 +67,7 @@ var valid_sub_element_default = createRule({
67
67
  type: "problem",
68
68
  docs: { description: "Validate sub-element values and prevent root-targeting affixes" },
69
69
  messages: {
70
- subElementNotObject: "Sub-element '{{name}}' value must be a style object, not a {{type}}.",
70
+ subElementNotObject: "Sub-element '{{name}}' value must be a style object, not {{type}}.",
71
71
  subElementTargetsRoot: "Sub-element '{{name}}' selector '{{selector}}' styles the containing element instead of a sub-element. Use property state maps in that containing scope, or a descendant '$' selector such as 'h1'. Pseudo-elements such as '&::before' are allowed."
72
72
  },
73
73
  schema: []
@@ -95,14 +95,21 @@ var valid_sub_element_default = createRule({
95
95
  }
96
96
  }
97
97
  /**
98
- * The type to name in the report when a value can never be a style object,
99
- * or `null` when it is `false` (disables the sub-element) or might be one.
98
+ * What to name in the report when a value can never be a style object, or
99
+ * `null` when it might be one or is `false` or `null`. Both disable the
100
+ * sub-element, and in a later `mergeStyles` layer or a `styles` prop they
101
+ * remove the one below; `undefined` (`void 0`) leaves it as it is.
100
102
  * A `const` binding is followed to what it names; any other binding, member
101
103
  * or call is opaque, and Tasty accepts a reference to a style object there.
102
104
  */
103
105
  function nonObjectType(node, seen) {
104
106
  node = unwrapExpression(node);
105
- if (node.type === "Literal") return node.value === false ? null : typeof node.value;
107
+ if (node.type === "Literal") {
108
+ if ("regex" in node && node.regex) return "a regular expression";
109
+ if (node.value === false || node.value === null) return null;
110
+ return `a ${typeof node.value}`;
111
+ }
112
+ if (node.type === "UnaryExpression" && node.operator === "void") return null;
106
113
  if (node.type === "Identifier") {
107
114
  if (seen.has(node)) return null;
108
115
  seen.add(node);
@@ -114,7 +121,7 @@ var valid_sub_element_default = createRule({
114
121
  const init = unwrapExpression(def.node.init);
115
122
  return init.type === "ObjectExpression" ? null : nonObjectType(init, seen);
116
123
  }
117
- return NON_OBJECT_EXPRESSIONS.has(node.type) ? node.type : null;
124
+ return NON_OBJECT_EXPRESSIONS.get(node.type) ?? null;
118
125
  }
119
126
  function checkStyleObject(node) {
120
127
  if (visited.has(node)) return;
@@ -1 +1 @@
1
- {"version":3,"file":"valid-sub-element.js","names":[],"sources":["../../src/rules/valid-sub-element.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport selectorParser from 'postcss-selector-parser';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext, styleObjectListeners } from '../context.js';\nimport { getKeyName, getStringValue, unwrapExpression } from '../utils.js';\n\ntype MessageIds = 'subElementNotObject' | 'subElementTargetsRoot';\n\n/** Expressions whose result is visibly not an object. */\nconst NON_OBJECT_EXPRESSIONS = new Set<string>([\n 'TemplateLiteral',\n 'ArrayExpression',\n 'ArrowFunctionExpression',\n 'FunctionExpression',\n 'ClassExpression',\n 'UnaryExpression',\n 'BinaryExpression',\n 'UpdateExpression',\n]);\n\nconst LEGACY_PSEUDO_ELEMENTS = new Set([\n ':before',\n ':after',\n ':first-line',\n ':first-letter',\n]);\n\nfunction hasDescendantTarget(nodes: selectorParser.Node[]): boolean {\n let lastCharacter = '';\n for (const node of nodes.slice(1)) {\n if (node.type === 'combinator') {\n if (node.value.trim()) return true;\n // The affix renderer skips authored whitespace. Tags insert their own\n // separator; pseudos attach directly, and classes/attributes attach\n // after a tag, class, attribute or placeholder.\n continue;\n }\n if (node.type === 'tag' || node.type === 'universal') {\n if (lastCharacter) return true;\n } else if (node.type === 'class' || node.type === 'attribute') {\n if (lastCharacter && !/[\\]@a-zA-Z0-9-]/.test(lastCharacter)) return true;\n }\n lastCharacter = node.toString().trim().slice(-1);\n }\n return false;\n}\n\nfunction firstRootSelector(selector: string, key: string): string | null {\n try {\n const root = selectorParser().astSync(selector);\n for (const branch of root.nodes) {\n const nodes = branch.nodes.filter((node) => node.type !== 'comment');\n if (nodes[0]?.type !== 'nesting' || nodes.length < 2) continue;\n // An explicit placeholder creates a descendant selector even with an\n // ampersand prefix. A different trailing uppercase name injects the key\n // as its descendant; the sub-element's own name does not.\n if (\n nodes.some((node) => node.type === 'tag' && node.value.startsWith('@'))\n )\n continue;\n const trailingElement = branch\n .toString()\n .trim()\n .slice(1)\n .trim()\n .match(/(?:^|[\\s>+~\\]:])([A-Z][a-zA-Z0-9]*)$/);\n if (trailingElement && trailingElement[1] !== key) continue;\n // Follow Tasty's affix normalization, rather than CSS whitespace alone.\n // Nested :is() arguments do not change the outer selector's target.\n if (hasDescendantTarget(nodes)) continue;\n const hasPseudoElement = nodes.some((node) => {\n if (node.type !== 'pseudo') return false;\n let name = node.value.toLowerCase();\n if (name.startsWith('::')) return true;\n if (name.includes('\\\\')) {\n const identifier = selectorParser().astSync(name.slice(1)).first\n ?.first;\n if (identifier?.type === 'tag')\n name = ':' + identifier.value.toLowerCase();\n }\n return LEGACY_PSEUDO_ELEMENTS.has(name);\n });\n if (!hasPseudoElement) return branch.toString().trim();\n }\n } catch {\n // Invalid/incomplete selector text belongs to syntax validation.\n }\n return null;\n}\n\nexport default createRule<[], MessageIds>({\n name: 'valid-sub-element',\n meta: {\n type: 'problem',\n docs: {\n description:\n 'Validate sub-element values and prevent root-targeting affixes',\n },\n messages: {\n subElementNotObject:\n \"Sub-element '{{name}}' value must be a style object, not a {{type}}.\",\n subElementTargetsRoot:\n \"Sub-element '{{name}}' selector '{{selector}}' styles the containing element instead of a sub-element. Use property state maps in that containing scope, or a descendant '$' selector such as 'h1'. Pseudo-elements such as '&::before' are allowed.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n const visited = new WeakSet<TSESTree.ObjectExpression>();\n\n function checkAffix(name: string, node: TSESTree.ObjectExpression) {\n for (const prop of node.properties) {\n if (prop.type !== 'Property') continue;\n const key = prop.computed\n ? getStringValue(unwrapExpression(prop.key))\n : getKeyName(prop.key);\n if (key !== '$') continue;\n const selector = getStringValue(unwrapExpression(prop.value));\n if (selector === null) continue;\n const rootSelector = firstRootSelector(selector, name);\n if (rootSelector === null) continue;\n context.report({\n node: prop.value,\n messageId: 'subElementTargetsRoot',\n data: { name, selector: rootSelector },\n });\n }\n }\n\n /**\n * The type to name in the report when a value can never be a style object,\n * or `null` when it is `false` (disables the sub-element) or might be one.\n * A `const` binding is followed to what it names; any other binding, member\n * or call is opaque, and Tasty accepts a reference to a style object there.\n */\n function nonObjectType(\n node: TSESTree.Node,\n seen: Set<TSESTree.Node>,\n ): string | null {\n node = unwrapExpression(node);\n if (node.type === 'Literal') {\n return node.value === false ? null : typeof node.value;\n }\n if (node.type === 'Identifier') {\n if (seen.has(node)) return null;\n seen.add(node);\n let scope: ReturnType<typeof context.sourceCode.getScope> | null =\n context.sourceCode.getScope(node);\n while (scope && !scope.set.has(node.name)) scope = scope.upper;\n const variable = scope?.set.get(node.name);\n const def = variable?.defs.length === 1 ? variable.defs[0] : undefined;\n if (\n def?.type !== 'Variable' ||\n def.parent.kind !== 'const' ||\n !def.node.init\n ) {\n return null;\n }\n const init = unwrapExpression(def.node.init);\n return init.type === 'ObjectExpression'\n ? null\n : nonObjectType(init, seen);\n }\n return NON_OBJECT_EXPRESSIONS.has(node.type) ? node.type : null;\n }\n\n // Recurse only through owned sub-elements. Some shared/JSX listeners match\n // just the root, and descriptor objects and state maps are not styles.\n function checkStyleObject(node: TSESTree.ObjectExpression) {\n if (visited.has(node)) return;\n visited.add(node);\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property') continue;\n\n const key = prop.computed\n ? getStringValue(unwrapExpression(prop.key))\n : getKeyName(prop.key);\n if (key === null || !/^[A-Z]/.test(key)) continue;\n\n const value = unwrapExpression(prop.value);\n if (value.type === 'ObjectExpression') {\n checkAffix(key, value);\n checkStyleObject(value);\n } else {\n const valueType = nonObjectType(value, new Set());\n if (valueType === null) continue;\n\n context.report({\n node: prop.value,\n messageId: 'subElementNotObject',\n data: { name: key, type: valueType },\n });\n }\n }\n }\n\n function handleStyleObject(node: TSESTree.ObjectExpression) {\n if (ctx.isStyleObject(node)) checkStyleObject(node);\n }\n\n return {\n ImportDeclaration(node) {\n ctx.trackImport(node);\n },\n ...styleObjectListeners(handleStyleObject),\n };\n },\n});\n"],"mappings":";;;;;;;AASA,MAAM,yBAAyB,IAAI,IAAY;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,yBAAyB,IAAI,IAAI;CACrC;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,oBAAoB,OAAuC;CAClE,IAAI,gBAAgB;AACpB,MAAK,MAAM,QAAQ,MAAM,MAAM,EAAE,EAAE;AACjC,MAAI,KAAK,SAAS,cAAc;AAC9B,OAAI,KAAK,MAAM,MAAM,CAAE,QAAO;AAI9B;;AAEF,MAAI,KAAK,SAAS,SAAS,KAAK,SAAS,aACvC;OAAI,cAAe,QAAO;aACjB,KAAK,SAAS,WAAW,KAAK,SAAS,aAChD;OAAI,iBA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I,KAAK,CAAE;AACvB,WAAQ,IAAI,KAAK;AAEjB,QAAK,MAAM,QAAQ,KAAK,YAAY;AAClC,QAAI,KAAK,SAAS,WAAY;IAE9B,MAAM,MAAM,KAAK,WACb,eAAe,iBAAiB,KAAK,IAAI,CAAC,GAC1C,WAAW,KAAK,IAAI;AACxB,QAAI,QAAQ,QAAQ,CAAC,SAAS,KAAK,IAAI,CAAE;IAEzC,MAAM,QAAQ,iBAAiB,KAAK,MAAM;AAC1C,QAAI,MAAM,SAAS,oBAAoB;AACrC,gBAAW,KAAK,MAAM;AACtB,sBAAiB,MAAM;WAClB;KACL,MAAM,YAAY,cAAc,uBAAO,IAAI,KAAK,CAAC;AACjD,SAAI,cAAc,KAAM;AAExB,aAAQ,OAAO;MACb,MAAM,KAAK;MACX,WAAW;MACX,MAAM;OAAE,MAAM;OAAK,MAAM;OAAW;MACrC,CAAC;;;;EAKR,SAAS,kBAAkB,MAAiC;AAC1D,OAAI,IAAI,cAAc,KAAK,CAAE,kBAAiB,KAAK;;AAGrD,SAAO;GACL,kBAAkB,MAAM;AACtB,QAAI,YAAY,KAAK;;GAEvB,GAAG,qBAAqB,kBAAkB;GAC3C;;CAEJ,CAAC"}
1
+ {"version":3,"file":"valid-sub-element.js","names":[],"sources":["../../src/rules/valid-sub-element.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport selectorParser from 'postcss-selector-parser';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext, styleObjectListeners } from '../context.js';\nimport { getKeyName, getStringValue, unwrapExpression } from '../utils.js';\n\ntype MessageIds = 'subElementNotObject' | 'subElementTargetsRoot';\n\n/** Expressions whose result is visibly not an object, as named in a report. */\nconst NON_OBJECT_EXPRESSIONS = new Map<string, string>([\n ['TemplateLiteral', 'a string'],\n ['ArrayExpression', 'an array'],\n ['ArrowFunctionExpression', 'a function'],\n ['FunctionExpression', 'a function'],\n ['ClassExpression', 'a class'],\n ['UnaryExpression', 'a primitive value'],\n ['BinaryExpression', 'a primitive value'],\n ['UpdateExpression', 'a number'],\n]);\n\nconst LEGACY_PSEUDO_ELEMENTS = new Set([\n ':before',\n ':after',\n ':first-line',\n ':first-letter',\n]);\n\nfunction hasDescendantTarget(nodes: selectorParser.Node[]): boolean {\n let lastCharacter = '';\n for (const node of nodes.slice(1)) {\n if (node.type === 'combinator') {\n if (node.value.trim()) return true;\n // The affix renderer skips authored whitespace. Tags insert their own\n // separator; pseudos attach directly, and classes/attributes attach\n // after a tag, class, attribute or placeholder.\n continue;\n }\n if (node.type === 'tag' || node.type === 'universal') {\n if (lastCharacter) return true;\n } else if (node.type === 'class' || node.type === 'attribute') {\n if (lastCharacter && !/[\\]@a-zA-Z0-9-]/.test(lastCharacter)) return true;\n }\n lastCharacter = node.toString().trim().slice(-1);\n }\n return false;\n}\n\nfunction firstRootSelector(selector: string, key: string): string | null {\n try {\n const root = selectorParser().astSync(selector);\n for (const branch of root.nodes) {\n const nodes = branch.nodes.filter((node) => node.type !== 'comment');\n if (nodes[0]?.type !== 'nesting' || nodes.length < 2) continue;\n // An explicit placeholder creates a descendant selector even with an\n // ampersand prefix. A different trailing uppercase name injects the key\n // as its descendant; the sub-element's own name does not.\n if (\n nodes.some((node) => node.type === 'tag' && node.value.startsWith('@'))\n )\n continue;\n const trailingElement = branch\n .toString()\n .trim()\n .slice(1)\n .trim()\n .match(/(?:^|[\\s>+~\\]:])([A-Z][a-zA-Z0-9]*)$/);\n if (trailingElement && trailingElement[1] !== key) continue;\n // Follow Tasty's affix normalization, rather than CSS whitespace alone.\n // Nested :is() arguments do not change the outer selector's target.\n if (hasDescendantTarget(nodes)) continue;\n const hasPseudoElement = nodes.some((node) => {\n if (node.type !== 'pseudo') return false;\n let name = node.value.toLowerCase();\n if (name.startsWith('::')) return true;\n if (name.includes('\\\\')) {\n const identifier = selectorParser().astSync(name.slice(1)).first\n ?.first;\n if (identifier?.type === 'tag')\n name = ':' + identifier.value.toLowerCase();\n }\n return LEGACY_PSEUDO_ELEMENTS.has(name);\n });\n if (!hasPseudoElement) return branch.toString().trim();\n }\n } catch {\n // Invalid/incomplete selector text belongs to syntax validation.\n }\n return null;\n}\n\nexport default createRule<[], MessageIds>({\n name: 'valid-sub-element',\n meta: {\n type: 'problem',\n docs: {\n description:\n 'Validate sub-element values and prevent root-targeting affixes',\n },\n messages: {\n subElementNotObject:\n \"Sub-element '{{name}}' value must be a style object, not {{type}}.\",\n subElementTargetsRoot:\n \"Sub-element '{{name}}' selector '{{selector}}' styles the containing element instead of a sub-element. Use property state maps in that containing scope, or a descendant '$' selector such as 'h1'. Pseudo-elements such as '&::before' are allowed.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n const visited = new WeakSet<TSESTree.ObjectExpression>();\n\n function checkAffix(name: string, node: TSESTree.ObjectExpression) {\n for (const prop of node.properties) {\n if (prop.type !== 'Property') continue;\n const key = prop.computed\n ? getStringValue(unwrapExpression(prop.key))\n : getKeyName(prop.key);\n if (key !== '$') continue;\n const selector = getStringValue(unwrapExpression(prop.value));\n if (selector === null) continue;\n const rootSelector = firstRootSelector(selector, name);\n if (rootSelector === null) continue;\n context.report({\n node: prop.value,\n messageId: 'subElementTargetsRoot',\n data: { name, selector: rootSelector },\n });\n }\n }\n\n /**\n * What to name in the report when a value can never be a style object, or\n * `null` when it might be one or is `false` or `null`. Both disable the\n * sub-element, and in a later `mergeStyles` layer or a `styles` prop they\n * remove the one below; `undefined` (`void 0`) leaves it as it is.\n * A `const` binding is followed to what it names; any other binding, member\n * or call is opaque, and Tasty accepts a reference to a style object there.\n */\n function nonObjectType(\n node: TSESTree.Node,\n seen: Set<TSESTree.Node>,\n ): string | null {\n node = unwrapExpression(node);\n if (node.type === 'Literal') {\n if ('regex' in node && node.regex) return 'a regular expression';\n if (node.value === false || node.value === null) return null;\n return `a ${typeof node.value}`;\n }\n if (node.type === 'UnaryExpression' && node.operator === 'void') {\n return null;\n }\n if (node.type === 'Identifier') {\n if (seen.has(node)) return null;\n seen.add(node);\n let scope: ReturnType<typeof context.sourceCode.getScope> | null =\n context.sourceCode.getScope(node);\n while (scope && !scope.set.has(node.name)) scope = scope.upper;\n const variable = scope?.set.get(node.name);\n const def = variable?.defs.length === 1 ? variable.defs[0] : undefined;\n if (\n def?.type !== 'Variable' ||\n def.parent.kind !== 'const' ||\n !def.node.init\n ) {\n return null;\n }\n const init = unwrapExpression(def.node.init);\n return init.type === 'ObjectExpression'\n ? null\n : nonObjectType(init, seen);\n }\n return NON_OBJECT_EXPRESSIONS.get(node.type) ?? null;\n }\n\n // Recurse only through owned sub-elements. Some shared/JSX listeners match\n // just the root, and descriptor objects and state maps are not styles.\n function checkStyleObject(node: TSESTree.ObjectExpression) {\n if (visited.has(node)) return;\n visited.add(node);\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property') continue;\n\n const key = prop.computed\n ? getStringValue(unwrapExpression(prop.key))\n : getKeyName(prop.key);\n if (key === null || !/^[A-Z]/.test(key)) continue;\n\n const value = unwrapExpression(prop.value);\n if (value.type === 'ObjectExpression') {\n checkAffix(key, value);\n checkStyleObject(value);\n } else {\n const valueType = nonObjectType(value, new Set());\n if (valueType === null) continue;\n\n context.report({\n node: prop.value,\n messageId: 'subElementNotObject',\n data: { name: key, type: valueType },\n });\n }\n }\n }\n\n function handleStyleObject(node: TSESTree.ObjectExpression) {\n if (ctx.isStyleObject(node)) checkStyleObject(node);\n }\n\n return {\n ImportDeclaration(node) {\n ctx.trackImport(node);\n },\n ...styleObjectListeners(handleStyleObject),\n };\n },\n});\n"],"mappings":";;;;;;;AASA,MAAM,yBAAyB,IAAI,IAAoB;CACrD,CAAC,mBAAmB,WAAW;CAC/B,CAAC,mBAAmB,WAAW;CAC/B,CAAC,2BAA2B,aAAa;CACzC,CAAC,sBAAsB,aAAa;CACpC,CAAC,mBAAmB,UAAU;CAC9B,CAAC,mBAAmB,oBAAoB;CACxC,CAAC,oBAAoB,oBAAoB;CACzC,CAAC,oBAAoB,WAAW;CACjC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;CAEJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/eslint-plugin-tasty",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "ESLint plugin for validating tasty() and tastyStatic() style objects",
5
5
  "type": "module",
6
6
  "exports": {