Skip to content

Commit

Permalink
[Fix] destructuring-assignment: get the contextName correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhoney1 authored and ljharb committed Jul 27, 2021
1 parent e8da096 commit 2459c00
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,12 +12,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* component detection: use `estraverse` to improve component detection ([#2992][] @Wesitos)
* [`destructuring-assignment`], [`no-multi-comp`], [`no-unstable-nested-components`], component detection: improve component detection ([#3001][] @vedadeepta)
* [`no-deprecated`]: fix crash on rest elements ([#3016][] @ljharb)
* [`destructuring-assignment`]: get the contextName correctly ([#3025][] @ohhoney1)

### Changed
* [Docs] [`jsx-no-bind`]: updates discussion of refs ([#2998][] @dimitropoulos)
* [Refactor] `utils/Components`: correct spelling and delete unused code ([#3026][] @ohhoney1)

[#3026]: https://github.com/yannickcr/eslint-plugin-react/pull/3026
[#3025]: https://github.com/yannickcr/eslint-plugin-react/pull/3025
[#3016]: https://github.com/yannickcr/eslint-plugin-react/issues/3016
[#3006]: https://github.com/yannickcr/eslint-plugin-react/pull/3006
[#3001]: https://github.com/yannickcr/eslint-plugin-react/pull/3001
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/destructuring-assignment.js
Expand Up @@ -32,7 +32,7 @@ function createSFCParams() {
const context = params[1];
return context && !context.destructuring && context.name;
});
return found && found[1] && found.name;
return found && found[1] && found[1].name;
}
};
}
Expand Down
19 changes: 16 additions & 3 deletions tests/lib/rules/destructuring-assignment.js
Expand Up @@ -180,9 +180,9 @@ ruleTester.run('destructuring-assignment', rule, {
// https://github.com/yannickcr/eslint-plugin-react/issues/2911
{
code: `
function Foo({context}) {
const d = context.describe()
return <div>{d}</div>
function Foo({ context }) {
const d = context.describe();
return <div>{d}</div>;
}
`,
options: ['always'],
Expand Down Expand Up @@ -412,5 +412,18 @@ ruleTester.run('destructuring-assignment', rule, {
messageId: 'useDestructAssignment',
data: {type: 'props'}
}]
}, {
code: `
function Foo(props, context) {
const d = context.describe();
return <div>{d}</div>;
}
`,
options: ['always'],
parser: parsers.BABEL_ESLINT,
errors: [{
messageId: 'useDestructAssignment',
data: {type: 'context'}
}]
}]
});

0 comments on commit 2459c00

Please sign in to comment.