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

Support createClass in no-typos #1828

Merged
merged 1 commit into from Dec 28, 2018
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
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'
Copy link
Member

Choose a reason for hiding this comment

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

i think it's fine to have different messages, but "static class property" is a conceptual term prior to the feature landing in the language, so i think that'd be reasonable.

: '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