From 747d6dc5b905a718c89f10aad04cb2bcdbed7068 Mon Sep 17 00:00:00 2001 From: The Jared Wilcurt Date: Wed, 2 Mar 2022 18:26:46 -0500 Subject: [PATCH 1/3] [Docs] make rule doc titles consistent matches other docs pages now, easier for copy/pasting the rule --- CHANGELOG.md | 3 +++ docs/rules/dynamic-import-chunkname.md | 2 +- docs/rules/imports-first.md | 2 +- docs/rules/no-import-module-exports.md | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b1b4aa2f..2c9357bf18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange - [Tests] `default`, `no-anonymous-default-export`, `no-mutable-exports`, `no-named-as-default-member`, `no-named-as-default`: add tests for arbitrary module namespace names ([#2358], thanks [@sosukesuzuki]) - [Docs] [`no-unresolved`]: Fix RegExp escaping in readme ([#2332], thanks [@stephtr]) - [Refactor] `namespace`: try to improve performance ([#2340], thanks [@ljharb]) +- [Docs] make rule doc titles consistent ([#2393], thanks [@TheJaredWilcurt]) ## [2.25.4] - 2022-01-02 @@ -971,6 +972,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#2393]: https://github.com/import-js/eslint-plugin-import/pull/2393 [#2381]: https://github.com/import-js/eslint-plugin-import/pull/2381 [#2378]: https://github.com/import-js/eslint-plugin-import/pull/2378 [#2371]: https://github.com/import-js/eslint-plugin-import/pull/2371 @@ -1659,6 +1661,7 @@ for info on changes for earlier releases. [@Taranys]: https://github.com/Taranys [@taye]: https://github.com/taye [@TheCrueltySage]: https://github.com/TheCrueltySage +[@TheJaredWilcurt]: https://github.com/TheJaredWilcurt [@tihonove]: https://github.com/tihonove [@timkraut]: https://github.com/timkraut [@tizmagik]: https://github.com/tizmagik diff --git a/docs/rules/dynamic-import-chunkname.md b/docs/rules/dynamic-import-chunkname.md index d29c06bbaa..6b43074f19 100644 --- a/docs/rules/dynamic-import-chunkname.md +++ b/docs/rules/dynamic-import-chunkname.md @@ -1,4 +1,4 @@ -# dynamic imports require a leading comment with a webpackChunkName (dynamic-import-chunkname) +# import/dynamic-import-chunkname This rule reports any dynamic imports without a webpackChunkName specified in a leading block comment in the proper format. diff --git a/docs/rules/imports-first.md b/docs/rules/imports-first.md index 7dadffa684..4b90f04ea8 100644 --- a/docs/rules/imports-first.md +++ b/docs/rules/imports-first.md @@ -1,3 +1,3 @@ -# imports-first +# import/imports-first This rule was **deprecated** in eslint-plugin-import v2.0.0. Please use the corresponding rule [`first`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/first.md). diff --git a/docs/rules/no-import-module-exports.md b/docs/rules/no-import-module-exports.md index 8131fd5f78..d658deb566 100644 --- a/docs/rules/no-import-module-exports.md +++ b/docs/rules/no-import-module-exports.md @@ -1,4 +1,4 @@ -# no-import-module-exports +# import/no-import-module-exports Reports the use of import declarations with CommonJS exports in any module except for the [main module](https://docs.npmjs.com/files/package.json#main). From 8b7000ec75968c1bd94f3099d67995a699286cf0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 13 Mar 2022 13:37:07 -0700 Subject: [PATCH 2/3] [Fix] `no-unused-modules`: avoid a crash when processing re-exports Fixes #2388. --- CHANGELOG.md | 2 ++ src/rules/no-unused-modules.js | 6 ++++-- .../files/unused-modules-reexport-crash/src/App.tsx | 5 +++++ .../unused-modules-reexport-crash/src/index.tsx | 3 +++ .../src/magic/index.js | 1 + .../unused-modules-reexport-crash/src/magic/test.js | 7 +++++++ tests/src/rules/no-unused-modules.js | 13 ++++++++++++- 7 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/files/unused-modules-reexport-crash/src/App.tsx create mode 100644 tests/files/unused-modules-reexport-crash/src/index.tsx create mode 100644 tests/files/unused-modules-reexport-crash/src/magic/index.js create mode 100644 tests/files/unused-modules-reexport-crash/src/magic/test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c9357bf18..59ab25da95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange - [`default`]: `typescript-eslint-parser`: avoid a crash on exporting as namespace (thanks [@ljharb]) - [`export`]/TypeScript: false positive for typescript namespace merging ([#1964], thanks [@magarcia]) - [`no-duplicates`]: ignore duplicate modules in different TypeScript module declarations ([#2378], thanks [@remcohaszing]) +- [`no-unused-modules`]: avoid a crash when processing re-exports ([#2388], thanks [@ljharb]) ### Changed - [Tests] `no-nodejs-modules`: add tests for node protocol URL ([#2367], thanks [@sosukesuzuki]) @@ -973,6 +974,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md [#2393]: https://github.com/import-js/eslint-plugin-import/pull/2393 +[#2388]: https://github.com/import-js/eslint-plugin-import/pull/2388 [#2381]: https://github.com/import-js/eslint-plugin-import/pull/2381 [#2378]: https://github.com/import-js/eslint-plugin-import/pull/2378 [#2371]: https://github.com/import-js/eslint-plugin-import/pull/2371 diff --git a/src/rules/no-unused-modules.js b/src/rules/no-unused-modules.js index efc2169946..5feb319036 100644 --- a/src/rules/no-unused-modules.js +++ b/src/rules/no-unused-modules.js @@ -273,8 +273,10 @@ const prepareImportsAndExports = (srcFiles, context) => { exportAll.forEach((value, key) => { value.forEach(val => { const currentExports = exportList.get(val); - const currentExport = currentExports.get(EXPORT_ALL_DECLARATION); - currentExport.whereUsed.add(key); + if (currentExports) { + const currentExport = currentExports.get(EXPORT_ALL_DECLARATION); + currentExport.whereUsed.add(key); + } }); }); }; diff --git a/tests/files/unused-modules-reexport-crash/src/App.tsx b/tests/files/unused-modules-reexport-crash/src/App.tsx new file mode 100644 index 0000000000..c797a976cb --- /dev/null +++ b/tests/files/unused-modules-reexport-crash/src/App.tsx @@ -0,0 +1,5 @@ +import { hello } from './magic/test' + +hello(); + +export default function App() {}; diff --git a/tests/files/unused-modules-reexport-crash/src/index.tsx b/tests/files/unused-modules-reexport-crash/src/index.tsx new file mode 100644 index 0000000000..124b1745d2 --- /dev/null +++ b/tests/files/unused-modules-reexport-crash/src/index.tsx @@ -0,0 +1,3 @@ +import App from './App'; + +export const x = App \ No newline at end of file diff --git a/tests/files/unused-modules-reexport-crash/src/magic/index.js b/tests/files/unused-modules-reexport-crash/src/magic/index.js new file mode 100644 index 0000000000..ac3f46bb1b --- /dev/null +++ b/tests/files/unused-modules-reexport-crash/src/magic/index.js @@ -0,0 +1 @@ +export * from './test' diff --git a/tests/files/unused-modules-reexport-crash/src/magic/test.js b/tests/files/unused-modules-reexport-crash/src/magic/test.js new file mode 100644 index 0000000000..a6d74afd9b --- /dev/null +++ b/tests/files/unused-modules-reexport-crash/src/magic/test.js @@ -0,0 +1,7 @@ +export function hello() { + console.log('hello!!'); +} + +export function unused() { + console.log('im unused!!'); +} \ No newline at end of file diff --git a/tests/src/rules/no-unused-modules.js b/tests/src/rules/no-unused-modules.js index aa0e123c2b..38db2ef43d 100644 --- a/tests/src/rules/no-unused-modules.js +++ b/tests/src/rules/no-unused-modules.js @@ -105,7 +105,7 @@ ruleTester.run('no-unused-modules', rule, { }); -// tests for exports +// tests for exports ruleTester.run('no-unused-modules', rule, { valid: [ test({ @@ -301,6 +301,17 @@ describe('dynamic imports', () => { parser: parsers.TS_NEW, filename: testFilePath('./no-unused-modules/typescript/exports-for-dynamic-ts.ts'), }), + test({ + code: ` + import App from './App'; + `, + filename: testFilePath('./unused-modules-reexport-crash/src/index.tsx'), + parser: parsers.TS_NEW, + options: [{ + unusedExports: true, + ignoreExports: ['**/magic/**'], + }], + }), ], invalid: [ ], From 21304bdf0124be1db8e6b152b072661b50fa931c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 13 Mar 2022 13:52:48 -0700 Subject: [PATCH 3/3] [Deps] update `tsconfig-paths` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a55575143..186c5cb57e 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,6 @@ "minimatch": "^3.1.2", "object.values": "^1.1.5", "resolve": "^1.22.0", - "tsconfig-paths": "^3.12.0" + "tsconfig-paths": "^3.13.0" } }