Skip to content

Commit

Permalink
[Fix] no-typos: prevent a crash when using private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 30, 2021
1 parent 38ab031 commit 12f33f6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ ruleTester.run('no-typos', rule, {
`,
parserOptions,
},
semver.satisfies(babelEslintVersion, '>= 9') ? {
{
code: `
class Editor extends React.Component {
#somethingPrivate() {
Expand All @@ -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(
Expand Down

0 comments on commit 12f33f6

Please sign in to comment.