Skip to content

Commit aca2ec5

Browse files
authored
consistent-destructuring: Add ExperimentalRestProperty check (#1060)
1 parent 75c477f commit aca2ec5

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

rules/consistent-destructuring.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ const create = context => {
9292
property.value.type === 'Identifier'
9393
);
9494
const lastProperty = objectPattern.properties[objectPattern.properties.length - 1];
95-
const hasRest = lastProperty && lastProperty.type === 'RestElement';
95+
96+
// TODO: Remove `ExperimentalRestProperty` check when we drop support for `babel-eslint` #1040
97+
const hasRest = lastProperty &&
98+
(lastProperty.type === 'RestElement' || lastProperty.type === 'ExperimentalRestProperty');
9699

97100
const expression = source.getText(node);
98101
const member = source.getText(node.property);

test/consistent-destructuring.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import test from 'ava';
2-
import avaRuleTester from 'eslint-ava-rule-tester';
31
import {outdent} from 'outdent';
4-
import rule from '../rules/consistent-destructuring.js';
5-
6-
const ruleTester = avaRuleTester(test, {
7-
parserOptions: {
8-
ecmaVersion: 2020
9-
}
10-
});
2+
import {test} from './utils/test.js';
113

124
const invalidTestCase = ({code, suggestions}) => {
135
if (!suggestions) {
@@ -33,7 +25,7 @@ const invalidTestCase = ({code, suggestions}) => {
3325
};
3426
};
3527

36-
ruleTester.run('consistent-destructuring', rule, {
28+
test({
3729
valid: [
3830
'console.log(foo.a, foo.b);',
3931
'const foo = 10;',
@@ -476,3 +468,24 @@ ruleTester.run('consistent-destructuring', rule, {
476468
}
477469
]
478470
});
471+
472+
test.babelLegacy({
473+
valid: [
474+
outdent`
475+
const {a, ...b} = bar;
476+
console.log(bar.c);
477+
`
478+
],
479+
invalid: [
480+
invalidTestCase({
481+
code: outdent`
482+
const {a, ...b} = bar;
483+
console.log(bar.a);
484+
`,
485+
suggestions: [outdent`
486+
const {a, ...b} = bar;
487+
console.log(a);
488+
`]
489+
})
490+
]
491+
});

0 commit comments

Comments
 (0)