Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-09-27 15:06:36 +02:00
parent 871a660643
commit 63963f6c2b
3 changed files with 37 additions and 27 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/eslint-plugin': patch
---
Internal refactor to deal with `estree` upgrade
@@ -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,
},
];
},
);
+4 -11
View File
@@ -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"