Skip to content

Commit 988b794

Browse files
Songyu-Wangljharb
authored andcommitted
[Fix] no-typos: avoid crash on spread syntax in createReactClass object
Fixes #2816.
1 parent 2b0d70c commit 988b794

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
77

88
## Fixed
99
* [`prop-types`]: fix Cannot read property 'type' of undefined error when destructured param ([#2807][] @minwe)
10+
* [`no-typos`]: avoid crash on spread syntax in createReactClass object ([#2816][] @ljharb @Songyu-Wang)
1011

12+
[#2816]: https://github.com/yannickcr/eslint-plugin-react/issues/2816
1113
[#2807]: https://github.com/yannickcr/eslint-plugin-react/pull/2807
1214

1315
## [7.21.2] - 2020.09.24

lib/rules/no-typos.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ module.exports = {
240240
}
241241

242242
node.properties.forEach((property) => {
243-
reportErrorIfPropertyCasingTypo(property.value, property.key, false);
244-
reportErrorIfLifecycleMethodCasingTypo(property);
243+
if (property.type !== 'SpreadElement') {
244+
reportErrorIfPropertyCasingTypo(property.value, property.key, false);
245+
reportErrorIfLifecycleMethodCasingTypo(property);
246+
}
245247
});
246248
}
247249
};

tests/lib/rules/no-typos.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ const ERROR_MESSAGE_STATIC = (method) => `Lifecycle method should be static: ${m
3333
const ruleTester = new RuleTester();
3434
ruleTester.run('no-typos', rule, {
3535
valid: [{
36+
code: `
37+
import createReactClass from 'create-react-class'
38+
function hello (extra = {}) {
39+
return createReactClass({
40+
noteType: 'hello',
41+
renderItem () {
42+
return null
43+
},
44+
...extra
45+
})
46+
}
47+
`,
48+
parser: parsers.TYPESCRIPT_ESLINT,
49+
parserOptions
50+
},
51+
{
3652
code: `
3753
class First {
3854
static PropTypes = {key: "myValue"};

0 commit comments

Comments
 (0)