From 334556429dc2f976c669d0662654056ab0876e90 Mon Sep 17 00:00:00 2001 From: "ala'n (Alexey Stsefanovich)" Date: Thu, 26 Sep 2024 21:49:46 +0200 Subject: [PATCH] fix(lint): fix Literal import processing & update eslint 9.11.1 --- eslint/src/core/deprecated-alias.ts | 4 +++- eslint/src/core/deprecated-path.ts | 2 ++ package-lock.json | 36 +++++++++++++++-------------- package.json | 2 +- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/eslint/src/core/deprecated-alias.ts b/eslint/src/core/deprecated-alias.ts index d8b2e2ada..aa8f721dc 100644 --- a/eslint/src/core/deprecated-alias.ts +++ b/eslint/src/core/deprecated-alias.ts @@ -27,7 +27,7 @@ export function buildRule({deprecation, alias}: ESLintDeprecationCfg): Rule.Rule const create = (context: Rule.RuleContext): Rule.RuleListener => ({ ImportSpecifier(node: ImportNode): null { const importedValue = node.imported; - if (importedValue.name === deprecation) { + if (importedValue.type === 'Identifier' && importedValue.name === deprecation) { context.report({ node, message: `[ESL Lint]: Deprecated alias ${deprecation} for ${alias}`, @@ -61,6 +61,8 @@ function buildFixer(node: ImportNode, context: Rule.RuleContext, alias: string): // eslint-disable-next-line sonarjs/cognitive-complexity function getIdentifierRanges(importNode: ImportNode, context: Rule.RuleContext): (AST.Range | undefined)[] { const root = findRoot(importNode); + if (importNode.imported.type !== 'Identifier' || !root) return []; + const {name} = importNode.imported; const identifiers = findAllBy(context, root, {type: 'Identifier', name}); diff --git a/eslint/src/core/deprecated-path.ts b/eslint/src/core/deprecated-path.ts index 2d69fb74b..393da7bb2 100644 --- a/eslint/src/core/deprecated-path.ts +++ b/eslint/src/core/deprecated-path.ts @@ -26,6 +26,8 @@ export function buildRule(configs: ESLintDeprecationImportCfg | ESLintDeprecatio const create = (context: Rule.RuleContext): Rule.RuleListener => ({ ImportSpecifier(node: ImportNode): null { const importedValue = node.imported; + if (importedValue.type !== 'Identifier') return null; + const importedSource = (node.parent as ESTree.ImportDeclaration).source.value; for (const cfg of configs) { diff --git a/package-lock.json b/package-lock.json index 711e751c6..27121f8fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,7 @@ "concurrently": "^9.0.1", "copyfiles": "^2.4.1", "cross-env": "^7.0.3", - "eslint": "^9.11.0", + "eslint": "^9.11.1", "eslint-plugin-editorconfig": "^4.0.3", "eslint-plugin-import-x": "^4.3.0", "eslint-plugin-sonarjs": "^1.0.4", @@ -1392,6 +1392,14 @@ "node": "*" } }, + "node_modules/@eslint/core": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.6.0.tgz", + "integrity": "sha512-8I2Q8ykA4J0x0o7cg67FPVnehcqWTBehu/lmY+bolPFHGjh49YzGBMXTvpqVgEbBdvNCSxj6iFgiIyHzf03lzg==", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/eslintrc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", @@ -1463,7 +1471,6 @@ "version": "9.11.1", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.1.tgz", "integrity": "sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA==", - "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -3930,9 +3937,9 @@ } }, "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==" + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==" }, "node_modules/@types/graceful-fs": { "version": "4.1.9", @@ -7819,19 +7826,22 @@ } }, "node_modules/eslint": { - "version": "9.11.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.0.tgz", - "integrity": "sha512-yVS6XODx+tMFMDFcG4+Hlh+qG7RM6cCJXtQhCKLSsr3XkLvWggHjCqjfh0XsPPnt1c56oaT6PMgW9XWQQjdHXA==", + "version": "9.11.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.1.tgz", + "integrity": "sha512-MobhYKIoAO1s1e4VUrgx1l1Sk2JBR/Gqjjgw8+mfgoLE2xwsHur4gdfTxyTgShrhvdVFTaJSgMiQBl1jv/AWxg==", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", + "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.0", + "@eslint/js": "9.11.1", "@eslint/plugin-kit": "^0.2.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -8356,14 +8366,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/@eslint/js": { - "version": "9.11.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.0.tgz", - "integrity": "sha512-LPkkenkDqyzTFauZLLAPhIb48fj6drrfMvRGSL9tS3AcZBSVTllemLSNyCvHNNL2t797S/6DJNSIwRwXgMO/eQ==", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - } - }, "node_modules/eslint/node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", diff --git a/package.json b/package.json index 461befe87..e82ebd8b2 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "concurrently": "^9.0.1", "copyfiles": "^2.4.1", "cross-env": "^7.0.3", - "eslint": "^9.11.0", + "eslint": "^9.11.1", "eslint-plugin-editorconfig": "^4.0.3", "eslint-plugin-import-x": "^4.3.0", "eslint-plugin-sonarjs": "^1.0.4",