diff --git a/lib/rules/no-typos.js b/lib/rules/no-typos.js index b85db837ef..f9c798a9fb 100644 --- a/lib/rules/no-typos.js +++ b/lib/rules/no-typos.js @@ -155,8 +155,9 @@ module.exports = { if (node.source && node.source.value === 'prop-types') { // import PropType from "prop-types" propTypesPackageName = node.specifiers[0].local.name; } else if (node.source && node.source.value === 'react') { // import { PropTypes } from "react" - reactPackageName = node.specifiers[0].local.name; - + if (node.specifiers.length > 0) { + reactPackageName = node.specifiers[0].local.name; // guard against accidental anonymous `import "react"` + } if (node.specifiers.length >= 1) { const propTypesSpecifier = node.specifiers.find(specifier => ( specifier.imported && specifier.imported.name === 'PropTypes' diff --git a/tests/lib/rules/no-typos.js b/tests/lib/rules/no-typos.js index a7b9b02a11..0123327e1c 100644 --- a/tests/lib/rules/no-typos.js +++ b/tests/lib/rules/no-typos.js @@ -1170,6 +1170,14 @@ ruleTester.run('no-typos', rule, { }, { message: 'Typo in prop type chain qualifier: isrequired' }] + }, { + code: ` + import 'react'; + class Component extends React.Component {}; + `, + parser: 'babel-eslint', + parserOptions: parserOptions, + errors: [] }, { code: ` import { PropTypes } from 'react';