Skip to content

Commit 2459c00

Browse files
ohhoney1ljharb
authored andcommitted
[Fix] destructuring-assignment: get the contextName correctly
1 parent e8da096 commit 2459c00

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1212
* component detection: use `estraverse` to improve component detection ([#2992][] @Wesitos)
1313
* [`destructuring-assignment`], [`no-multi-comp`], [`no-unstable-nested-components`], component detection: improve component detection ([#3001][] @vedadeepta)
1414
* [`no-deprecated`]: fix crash on rest elements ([#3016][] @ljharb)
15+
* [`destructuring-assignment`]: get the contextName correctly ([#3025][] @ohhoney1)
1516

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

2021
[#3026]: https://github.com/yannickcr/eslint-plugin-react/pull/3026
22+
[#3025]: https://github.com/yannickcr/eslint-plugin-react/pull/3025
2123
[#3016]: https://github.com/yannickcr/eslint-plugin-react/issues/3016
2224
[#3006]: https://github.com/yannickcr/eslint-plugin-react/pull/3006
2325
[#3001]: https://github.com/yannickcr/eslint-plugin-react/pull/3001

lib/rules/destructuring-assignment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function createSFCParams() {
3232
const context = params[1];
3333
return context && !context.destructuring && context.name;
3434
});
35-
return found && found[1] && found.name;
35+
return found && found[1] && found[1].name;
3636
}
3737
};
3838
}

tests/lib/rules/destructuring-assignment.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ ruleTester.run('destructuring-assignment', rule, {
180180
// https://github.com/yannickcr/eslint-plugin-react/issues/2911
181181
{
182182
code: `
183-
function Foo({context}) {
184-
const d = context.describe()
185-
return <div>{d}</div>
183+
function Foo({ context }) {
184+
const d = context.describe();
185+
return <div>{d}</div>;
186186
}
187187
`,
188188
options: ['always'],
@@ -412,5 +412,18 @@ ruleTester.run('destructuring-assignment', rule, {
412412
messageId: 'useDestructAssignment',
413413
data: {type: 'props'}
414414
}]
415+
}, {
416+
code: `
417+
function Foo(props, context) {
418+
const d = context.describe();
419+
return <div>{d}</div>;
420+
}
421+
`,
422+
options: ['always'],
423+
parser: parsers.BABEL_ESLINT,
424+
errors: [{
425+
messageId: 'useDestructAssignment',
426+
data: {type: 'context'}
427+
}]
415428
}]
416429
});

0 commit comments

Comments
 (0)