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

Already on GitHub? Sign in to your account

Fix static propTypes handling in no-typos #1827

Merged
merged 2 commits into from
Jun 15, 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: 5 additions & 5 deletions lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ module.exports = {

function reportErrorIfClassPropertyCasingTypo(node, propertyName) {
if (propertyName === 'propTypes' || propertyName === 'contextTypes' || propertyName === 'childContextTypes') {
const propsNode = node && node.parent && node.parent.type === 'AssignmentExpression' && node.parent.right;
checkValidPropObject(propsNode);
checkValidPropObject(node);
}
STATIC_CLASS_PROPERTIES.forEach(CLASS_PROP => {
if (propertyName && CLASS_PROP.toLowerCase() === propertyName.toLowerCase() && CLASS_PROP !== propertyName) {
Expand Down Expand Up @@ -176,7 +175,7 @@ module.exports = {

const tokens = context.getFirstTokens(node, 2);
const propertyName = tokens[1].value;
reportErrorIfClassPropertyCasingTypo(node, propertyName);
reportErrorIfClassPropertyCasingTypo(node.value, propertyName);
},

MemberExpression: function(node) {
Expand All @@ -193,9 +192,10 @@ module.exports = {

if (
relatedComponent &&
(utils.isES6Component(relatedComponent.node) || utils.isReturningJSX(relatedComponent.node))
(utils.isES6Component(relatedComponent.node) || utils.isReturningJSX(relatedComponent.node)) &&
(node.parent && node.parent.type === 'AssignmentExpression' && node.parent.right)
) {
reportErrorIfClassPropertyCasingTypo(node, propertyName);
reportErrorIfClassPropertyCasingTypo(node.parent.right, propertyName);
}
},

Expand Down
28 changes: 28 additions & 0 deletions tests/lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,34 @@ ruleTester.run('no-typos', rule, {
errors: [{
message: 'Typo in prop type chain qualifier: isrequired'
}]
}, {
code: `
import PropTypes from "prop-types";
class Component extends React.Component {
static propTypes = {
a: PropTypes.number.isrequired
}
};
`,
parser: 'babel-eslint',
parserOptions: parserOptions,
errors: [{
message: 'Typo in prop type chain qualifier: isrequired'
}]
}, {
code: `
import PropTypes from "prop-types";
class Component extends React.Component {
static propTypes = {
a: PropTypes.Number
}
};
`,
parser: 'babel-eslint',
parserOptions: parserOptions,
errors: [{
message: 'Typo in declared prop type: Number'
}]
}, {
code: `
import PropTypes from "prop-types";
Expand Down