Skip to content

Commit 4073d0e

Browse files
committed
[Fix] no-typos: avoid crash with computed method name
Fixes #2870
1 parent 63d5a1b commit 4073d0e

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1414
* [`display-name`]/component detection: avoid a crash on anonymous components ([#2840][] @ljharb)
1515
* [`prop-types`]: function in class that returns a component causes false warning in typescript ([#2843][] @SyMind)
1616
* [`jsx-no-target-blank`]: avoid a crash with a non-string literal ([#2851][] @ljharb)
17-
* [`jsx-no-script-url`]: avoid crash with boolean `href` ([#2871][] @ljharb)
17+
* [`jsx-no-script-url`]: avoid crash with boolean `href` ([#2871][] @ljharb, @AriPerkkio)
18+
* [`no-typos`]: avoid crash with computed method name ([#2870][] @ljharb, @AriPerkkio)
1819

1920
[#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2871
21+
[#2870]: https://github.com/yannickcr/eslint-plugin-react/issues/2870
2022
[#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851
2123
[#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843
2224
[#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840

lib/rules/no-typos.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ module.exports = {
150150
if (node.key.type === 'Literal') {
151151
nodeKeyName = node.key.value;
152152
}
153+
if (node.computed && typeof nodeKeyName !== 'string') {
154+
return;
155+
}
153156

154157
STATIC_LIFECYCLE_METHODS.forEach((method) => {
155158
if (!node.static && nodeKeyName.toLowerCase() === method.toLowerCase()) {

tests/lib/rules/no-typos.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,19 @@ ruleTester.run('no-typos', rule, {
634634
};
635635
`,
636636
parserOptions
637+
}, {
638+
code: `
639+
import React from 'react';
640+
641+
const A = { B: 'C' };
642+
643+
export default class MyComponent extends React.Component {
644+
[A.B] () {
645+
return null
646+
}
647+
}
648+
`,
649+
parserOptions
637650
}],
638651

639652
invalid: [{

0 commit comments

Comments
 (0)