@tenphi/eslint-plugin-tasty 1.7.0 → 1.7.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRule } from "../create-rule.js";
|
|
2
2
|
import { collectLocalStateAliases, getKeyName, getStringValue, isKnownStateAlias } from "../utils.js";
|
|
3
3
|
import { TastyContext, styleObjectListeners } from "../context.js";
|
|
4
|
+
import { parseStateKey } from "../parsers/state-key-parser.js";
|
|
4
5
|
|
|
5
6
|
//#region src/rules/no-unknown-state-alias.ts
|
|
6
7
|
var no_unknown_state_alias_default = createRule({
|
|
@@ -18,12 +19,16 @@ var no_unknown_state_alias_default = createRule({
|
|
|
18
19
|
for (const prop of obj.properties) {
|
|
19
20
|
if (prop.type !== "Property") continue;
|
|
20
21
|
const key = !prop.computed ? getKeyName(prop.key) : getStringValue(prop.key);
|
|
21
|
-
if (key === null || !key.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (key === null || !key.includes("@")) continue;
|
|
23
|
+
const { referencedAliases } = parseStateKey(key);
|
|
24
|
+
for (const alias of new Set(referencedAliases)) {
|
|
25
|
+
if (isKnownStateAlias(alias, ctx.config) || localAliases.includes(alias)) continue;
|
|
26
|
+
context.report({
|
|
27
|
+
node: prop.key,
|
|
28
|
+
messageId: "unknownAlias",
|
|
29
|
+
data: { alias }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
function handleStyleObject(node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unknown-state-alias.js","names":[],"sources":["../../src/rules/no-unknown-state-alias.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext, styleObjectListeners } from '../context.js';\nimport {\n getKeyName,\n getStringValue,\n isKnownStateAlias,\n collectLocalStateAliases,\n} from '../utils.js';\n\ntype MessageIds = 'unknownAlias';\n\nexport default createRule<[], MessageIds>({\n name: 'no-unknown-state-alias',\n meta: {\n type: 'suggestion',\n docs: {\n description:\n \"Warn when a @name state alias is used that isn't in the config\",\n },\n messages: {\n unknownAlias:\n \"Unknown state alias '{{alias}}'. Add it to 'states' in your tasty config, or define it locally as a '@name' key.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n\n function checkStateKeys(\n obj: TSESTree.ObjectExpression,\n localAliases: string[],\n ): void {\n for (const prop of obj.properties) {\n if (prop.type !== 'Property') continue;\n\n const key = !prop.computed\n ? getKeyName(prop.key)\n : getStringValue(prop.key);\n if (key === null || !key.
|
|
1
|
+
{"version":3,"file":"no-unknown-state-alias.js","names":[],"sources":["../../src/rules/no-unknown-state-alias.ts"],"sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport { createRule } from '../create-rule.js';\nimport { TastyContext, styleObjectListeners } from '../context.js';\nimport {\n getKeyName,\n getStringValue,\n isKnownStateAlias,\n collectLocalStateAliases,\n} from '../utils.js';\nimport { parseStateKey } from '../parsers/state-key-parser.js';\n\ntype MessageIds = 'unknownAlias';\n\nexport default createRule<[], MessageIds>({\n name: 'no-unknown-state-alias',\n meta: {\n type: 'suggestion',\n docs: {\n description:\n \"Warn when a @name state alias is used that isn't in the config\",\n },\n messages: {\n unknownAlias:\n \"Unknown state alias '{{alias}}'. Add it to 'states' in your tasty config, or define it locally as a '@name' key.\",\n },\n schema: [],\n },\n defaultOptions: [],\n create(context) {\n const ctx = new TastyContext(context);\n\n function checkStateKeys(\n obj: TSESTree.ObjectExpression,\n localAliases: string[],\n ): void {\n for (const prop of obj.properties) {\n if (prop.type !== 'Property') continue;\n\n const key = !prop.computed\n ? getKeyName(prop.key)\n : getStringValue(prop.key);\n if (key === null || !key.includes('@')) continue;\n\n // Aliases can appear anywhere in a compound key ('@a | b', 'b & @a')\n const { referencedAliases } = parseStateKey(key);\n for (const alias of new Set(referencedAliases)) {\n if (\n isKnownStateAlias(alias, ctx.config) ||\n localAliases.includes(alias)\n ) {\n continue;\n }\n\n context.report({\n node: prop.key,\n messageId: 'unknownAlias',\n data: { alias },\n });\n }\n }\n }\n\n function handleStyleObject(node: TSESTree.ObjectExpression) {\n if (!ctx.isStyleObject(node)) return;\n\n const rootObj = ctx.getRootStyleObject(node);\n const localAliases = collectLocalStateAliases(rootObj);\n\n // Skip if no states configured and no local aliases\n if (ctx.config.states.length === 0 && localAliases.length === 0) return;\n\n for (const prop of node.properties) {\n if (prop.type !== 'Property' || prop.computed) continue;\n\n // Skip sub-elements and special keys\n const key = getKeyName(prop.key);\n if (key === null || /^[A-Z@&]/.test(key)) continue;\n\n // Check state map objects for unknown aliases\n if (prop.value.type === 'ObjectExpression') {\n checkStateKeys(prop.value, localAliases);\n }\n }\n }\n\n return {\n ImportDeclaration(node) {\n ctx.trackImport(node);\n },\n ...styleObjectListeners(handleStyleObject),\n };\n },\n});\n"],"mappings":";;;;;;AAaA,qCAAe,WAA2B;CACxC,MAAM;CACN,MAAM;EACJ,MAAM;EACN,MAAM,EACJ,aACE,kEACH;EACD,UAAU,EACR,cACE,oHACH;EACD,QAAQ,EAAE;EACX;CACD,gBAAgB,EAAE;CAClB,OAAO,SAAS;EACd,MAAM,MAAM,IAAI,aAAa,QAAQ;EAErC,SAAS,eACP,KACA,cACM;AACN,QAAK,MAAM,QAAQ,IAAI,YAAY;AACjC,QAAI,KAAK,SAAS,WAAY;IAE9B,MAAM,MAAM,CAAC,KAAK,WACd,WAAW,KAAK,IAAI,GACpB,eAAe,KAAK,IAAI;AAC5B,QAAI,QAAQ,QAAQ,CAAC,IAAI,SAAS,IAAI,CAAE;IAGxC,MAAM,EAAE,sBAAsB,cAAc,IAAI;AAChD,SAAK,MAAM,SAAS,IAAI,IAAI,kBAAkB,EAAE;AAC9C,SACE,kBAAkB,OAAO,IAAI,OAAO,IACpC,aAAa,SAAS,MAA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