Skip to content

Commit 12f33f6

Browse files
committed
[Fix] no-typos: prevent a crash when using private methods
1 parent 38ab031 commit 12f33f6

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1919
* [`destructuring-assignment`]: detect refs nested in functions ([#3102] @ljharb)
2020
* [`no-unstable-components`]: improve handling of objects containing render function properties ([#3111] @fizwidget)
2121
* [`prop-types`], `propTypes`: add forwardRef<>, ForwardRefRenderFunction<> prop-types ([#3112] @vedadeepta)
22+
* [`no-typos`]: prevent a crash when using private methods (@ljharb)
2223

2324
### Changed
2425
* [Tests] test on the new babel eslint parser ([#3113] @ljharb)

lib/rules/no-typos.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ module.exports = {
152152
}
153153

154154
lifecycleMethods.static.forEach((method) => {
155-
if (!node.static && nodeKeyName.toLowerCase() === method.toLowerCase()) {
155+
if (!node.static && nodeKeyName && nodeKeyName.toLowerCase() === method.toLowerCase()) {
156156
report(context, messages.staticLifecycleMethod, 'staticLifecycleMethod', {
157157
node,
158158
data: {
@@ -163,7 +163,7 @@ module.exports = {
163163
});
164164

165165
lifecycleMethods.instance.concat(lifecycleMethods.static).forEach((method) => {
166-
if (method.toLowerCase() === nodeKeyName.toLowerCase() && method !== nodeKeyName) {
166+
if (nodeKeyName && method.toLowerCase() === nodeKeyName.toLowerCase() && method !== nodeKeyName) {
167167
report(context, messages.typoLifecycleMethod, 'typoLifecycleMethod', {
168168
node,
169169
data: { actual: nodeKeyName, expected: method },

tests/helpers/parsers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const parsers = {
7777
|| (features.has('fragment') && semver.satisfies(version, '< 5'));
7878

7979
const skipBabel = features.has('no-babel');
80-
const skipOldBabel = skipBabel || semver.satisfies(version, '>= 8');
80+
const skipOldBabel = skipBabel || features.has('no-babel-old') || semver.satisfies(version, '>= 8');
8181
const skipNewBabel = skipBabel
8282
|| features.has('no-babel-new')
8383
|| !semver.satisfies(version, '^7.5.0') // require('@babel/eslint-parser/package.json').peerDependencies.eslint

tests/lib/rules/no-typos.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ ruleTester.run('no-typos', rule, {
557557
`,
558558
parserOptions,
559559
},
560-
semver.satisfies(babelEslintVersion, '>= 9') ? {
560+
{
561561
code: `
562562
class Editor extends React.Component {
563563
#somethingPrivate() {
@@ -575,14 +575,14 @@ ruleTester.run('no-typos', rule, {
575575
}
576576
}
577577
`,
578-
parser: parsers.BABEL_ESLINT,
579-
parserOptions: {
578+
features: [].concat('class fields', semver.satisfies(babelEslintVersion, '< 9') ? 'no-babel-old' : []),
579+
parserOptions: Object.assign({}, parserOptions, {
580580
babelOptions: {
581-
classPrivateMethods: true,
581+
// classPrivateMethods: true,
582582
},
583583
shippedProposals: true,
584-
},
585-
} : []
584+
}),
585+
}
586586
)),
587587

588588
invalid: parsers.all([].concat(

0 commit comments

Comments
 (0)