From 9f401a8f7e049a3f16fa2e453eca62126ffd3af6 Mon Sep 17 00:00:00 2001 From: George Reith Date: Thu, 21 Apr 2022 12:09:02 +0100 Subject: [PATCH] [Tests] `no-cycle`: add passing test cases --- CHANGELOG.md | 11 +++++++---- tests/files/cycles/ignore/.eslintrc | 5 +++++ tests/files/cycles/ignore/index.js | 2 ++ tests/files/cycles/intermediate-ignore.js | 2 ++ tests/src/rules/no-cycle.js | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/files/cycles/ignore/.eslintrc create mode 100644 tests/files/cycles/ignore/index.js create mode 100644 tests/files/cycles/intermediate-ignore.js diff --git a/CHANGELOG.md b/CHANGELOG.md index d710b71bc..f1bbceb50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,15 +23,16 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange - [`dynamic-import-chunkname`]: prevent false report on a valid webpack magic comment ([#2330], thanks [@mhmadhamster]) ### Changed -- [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim]) +- [Tests] [`named`]: Run all TypeScript test ([#2427], thanks [@ProdigySim]) - [readme] note use of typescript in readme `import/extensions` section ([#2440], thanks [@OutdatedVersion]) -- [Docs] `order`: use correct default value ([#2392], thanks [@hyperupcall]) +- [Docs] [`order`]: use correct default value ([#2392], thanks [@hyperupcall]) - [meta] replace git.io link in comments with the original URL ([#2444], thanks [@liby]) - [Docs] remove global install in readme ([#2412], thanks [@aladdin-add]) - [readme] clarify `eslint-import-resolver-typescript` usage ([#2503], thanks [@JounQin]) -- [Refactor] `no-cycle`: Add per-run caching of traversed paths ([#2419], thanks [@nokel81]) +- [Refactor] [`no-cycle`]: Add per-run caching of traversed paths ([#2419], thanks [@nokel81]) - [Performance] `ExportMap`: add caching after parsing for an ambiguous module ([#2531], thanks [@stenin-nikita]) -- [Docs] `no-useless-path-segments`: fix paths ([#2424] thanks [@s-h-a-d-o-w]) +- [Docs] [`no-useless-path-segments`]: fix paths ([#2424], thanks [@s-h-a-d-o-w]) +- [Tests] [`no-cycle`]: add passing test cases ([#2438], thanks [@georeith]) ## [2.26.0] - 2022-04-05 @@ -1011,6 +1012,7 @@ for info on changes for earlier releases. [#2490]: https://github.com/import-js/eslint-plugin-import/pull/2490 [#2466]: https://github.com/import-js/eslint-plugin-import/pull/2466 [#2440]: https://github.com/import-js/eslint-plugin-import/pull/2440 +[#2438]: https://github.com/import-js/eslint-plugin-import/pull/2438 [#2427]: https://github.com/import-js/eslint-plugin-import/pull/2427 [#2424]: https://github.com/import-js/eslint-plugin-import/pull/2424 [#2419]: https://github.com/import-js/eslint-plugin-import/pull/2419 @@ -1583,6 +1585,7 @@ for info on changes for earlier releases. [@futpib]: https://github.com/futpib [@gajus]: https://github.com/gajus [@gausie]: https://github.com/gausie +[@georeith]: https://github.com/georeith [@gavriguy]: https://github.com/gavriguy [@giodamelio]: https://github.com/giodamelio [@golopot]: https://github.com/golopot diff --git a/tests/files/cycles/ignore/.eslintrc b/tests/files/cycles/ignore/.eslintrc new file mode 100644 index 000000000..896eda6a3 --- /dev/null +++ b/tests/files/cycles/ignore/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "import/no-cycle": 0 + } +} diff --git a/tests/files/cycles/ignore/index.js b/tests/files/cycles/ignore/index.js new file mode 100644 index 000000000..211fd972f --- /dev/null +++ b/tests/files/cycles/ignore/index.js @@ -0,0 +1,2 @@ +import { foo } from "../depth-zero"; +export { foo }; diff --git a/tests/files/cycles/intermediate-ignore.js b/tests/files/cycles/intermediate-ignore.js new file mode 100644 index 000000000..1ba6fba79 --- /dev/null +++ b/tests/files/cycles/intermediate-ignore.js @@ -0,0 +1,2 @@ +import foo from "./ignore"; +export { foo }; diff --git a/tests/src/rules/no-cycle.js b/tests/src/rules/no-cycle.js index 233cae613..de0083f56 100644 --- a/tests/src/rules/no-cycle.js +++ b/tests/src/rules/no-cycle.js @@ -267,5 +267,23 @@ ruleTester.run('no-cycle', rule, { parser: parsers.BABEL_OLD, errors: [error(`Dependency cycle via ./flow-types-depth-two:4=>./es6/depth-one:1`)], }), + test({ + code: 'import { foo } from "./intermediate-ignore"', + errors: [ + { + message: 'Dependency cycle via ./ignore:1', + line: 1, + }, + ], + }), + test({ + code: 'import { foo } from "./ignore"', + errors: [ + { + message: 'Dependency cycle detected.', + line: 1, + }, + ], + }), ), });