diff --git a/CHANGELOG.md b/CHANGELOG.md index b8e2c6fe18..a2f2d983de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel * [`destructuring-assignment`]: detect refs nested in functions ([#3102] @ljharb) * [`no-unstable-components`]: improve handling of objects containing render function properties ([#3111] @fizwidget) * [`prop-types`], `propTypes`: add forwardRef<>, ForwardRefRenderFunction<> prop-types ([#3112] @vedadeepta) +* [`no-typos`]: prevent a crash when using private methods (@ljharb) ### Changed * [Tests] test on the new babel eslint parser ([#3113] @ljharb) diff --git a/lib/rules/no-typos.js b/lib/rules/no-typos.js index 36a3d017b9..76783729ae 100644 --- a/lib/rules/no-typos.js +++ b/lib/rules/no-typos.js @@ -152,7 +152,7 @@ module.exports = { } lifecycleMethods.static.forEach((method) => { - if (!node.static && nodeKeyName.toLowerCase() === method.toLowerCase()) { + if (!node.static && nodeKeyName && nodeKeyName.toLowerCase() === method.toLowerCase()) { report(context, messages.staticLifecycleMethod, 'staticLifecycleMethod', { node, data: { @@ -163,7 +163,7 @@ module.exports = { }); lifecycleMethods.instance.concat(lifecycleMethods.static).forEach((method) => { - if (method.toLowerCase() === nodeKeyName.toLowerCase() && method !== nodeKeyName) { + if (nodeKeyName && method.toLowerCase() === nodeKeyName.toLowerCase() && method !== nodeKeyName) { report(context, messages.typoLifecycleMethod, 'typoLifecycleMethod', { node, data: { actual: nodeKeyName, expected: method }, diff --git a/tests/helpers/parsers.js b/tests/helpers/parsers.js index 07c9097fa7..1a935f60d7 100644 --- a/tests/helpers/parsers.js +++ b/tests/helpers/parsers.js @@ -77,7 +77,7 @@ const parsers = { || (features.has('fragment') && semver.satisfies(version, '< 5')); const skipBabel = features.has('no-babel'); - const skipOldBabel = skipBabel || semver.satisfies(version, '>= 8'); + const skipOldBabel = skipBabel || features.has('no-babel-old') || semver.satisfies(version, '>= 8'); const skipNewBabel = skipBabel || features.has('no-babel-new') || !semver.satisfies(version, '^7.5.0') // require('@babel/eslint-parser/package.json').peerDependencies.eslint diff --git a/tests/lib/rules/no-typos.js b/tests/lib/rules/no-typos.js index 44dfbecf7b..f5a90514a6 100644 --- a/tests/lib/rules/no-typos.js +++ b/tests/lib/rules/no-typos.js @@ -557,7 +557,7 @@ ruleTester.run('no-typos', rule, { `, parserOptions, }, - semver.satisfies(babelEslintVersion, '>= 9') ? { + { code: ` class Editor extends React.Component { #somethingPrivate() { @@ -575,14 +575,14 @@ ruleTester.run('no-typos', rule, { } } `, - parser: parsers.BABEL_ESLINT, - parserOptions: { + features: [].concat('class fields', semver.satisfies(babelEslintVersion, '< 9') ? 'no-babel-old' : []), + parserOptions: Object.assign({}, parserOptions, { babelOptions: { - classPrivateMethods: true, + // classPrivateMethods: true, }, shippedProposals: true, - }, - } : [] + }), + } )), invalid: parsers.all([].concat(