Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] destructuring-assignment: get the contextName correctly #3025

Merged
merged 1 commit into from Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'}
}]
}]
});