Skip to content

Commit

Permalink
[Fix] no-unused-modules: support export patterns with array destruc…
Browse files Browse the repository at this point in the history
…turing

Fixes #2930
  • Loading branch information
ljharb committed Dec 4, 2023
1 parent 9fd3c42 commit e67259e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

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

## [2.29.0] - 2023-10-22

Expand Down Expand Up @@ -1435,6 +1436,8 @@ for info on changes for earlier releases.
[#211]: https://github.com/import-js/eslint-plugin-import/pull/211
[#164]: https://github.com/import-js/eslint-plugin-import/pull/164
[#157]: https://github.com/import-js/eslint-plugin-import/pull/157

[#2930]: https://github.com/import-js/eslint-plugin-import/issues/2930
[#2687]: https://github.com/import-js/eslint-plugin-import/issues/2687
[#2684]: https://github.com/import-js/eslint-plugin-import/issues/2684
[#2674]: https://github.com/import-js/eslint-plugin-import/issues/2674
Expand Down
5 changes: 5 additions & 0 deletions src/rules/no-unused-modules.js
Expand Up @@ -74,6 +74,7 @@ const FUNCTION_DECLARATION = 'FunctionDeclaration';
const CLASS_DECLARATION = 'ClassDeclaration';
const IDENTIFIER = 'Identifier';
const OBJECT_PATTERN = 'ObjectPattern';
const ARRAY_PATTERN = 'ArrayPattern';
const TS_INTERFACE_DECLARATION = 'TSInterfaceDeclaration';
const TS_TYPE_ALIAS_DECLARATION = 'TSTypeAliasDeclaration';
const TS_ENUM_DECLARATION = 'TSEnumDeclaration';
Expand All @@ -97,6 +98,10 @@ function forEachDeclarationIdentifier(declaration, cb) {
cb(pattern.name);
}
});
} else if (id.type === ARRAY_PATTERN) {
id.elements.forEach(({ name }) => {
cb(name);
});
} else {
cb(id.name);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/src/rules/no-unused-modules.js
Expand Up @@ -160,6 +160,15 @@ ruleTester.run('no-unused-modules', rule, {
filename: testFilePath('./no-unused-modules/file-o.js'),
parser: parsers.BABEL_OLD,
}),
test({
options: unusedExportsOptions,
code: `
export const [o0, o2] = createLoadingAndErrorSelectors(
AUTH_USER
);
`,
filename: testFilePath('./no-unused-modules/file-o.js'),
}),
],
invalid: [
test({
Expand Down

0 comments on commit e67259e

Please sign in to comment.