Skip to content

Commit 686ab89

Browse files
authored
Merge pull request #1375 from jseminck/more-robust-no-typos-fix
More robust no typos fix
2 parents 9805f70 + 5e25a5e commit 686ab89

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

lib/rules/no-typos.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ module.exports = {
117117
},
118118

119119
MemberExpression: function(node) {
120-
if (node.parent.type !== 'AssignmentExpression') {
121-
return;
122-
}
123-
124120
const relatedComponent = utils.getRelatedComponent(node);
125121

126122
if (

lib/util/Components.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,16 @@ function componentRule(rule, context) {
215215
* @returns {Boolean} True if the node is explicitly declared as a descendant of a React Component, false if not
216216
*/
217217
isExplicitComponent: function(node) {
218-
const comment = sourceCode.getJSDocComment(node);
218+
let comment;
219+
// Sometimes the passed node may not have been parsed yet by eslint, and this function call crashes.
220+
// Can be removed when eslint sets "parent" property for all nodes on initial AST traversal: https://github.com/eslint/eslint-scope/issues/27
221+
// eslint-disable-next-line no-warning-comments
222+
// FIXME: Remove try/catch when https://github.com/eslint/eslint-scope/issues/27 is implemented.
223+
try {
224+
comment = sourceCode.getJSDocComment(node);
225+
} catch (e) {
226+
comment = null;
227+
}
219228

220229
if (comment === null) {
221230
return false;

tests/lib/rules/no-typos.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ ruleTester.run('no-typos', rule, {
238238
'}'
239239
].join('\n'),
240240
parserOptions: parserOptions
241+
}, {
242+
// PropTypes declared on a component that is detected through JSDoc comments and is
243+
// declared AFTER the PropTypes assignment does not work.
244+
code: `
245+
MyComponent.PROPTYPES = {}
246+
/** @extends React.Component */
247+
class MyComponent extends BaseComponent {}
248+
`,
249+
parserOptions: parserOptions
241250
}, {
242251
// https://github.com/yannickcr/eslint-plugin-react/issues/1353
243252
code: `
@@ -513,6 +522,21 @@ ruleTester.run('no-typos', rule, {
513522
].join('\n'),
514523
parserOptions: parserOptions,
515524
errors: [{message: ERROR_MESSAGE}]
525+
}, {
526+
code: [
527+
'Component.defaultprops = {}',
528+
'class Component extends React.Component {}'
529+
].join('\n'),
530+
parserOptions: parserOptions,
531+
errors: [{message: ERROR_MESSAGE}]
532+
}, {
533+
code: `
534+
/** @extends React.Component */
535+
class MyComponent extends BaseComponent {}
536+
MyComponent.PROPTYPES = {}
537+
`,
538+
parserOptions: parserOptions,
539+
errors: [{message: ERROR_MESSAGE}]
516540
}, {
517541
code: [
518542
'class Hello extends React.Component {',

0 commit comments

Comments
 (0)