Skip to content

support for custom propTypes with isRequired in no-typos #1652

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ module.exports = {
if (node && node.type === 'MemberExpression' && node.object.type === 'MemberExpression') {
checkValidPropType(node.object.property);
checkValidPropTypeQualfier(node.property);
} else if (node && node.type === 'MemberExpression' && node.object.type === 'Identifier') {
} else if (node && node.type === 'MemberExpression' && node.object.type === 'Identifier' && node.property.name !== 'isRequired') {
checkValidPropType(node.property);
} else if (node && node.type === 'CallExpression') {
} else if (node && (
node.type === 'MemberExpression' && node.object.type === 'CallExpression' || node.type === 'CallExpression'
)) {
if (node.type === 'MemberExpression') {
checkValidPropTypeQualfier(node.property);
node = node.object;
}
const callee = node.callee;
if (callee.type === 'MemberExpression' && callee.property.name === 'shape') {
checkValidPropObject(node.arguments[0]);
Expand Down
35 changes: 35 additions & 0 deletions tests/lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ ruleTester.run('no-typos', rule, {
};
`,
parser: 'babel-eslint'
}, {
code: `class Component extends React.Component {};
Component.propTypes = {
b: string.isRequired,
c: PropTypes.shape({
d: number.isRequired,
}).isRequired
}
`,
parser: 'babel-eslint',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add another test like this that uses the default parser

parserOptions: parserOptions
}],

invalid: [{
Expand Down Expand Up @@ -795,5 +806,29 @@ ruleTester.run('no-typos', rule, {
}, {
message: 'Typo in declared prop type: objectof'
}]
}, {
code: `class Component extends React.Component {};
Component.propTypes = {
b: string.isrequired
}
`,
parser: 'babel-eslint',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with these 2 tests; please duplicate them so there's 1 for babel-eslint and 1 for the default parser.

parserOptions: parserOptions,
errors: [{
message: 'Typo in declared prop type: isrequired'
}]
}, {
code: `class Component extends React.Component {};
Component.propTypes = {
c: shape({
d: number,
}).isrequired
}
`,
parser: 'babel-eslint',
parserOptions: parserOptions,
errors: [{
message: 'Typo in prop type chain qualifier: isrequired'
}]
}]
});