Skip to content

Commit

Permalink
Fix static propTypes handling in no-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzherdev committed Jun 14, 2018
1 parent c82746c commit f924414
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/rules/no-typos.js
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
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

0 comments on commit f924414

Please sign in to comment.