Skip to content

Commit

Permalink
[Fix] no-typos: avoid crash on spread syntax in createReactClass ob…
Browse files Browse the repository at this point in the history
…ject

Fixes #2816.
  • Loading branch information
Songyu-Wang authored and ljharb committed Oct 1, 2020
1 parent 2b0d70c commit 988b794
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

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

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

## [7.21.2] - 2020.09.24
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/no-typos.js
Expand Up @@ -240,8 +240,10 @@ module.exports = {
}

node.properties.forEach((property) => {
reportErrorIfPropertyCasingTypo(property.value, property.key, false);
reportErrorIfLifecycleMethodCasingTypo(property);
if (property.type !== 'SpreadElement') {
reportErrorIfPropertyCasingTypo(property.value, property.key, false);
reportErrorIfLifecycleMethodCasingTypo(property);
}
});
}
};
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-typos.js
Expand Up @@ -33,6 +33,22 @@ const ERROR_MESSAGE_STATIC = (method) => `Lifecycle method should be static: ${m
const ruleTester = new RuleTester();
ruleTester.run('no-typos', rule, {
valid: [{
code: `
import createReactClass from 'create-react-class'
function hello (extra = {}) {
return createReactClass({
noteType: 'hello',
renderItem () {
return null
},
...extra
})
}
`,
parser: parsers.TYPESCRIPT_ESLINT,
parserOptions
},
{
code: `
class First {
static PropTypes = {key: "myValue"};
Expand Down

0 comments on commit 988b794

Please sign in to comment.