From 63963f6c2b8e1394efa78a66d9b7865978d9c5a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Fri, 27 Sep 2024 15:06:36 +0200 Subject: [PATCH] fixup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/famous-bobcats-remain.md | 5 +++ .../no-top-level-material-ui-4-imports.js | 44 ++++++++++++------- yarn.lock | 15 ++----- 3 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 .changeset/famous-bobcats-remain.md diff --git a/.changeset/famous-bobcats-remain.md b/.changeset/famous-bobcats-remain.md new file mode 100644 index 0000000000..6943eb7e56 --- /dev/null +++ b/.changeset/famous-bobcats-remain.md @@ -0,0 +1,5 @@ +--- +'@backstage/eslint-plugin': patch +--- + +Internal refactor to deal with `estree` upgrade diff --git a/packages/eslint-plugin/rules/no-top-level-material-ui-4-imports.js b/packages/eslint-plugin/rules/no-top-level-material-ui-4-imports.js index 78fd3d63e9..6e0ba9ee87 100644 --- a/packages/eslint-plugin/rules/no-top-level-material-ui-4-imports.js +++ b/packages/eslint-plugin/rules/no-top-level-material-ui-4-imports.js @@ -80,11 +80,14 @@ const KNOWN_STYLES = [ /** * filter function to keep only ImportSpecifier nodes - * @param {import('estree').ImportSpecifier | import('estree').ImportDefaultSpecifier| import('estree').ImportNamespaceSpecifier} specifier + * @param {import('estree').ImportSpecifier | import('estree').ImportDefaultSpecifier | import('estree').ImportNamespaceSpecifier} specifier * @returns {specifier is import('estree').ImportSpecifier} */ function importSpecifiersFilter(specifier) { - return specifier.type === 'ImportSpecifier'; + return ( + specifier.type === 'ImportSpecifier' && + specifier.imported.type !== 'Literal' + ); } /** @@ -146,12 +149,16 @@ module.exports = { const specifiers = node.specifiers.filter(importSpecifiersFilter); - const specifiersMap = specifiers.map( + const specifiersMap = specifiers.flatMap( /** * transform ImportSpecifier to FixerValues to have a simpler object to work with - * @returns {FixerValues} + * @returns {FixerValues[]} */ s => { + if (s.imported.type === 'Literal') { + return []; + } + const value = s.imported.name; const alias = s.local.name === value ? undefined : s.local.name; @@ -165,19 +172,24 @@ module.exports = { const emitComponent = !emitProp; const emitComponentAndProp = emitProp && - specifiers.find(s => s.imported.name === propsMatch[1])?.local - .name; + specifiers.find( + s => + s.imported.type !== 'Literal' && + s.imported.name === propsMatch[1], + )?.local.name; - return { - emitComponent: emitComponent || Boolean(emitComponentAndProp), - emitProp, - value, - componentValue: propsMatch ? propsMatch[1] : undefined, - componentAlias: emitComponentAndProp - ? emitComponentAndProp - : undefined, - alias, - }; + return [ + { + emitComponent: emitComponent || Boolean(emitComponentAndProp), + emitProp, + value, + componentValue: propsMatch ? propsMatch[1] : undefined, + componentAlias: emitComponentAndProp + ? emitComponentAndProp + : undefined, + alias, + }, + ]; }, ); diff --git a/yarn.lock b/yarn.lock index 21ea1f81dc..c662e0492f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17434,10 +17434,10 @@ __metadata: languageName: node linkType: hard -"@types/estree@npm:*, @types/estree@npm:^1.0.0, @types/estree@npm:^1.0.5": - version: 1.0.5 - resolution: "@types/estree@npm:1.0.5" - checksum: dd8b5bed28e6213b7acd0fb665a84e693554d850b0df423ac8076cc3ad5823a6bc26b0251d080bdc545af83179ede51dd3f6fa78cad2c46ed1f29624ddf3e41a +"@types/estree@npm:*, @types/estree@npm:1.0.6, @types/estree@npm:^1.0.0, @types/estree@npm:^1.0.5": + version: 1.0.6 + resolution: "@types/estree@npm:1.0.6" + checksum: 8825d6e729e16445d9a1dd2fb1db2edc5ed400799064cd4d028150701031af012ba30d6d03fe9df40f4d7a437d0de6d2b256020152b7b09bde9f2e420afdffd9 languageName: node linkType: hard @@ -17448,13 +17448,6 @@ __metadata: languageName: node linkType: hard -"@types/estree@npm:1.0.6": - version: 1.0.6 - resolution: "@types/estree@npm:1.0.6" - checksum: 8825d6e729e16445d9a1dd2fb1db2edc5ed400799064cd4d028150701031af012ba30d6d03fe9df40f4d7a437d0de6d2b256020152b7b09bde9f2e420afdffd9 - languageName: node - linkType: hard - "@types/expect@npm:^1.20.4": version: 1.20.4 resolution: "@types/expect@npm:1.20.4"