Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle TSTypeReference in no-unused-prop-types #3195

Merged
merged 1 commit into from Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`prop-types`], `propTypes`: add support for exported type inference ([#3163][] @vedadeepta)
* [`no-invalid-html-attribute`]: allow 'shortcut icon' on `link` ([#3174][] @Primajin)
* [`prefer-exact-props`] improve performance for `Identifier` visitor ([#3190][] @meowtec)
* `propTypes`: Handle TSTypeReference in no-unused-prop-type ([#3195][] @niik)

### Changed
* [readme] change [`jsx-runtime`] link from branch to sha ([#3160][] @tatsushitoji)
Expand All @@ -23,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [Docs] [`display-name`]: improve examples ([#3189][] @golopot)
* [Refactor] [`no-invalid-html-attribute`]: sort HTML_ELEMENTS and messages ([#3182][] @Primajin)

[#3195]: https://github.com/yannickcr/eslint-plugin-react/pull/3195
[#3191]: https://github.com/yannickcr/eslint-plugin-react/pull/3191
[#3190]: https://github.com/yannickcr/eslint-plugin-react/pull/3190
[#3189]: https://github.com/yannickcr/eslint-plugin-react/pull/3189
Expand Down
1 change: 1 addition & 0 deletions lib/util/propTypes.js
Expand Up @@ -967,6 +967,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
ignorePropsValidation = true;
}
break;
case 'TSTypeReference':
case 'TSTypeAnnotation': {
const tsTypeAnnotation = new DeclarePropTypesForTSTypeAnnotation(propTypes, declaredPropTypes);
ignorePropsValidation = tsTypeAnnotation.shouldIgnorePropTypes;
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -6486,6 +6486,23 @@ ruleTester.run('no-unused-prop-types', rule, {
};
`,
errors: [{ message: '\'foo\' PropType is defined but prop is never used' }],
},

{
code: `
interface Props {
readonly firstname: string;
readonly lastname: string;
}

class TestComponent extends React.Component<Props> {
public render() {
return <div>{this.props.firstname}</div>;
}
}
`,
features: ['ts', 'no-babel'],
errors: [{ message: '\'lastname\' PropType is defined but prop is never used' }],
}
)),
});