Skip to content

Commit

Permalink
Merge pull request #1828 from alexzherdev/1721-no-typos-create-class
Browse files Browse the repository at this point in the history
[New] `no-typos`: Support createClass
  • Loading branch information
ljharb committed Dec 28, 2018
2 parents e747459 + 7b70462 commit d2b5b73
Show file tree
Hide file tree
Showing 2 changed files with 323 additions and 111 deletions.
26 changes: 21 additions & 5 deletions lib/rules/no-typos.js
Expand Up @@ -124,15 +124,18 @@ module.exports = {
}
}

function reportErrorIfClassPropertyCasingTypo(node, propertyName) {
function reportErrorIfPropertyCasingTypo(node, propertyName, isClassProperty) {
if (propertyName === 'propTypes' || propertyName === 'contextTypes' || propertyName === 'childContextTypes') {
checkValidPropObject(node);
}
STATIC_CLASS_PROPERTIES.forEach(CLASS_PROP => {
if (propertyName && CLASS_PROP.toLowerCase() === propertyName.toLowerCase() && CLASS_PROP !== propertyName) {
const message = isClassProperty
? 'Typo in static class property declaration'
: 'Typo in property declaration';
context.report({
node: node,
message: 'Typo in static class property declaration'
message: message
});
}
});
Expand Down Expand Up @@ -175,7 +178,7 @@ module.exports = {

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

MemberExpression: function(node) {
Expand All @@ -195,16 +198,29 @@ module.exports = {
(utils.isES6Component(relatedComponent.node) || utils.isReturningJSX(relatedComponent.node)) &&
(node.parent && node.parent.type === 'AssignmentExpression' && node.parent.right)
) {
reportErrorIfClassPropertyCasingTypo(node.parent.right, propertyName);
reportErrorIfPropertyCasingTypo(node.parent.right, propertyName, true);
}
},

MethodDefinition: function (node) {
MethodDefinition: function(node) {
if (!utils.isES6Component(node.parent.parent)) {
return;
}

reportErrorIfLifecycleMethodCasingTypo(node);
},

ObjectExpression: function(node) {
const component = utils.isES5Component(node) && components.get(node);

if (!component) {
return;
}

node.properties.forEach(property => {
reportErrorIfPropertyCasingTypo(property.value, property.key.name, false);
reportErrorIfLifecycleMethodCasingTypo(property);
});
}
};
})
Expand Down

0 comments on commit d2b5b73

Please sign in to comment.