Skip to content

Commit 89b982e

Browse files
committed
Merge branch 'fix/false-positive'
2 parents c2e0a67 + 89d2a93 commit 89b982e

File tree

5 files changed

+8972
-3256
lines changed

5 files changed

+8972
-3256
lines changed

src/rules/deprecatedProps.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ function getSymbol(id: TSESTree.Identifier, services: RequiredParserServices, tc
4646
return symbol;
4747
}
4848

49-
function getOpeningElement(nodes: Array<TSESTree.Node>): TSESTree.JSXOpeningElement | undefined {
50-
return nodes.find((node) => node.type === 'JSXOpeningElement') as TSESTree.JSXOpeningElement;
49+
function getOpeningElement(
50+
nodes: Array<TSESTree.Node>,
51+
name: string,
52+
): TSESTree.JSXOpeningElement | undefined {
53+
return nodes.find(
54+
(node) =>
55+
node.type === 'JSXOpeningElement' && (node.name as TSESTree.JSXIdentifier).name === name,
56+
) as TSESTree.JSXOpeningElement;
5157
}
5258

5359
function getSourceFileParent(node: ts.Node): ts.SourceFile | undefined {
@@ -87,7 +93,10 @@ export default {
8793
}
8894

8995
const ancestors = context.getAncestors();
90-
const openingJsxElement = getOpeningElement(ancestors);
96+
const openingJsxElement = getOpeningElement(
97+
ancestors,
98+
(node as TSESTree.JSXIdentifier).name,
99+
);
91100
const attributeElements =
92101
openingJsxElement?.attributes.filter((attribute) => attribute.type === 'JSXAttribute') ??
93102
[];

tests/integration/__tests__/avoid-deprecated.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ describe('avoidDeprecated', () => {
5151
});
5252
});
5353

54+
describe('when the component has a prop with the same name as a deprecated prop of one of its prop components', () => {
55+
let res: CLIEngine.LintReport;
56+
57+
beforeEach(() => {
58+
const file = path.resolve(__dirname, '../external-definition-false-positive.tsx');
59+
res = cli.executeOnFiles([file]);
60+
});
61+
62+
it('generates no warnings and errors', () => {
63+
const { warningCount, errorCount } = res.results[0]!;
64+
65+
expect(warningCount).toEqual(0);
66+
expect(errorCount).toEqual(0);
67+
});
68+
});
69+
5470
describe('when the component interface is in the same file', () => {
5571
let res: CLIEngine.LintReport;
5672

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Button, ButtonLink, Category, Dot, Icon } from '@drawbotics/react-drylus';
2+
import React from 'react';
3+
4+
export const Test = () => {
5+
return (
6+
<React.Fragment>
7+
<ButtonLink category={Category.BRAND} leading={<Icon name="plus" />}>
8+
New lead
9+
</ButtonLink>
10+
<Button category={Category.BRAND}>
11+
<Dot />
12+
</Button>
13+
</React.Fragment>
14+
);
15+
};

0 commit comments

Comments
 (0)