Clean-up based on feedback

Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
Andre Wanlin
2024-01-13 15:05:12 -06:00
parent aeed5347e1
commit b07ff647d6
2 changed files with 8 additions and 23 deletions
@@ -7,12 +7,12 @@ Forbid top level import from Material UI v4 packages.
Add the rules as follows, it has no options:
```js
"@backstage/no-top-level-material-ui-4-imports": ["error"]
'@backstage/no-top-level-material-ui-4-imports': 'error'
```
## Rule Details
TBD - Not sure what should go here
Automatically fixes imports from named to default imports. This will help you comply with [Material UI recommendations](https://mui.com/material-ui/guides/minimizing-bundle-size/) and make migrating to Material UI v5 easier.
### Fail
@@ -57,19 +57,8 @@ module.exports = {
// Return if import is from '@material-ui/core/styles', as it's valid already
if (node.source.value === '@material-ui/core/styles') return;
// Return if proper import eg. `import Box from '@material-ui/core/Box'`
if (
node.specifiers.length >= 1 &&
node.source.value?.split('/').length === 3
)
return;
// Return if third level or deeper imports
if (
node.specifiers.length >= 1 &&
node.source.value.split('/').length > 3
) {
return;
}
// Or if third level or deeper imports
if (node.source.value?.split('/').length >= 3) return;
// Report all other imports
context.report({
@@ -84,17 +73,13 @@ module.exports = {
);
const specifiersMap = specifiers.map(s => {
const propsTest = /^([A-Z]\w+)Props$/.test(s.local.name);
const propsMatch = /^([A-Z]\w+)Props$/.exec(s.local.name);
let propValue;
if (propsMatch) {
propValue = propsMatch[1];
}
return {
emitComponent: !propsTest,
emitProp: propsTest,
emitComponent: !(propsMatch !== null),
emitProp: propsMatch !== null,
value: s.local.name,
propValue,
propValue: propsMatch ? propsMatch[1] : undefined,
};
});