Skip to content

Commit e67259e

Browse files
committed
[Fix] no-unused-modules: support export patterns with array destructuring
Fixes #2930
1 parent 9fd3c42 commit e67259e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88

99
### Fixed
1010
- [`no-extraneous-dependencies`]: ignore `export type { ... } from '...'` when `includeTypes` is `false` ([#2919], thanks [@Pandemic1617])
11+
- [`no-unused-modules`]: support export patterns with array destructuring ([#2930], thanks [@ljharb])
1112

1213
## [2.29.0] - 2023-10-22
1314

@@ -1435,6 +1436,8 @@ for info on changes for earlier releases.
14351436
[#211]: https://github.com/import-js/eslint-plugin-import/pull/211
14361437
[#164]: https://github.com/import-js/eslint-plugin-import/pull/164
14371438
[#157]: https://github.com/import-js/eslint-plugin-import/pull/157
1439+
1440+
[#2930]: https://github.com/import-js/eslint-plugin-import/issues/2930
14381441
[#2687]: https://github.com/import-js/eslint-plugin-import/issues/2687
14391442
[#2684]: https://github.com/import-js/eslint-plugin-import/issues/2684
14401443
[#2674]: https://github.com/import-js/eslint-plugin-import/issues/2674

src/rules/no-unused-modules.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const FUNCTION_DECLARATION = 'FunctionDeclaration';
7474
const CLASS_DECLARATION = 'ClassDeclaration';
7575
const IDENTIFIER = 'Identifier';
7676
const OBJECT_PATTERN = 'ObjectPattern';
77+
const ARRAY_PATTERN = 'ArrayPattern';
7778
const TS_INTERFACE_DECLARATION = 'TSInterfaceDeclaration';
7879
const TS_TYPE_ALIAS_DECLARATION = 'TSTypeAliasDeclaration';
7980
const TS_ENUM_DECLARATION = 'TSEnumDeclaration';
@@ -97,6 +98,10 @@ function forEachDeclarationIdentifier(declaration, cb) {
9798
cb(pattern.name);
9899
}
99100
});
101+
} else if (id.type === ARRAY_PATTERN) {
102+
id.elements.forEach(({ name }) => {
103+
cb(name);
104+
});
100105
} else {
101106
cb(id.name);
102107
}

tests/src/rules/no-unused-modules.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ ruleTester.run('no-unused-modules', rule, {
160160
filename: testFilePath('./no-unused-modules/file-o.js'),
161161
parser: parsers.BABEL_OLD,
162162
}),
163+
test({
164+
options: unusedExportsOptions,
165+
code: `
166+
export const [o0, o2] = createLoadingAndErrorSelectors(
167+
AUTH_USER
168+
);
169+
`,
170+
filename: testFilePath('./no-unused-modules/file-o.js'),
171+
}),
163172
],
164173
invalid: [
165174
test({

0 commit comments

Comments
 (0)