Skip to content

Commit

Permalink
Merge branch 'fix/false-positive'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicmosc committed May 6, 2020
2 parents c2e0a67 + 89d2a93 commit 89b982e
Show file tree
Hide file tree
Showing 5 changed files with 8,972 additions and 3,256 deletions.
15 changes: 12 additions & 3 deletions src/rules/deprecatedProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ function getSymbol(id: TSESTree.Identifier, services: RequiredParserServices, tc
return symbol;
}

function getOpeningElement(nodes: Array<TSESTree.Node>): TSESTree.JSXOpeningElement | undefined {
return nodes.find((node) => node.type === 'JSXOpeningElement') as TSESTree.JSXOpeningElement;
function getOpeningElement(
nodes: Array<TSESTree.Node>,
name: string,
): TSESTree.JSXOpeningElement | undefined {
return nodes.find(
(node) =>
node.type === 'JSXOpeningElement' && (node.name as TSESTree.JSXIdentifier).name === name,
) as TSESTree.JSXOpeningElement;
}

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

const ancestors = context.getAncestors();
const openingJsxElement = getOpeningElement(ancestors);
const openingJsxElement = getOpeningElement(
ancestors,
(node as TSESTree.JSXIdentifier).name,
);
const attributeElements =
openingJsxElement?.attributes.filter((attribute) => attribute.type === 'JSXAttribute') ??
[];
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/__tests__/avoid-deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ describe('avoidDeprecated', () => {
});
});

describe('when the component has a prop with the same name as a deprecated prop of one of its prop components', () => {
let res: CLIEngine.LintReport;

beforeEach(() => {
const file = path.resolve(__dirname, '../external-definition-false-positive.tsx');
res = cli.executeOnFiles([file]);
});

it('generates no warnings and errors', () => {
const { warningCount, errorCount } = res.results[0]!;

expect(warningCount).toEqual(0);
expect(errorCount).toEqual(0);
});
});

describe('when the component interface is in the same file', () => {
let res: CLIEngine.LintReport;

Expand Down
15 changes: 15 additions & 0 deletions tests/integration/external-definition-false-positive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Button, ButtonLink, Category, Dot, Icon } from '@drawbotics/react-drylus';
import React from 'react';

export const Test = () => {
return (
<React.Fragment>
<ButtonLink category={Category.BRAND} leading={<Icon name="plus" />}>
New lead
</ButtonLink>
<Button category={Category.BRAND}>
<Dot />
</Button>
</React.Fragment>
);
};
Loading

0 comments on commit 89b982e

Please sign in to comment.