Skip to content

Commit 4bdf577

Browse files
fix: local-rules/no-override-ds-component were not riggered correcly due to incorrect configuration
1 parent 2da308d commit 4bdf577

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

.eslintrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,9 @@ module.exports = {
300300
'error',
301301
{ blankLine: 'always', prev: '*', next: 'return' },
302302
],
303-
'local-rules/no-override-ds-component': ['error', { packageName: '@trezor/components' }],
304303
'local-rules/no-override-ds-component': [
305304
'error',
306-
{ packageName: '@trezor/product-components' },
305+
{ packageNames: ['@trezor/product-components', '@trezor/components'] },
307306
],
308307
},
309308
overrides: [

eslint-local-rules/rules.ts

+29-17
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,36 @@ export default {
1919
{
2020
type: 'object',
2121
properties: {
22-
packageName: {
23-
type: 'string',
22+
packageNames: {
23+
type: 'array',
24+
items: { type: 'string' },
25+
minItems: 1,
2426
},
2527
},
26-
additionalProperties: false,
28+
// additionalProperties: false,
2729
},
2830
],
2931
},
3032
create(context) {
31-
const packageName = context.options[0] && context.options[0].packageName;
32-
if (!packageName) {
33+
const packageNames = context.options[0]?.packageNames || [];
34+
if (packageNames.length === 0) {
3335
return {};
3436
}
3537

36-
const importedComponents = new Set();
38+
const importedComponents = new Map<string, Set<string>>(); // Map to store components per package name
3739

3840
return {
3941
ImportDeclaration(node) {
40-
if (node.source.value === packageName) {
42+
if (packageNames.includes(node.source.value)) {
4143
node.specifiers.forEach(specifier => {
4244
if (
4345
specifier.type === 'ImportSpecifier' ||
4446
specifier.type === 'ImportDefaultSpecifier'
4547
) {
46-
importedComponents.add(specifier.local.name);
48+
if (!importedComponents.has(node.source.value)) {
49+
importedComponents.set(node.source.value, new Set<string>());
50+
}
51+
importedComponents.get(node.source.value).add(specifier.local.name);
4752
}
4853
});
4954
}
@@ -52,16 +57,23 @@ export default {
5257
if (
5358
node.tag.type === 'CallExpression' &&
5459
node.tag.callee.name === 'styled' &&
55-
node.tag.arguments[0].type === 'Identifier' &&
56-
importedComponents.has(node.tag.arguments[0].name)
60+
node.tag.arguments[0].type === 'Identifier'
5761
) {
58-
context.report({
59-
node,
60-
messageId: 'avoidStyledComponent',
61-
data: {
62-
packageName,
63-
},
64-
});
62+
const componentName = node.tag.arguments[0].name;
63+
64+
// Check if component name matches any imported component from the specified packages
65+
for (const [pkgName, components] of importedComponents) {
66+
if (components.has(componentName)) {
67+
context.report({
68+
node,
69+
messageId: 'avoidStyledComponent',
70+
data: {
71+
packageName: pkgName,
72+
},
73+
});
74+
break;
75+
}
76+
}
6577
}
6678
},
6779
};

packages/connect-explorer/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
extensions: ['.tsx', '.mdx'],
1414
},
1515
],
16+
'local-rules/no-override-ds-component': 'off', // To not show errors in *.mdx example files
1617
},
1718
extends: ['plugin:mdx/recommended'],
1819
};

packages/connect-explorer/src/components/GuideIndex.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Card as TrezorCard, H3, Paragraph, Button } from '@trezor/components';
66
import styled from 'styled-components';
77
import { spacingsPx } from '@trezor/theme';
88

9+
// eslint-disable-next-line local-rules/no-override-ds-component
910
const SectionCard = styled(TrezorCard)`
1011
margin-bottom: ${spacingsPx.xl};
1112
`;

packages/suite/src/views/wallet/coinmarket/common/CoinmarketDetail/CoinmarketDetailExchange/CoinmarketDetailExchangePaymentKYC.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const Description = styled.div`
3333
text-align: center;
3434
`;
3535

36+
// eslint-disable-next-line local-rules/no-override-ds-component
3637
const LinkWrapper = styled(Link)`
3738
margin-top: ${spacingsPx.xxs};
3839
margin-bottom: ${spacingsPx.lg};

packages/suite/src/views/wallet/coinmarket/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const CoinmarketFormOfferSpinnerText = styled.div`
111111
text-align: center;
112112
`;
113113

114+
// eslint-disable-next-line local-rules/no-override-ds-component
114115
export const CoinmarketSpinnerWrapper = styled(Spinner)`
115116
flex: none;
116117
margin: 0 ${spacingsPx.xs};

0 commit comments

Comments
 (0)