From 797f2e23eec3cf7134b7d8b97a1861de3ec513fc Mon Sep 17 00:00:00 2001 From: rendob <55734639+rendob@users.noreply.github.com> Date: Tue, 8 Apr 2025 22:34:13 +0900 Subject: [PATCH 1/2] feat: support satisfies operator in TypeScript --- lib/rules/classnames-order.js | 3 +++ lib/rules/enforces-negative-arbitrary-values.js | 3 +++ lib/rules/enforces-shorthand.js | 3 +++ lib/rules/migration-from-tailwind-2.js | 3 +++ lib/rules/no-arbitrary-value.js | 3 +++ lib/rules/no-unnecessary-arbitrary-value.js | 3 +++ lib/util/ast.js | 3 +++ 7 files changed, 21 insertions(+) diff --git a/lib/rules/classnames-order.js b/lib/rules/classnames-order.js index e7e35732..da630088 100644 --- a/lib/rules/classnames-order.js +++ b/lib/rules/classnames-order.js @@ -164,6 +164,9 @@ module.exports = { suffix = astUtil.getTemplateElementSuffix(txt, originalClassNamesValue); originalClassNamesValue = astUtil.getTemplateElementBody(txt, prefix, suffix); break; + case 'TSSatisfiesExpression': + sortNodeArgumentValue(node, arg.expression); + break; } } diff --git a/lib/rules/enforces-negative-arbitrary-values.js b/lib/rules/enforces-negative-arbitrary-values.js index 12189935..c409ab4a 100644 --- a/lib/rules/enforces-negative-arbitrary-values.js +++ b/lib/rules/enforces-negative-arbitrary-values.js @@ -126,6 +126,9 @@ module.exports = { return; } break; + case 'TSSatisfiesExpression': + parseForNegativeArbitraryClassNames(node, arg.expression); + return; } } diff --git a/lib/rules/enforces-shorthand.js b/lib/rules/enforces-shorthand.js index 61e84ac2..f0150986 100644 --- a/lib/rules/enforces-shorthand.js +++ b/lib/rules/enforces-shorthand.js @@ -233,6 +233,9 @@ module.exports = { suffix = astUtil.getTemplateElementSuffix(txt, originalClassNamesValue); originalClassNamesValue = astUtil.getTemplateElementBody(txt, prefix, suffix); break; + case 'TSSatisfiesExpression': + parseForShorthandCandidates(node, arg.expression); + return; } } diff --git a/lib/rules/migration-from-tailwind-2.js b/lib/rules/migration-from-tailwind-2.js index 5de0f0f7..a443b2e0 100644 --- a/lib/rules/migration-from-tailwind-2.js +++ b/lib/rules/migration-from-tailwind-2.js @@ -153,6 +153,9 @@ module.exports = { suffix = astUtil.getTemplateElementSuffix(txt, originalClassNamesValue); originalClassNamesValue = astUtil.getTemplateElementBody(txt, prefix, suffix); break; + case 'TSSatisfiesExpression': + parseForObsoleteClassNames(node, arg.expression); + return; } } diff --git a/lib/rules/no-arbitrary-value.js b/lib/rules/no-arbitrary-value.js index 71cf4595..d76dd8bb 100644 --- a/lib/rules/no-arbitrary-value.js +++ b/lib/rules/no-arbitrary-value.js @@ -126,6 +126,9 @@ module.exports = { return; } break; + case 'TSSatisfiesExpression': + parseForArbitraryValues(node, arg.expression); + return; } } diff --git a/lib/rules/no-unnecessary-arbitrary-value.js b/lib/rules/no-unnecessary-arbitrary-value.js index 58904f8a..2b414bcb 100644 --- a/lib/rules/no-unnecessary-arbitrary-value.js +++ b/lib/rules/no-unnecessary-arbitrary-value.js @@ -165,6 +165,9 @@ module.exports = { } } break; + case 'TSSatisfiesExpression': + parseForArbitraryValues(node, arg.expression); + return; } } diff --git a/lib/util/ast.js b/lib/util/ast.js index a6ed24d3..5dadc670 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -331,6 +331,9 @@ function parseNodeRecursive(rootNode, childNode, cb, skipConditional = false, is case 'TemplateElement': originalClassNamesValue = childNode.value.raw; break; + case 'TSSatisfiesExpression': + parseNodeRecursive(rootNode, childNode.expression, cb, skipConditional, isolate, ignoredKeys); + return; } ({ classNames } = extractClassnamesFromValue(originalClassNamesValue)); classNames = removeDuplicatesFromArray(classNames); From 4835647a322c0780c1aa5e7aecf3621c4ecf5f3d Mon Sep 17 00:00:00 2001 From: rendob <55734639+rendob@users.noreply.github.com> Date: Tue, 8 Apr 2025 22:35:05 +0900 Subject: [PATCH 2/2] test: add new case for satisfies operator --- package-lock.json | 14 ++++---- package.json | 2 +- tests/lib/rules/classnames-order.js | 36 +++++++++++++++++++ .../enforces-negative-arbitrary-values.js | 7 ++++ tests/lib/rules/enforces-shorthand.js | 14 ++++++++ tests/lib/rules/migration-from-tailwind-2.js | 13 +++++++ tests/lib/rules/no-arbitrary-value.js | 5 +++ tests/lib/rules/no-contradicting-classname.js | 23 ++++++++++++ tests/lib/rules/no-custom-classname.js | 20 +++++++++++ .../rules/no-unnecessary-arbitrary-value.js | 11 ++++++ 10 files changed, 137 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 08c57dd4..b1695406 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "mocha": "^10.2.0", "semver": "^7.6.0", "tailwindcss": "^3.4.0", - "typescript": "4.3.5", + "typescript": "4.9.5", "vue-eslint-parser": "^9.4.2" }, "engines": { @@ -2650,9 +2650,9 @@ } }, "node_modules/typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -4712,9 +4712,9 @@ "dev": true }, "typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true }, "uri-js": { diff --git a/package.json b/package.json index 85edb84e..207ceb1a 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "mocha": "^10.2.0", "semver": "^7.6.0", "tailwindcss": "^3.4.0", - "typescript": "4.3.5", + "typescript": "4.9.5", "vue-eslint-parser": "^9.4.2" }, "packageManager": "npm@10.2.5+sha256.8002e3e7305d2abd4016e1368af48d49b066c269079eeb10a56e7d6598acfdaa", diff --git a/tests/lib/rules/classnames-order.js b/tests/lib/rules/classnames-order.js index 032c1f46..190e1d01 100644 --- a/tests/lib/rules/classnames-order.js +++ b/tests/lib/rules/classnames-order.js @@ -327,6 +327,42 @@ ruleTester.run("classnames-order", rule, { parser: require.resolve("@typescript-eslint/parser"), errors: errors, }, + { + code: ` + export interface FakePropsInterface { + readonly name?: string; + } + function Fake({ + name = 'yolo' + }: FakeProps) { + return ( + <> +
Bye {name}
+ > + ); + } + export default Fake; + `, + output: ` + export interface FakePropsInterface { + readonly name?: string; + } + function Fake({ + name = 'yolo' + }: FakeProps) { + return ( + <> +Bye {name}
+ > + ); + } + export default Fake; + `, + parser: require.resolve("@typescript-eslint/parser"), + errors: errors, + }, { code: `