Skip to content

Commit

Permalink
Exit early for MemberExpressions if the property name doesn't match w…
Browse files Browse the repository at this point in the history
…hat we are checking for
  • Loading branch information
Joachim Seminck committed Aug 29, 2017
1 parent e2f6460 commit 4eb6b30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ module.exports = {
},

MemberExpression: function(node) {
const propertyName = node.property.name;

if (
!propertyName ||
STATIC_CLASS_PROPERTIES.map(prop => prop.toLocaleLowerCase()).indexOf(propertyName.toLowerCase()) === -1
) {
return;
}

const relatedComponent = utils.getRelatedComponent(node);

if (
relatedComponent &&
(utils.isES6Component(relatedComponent.node) || utils.isReturningJSX(relatedComponent.node))
) {
const propertyName = node.property.name;
reportErrorIfClassPropertyCasingTypo(node, propertyName);
}
},
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ ruleTester.run('no-typos', rule, {
`,
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
code: `
const fn = (err, res) => {
const { body: data = {} } = { ...res };
data.time = data.time || {};
};
`,
parser: 'babel-eslint'
}],

invalid: [{
Expand Down

0 comments on commit 4eb6b30

Please sign in to comment.