From 4abb20f27475affc0da44f3ae54a8dfb9b0d192a Mon Sep 17 00:00:00 2001 From: Aziz Abdullaev Date: Tue, 18 Oct 2022 13:27:14 -0400 Subject: [PATCH] [Tests] fix no-restricted-paths: import type test case --- CHANGELOG.md | 2 + tests/files/restricted-paths/server/c.ts | 0 tests/src/rules/no-restricted-paths.js | 162 ++++++++++++----------- 3 files changed, 84 insertions(+), 80 deletions(-) create mode 100644 tests/files/restricted-paths/server/c.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c6fddf6a9..b5a85ef046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange - [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]) - [Tests] [`no-restricted-paths`]: Tests for `import type` statements, thanks [@golergka] +- [Tests] [`no-restricted-paths`]: fix one failing `import type` test case, submitted by [@golergka], thanks [@azyzz228] - [Refactor] [`no-extraneous-dependencies`] improve performance using cache ([#2374], thanks [@meowtec]) - [meta] `CONTRIBUTING.md`: mention inactive PRs ([#2546], thanks [@stropho]) - [readme] make json for setting groups multiline ([#2570], thanks [@bertyhell]) @@ -1556,6 +1557,7 @@ for info on changes for earlier releases. [@atav32]: https://github.com/atav32 [@atikenny]: https://github.com/atikenny [@atos1990]: https://github.com/atos1990 +[@azyzz228]: https://github.com/azyzz228 [@barbogast]: https://github.com/barbogast [@be5invis]: https://github.com/be5invis [@beatrizrezener]: https://github.com/beatrizrezener diff --git a/tests/files/restricted-paths/server/c.ts b/tests/files/restricted-paths/server/c.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/rules/no-restricted-paths.js b/tests/src/rules/no-restricted-paths.js index ec62556f0f..a7db43a6d4 100644 --- a/tests/src/rules/no-restricted-paths.js +++ b/tests/src/rules/no-restricted-paths.js @@ -474,7 +474,7 @@ ruleTester.run('no-restricted-paths', rule, { errors: [ { message: 'Restricted path exceptions must be descendants of the configured ' + - '`from` path for that zone.', + '`from` path for that zone.', line: 1, column: 15, }, @@ -723,91 +723,91 @@ context('Typescript', function () { test({ code: 'import type a from "../client/a.ts"', filename: testFilePath('./restricted-paths/server/b.ts'), - options: [ { - zones: [ { target: './tests/files/restricted-paths/server', from: './tests/files/restricted-paths/other' } ], - } ], + options: [{ + zones: [{ target: './tests/files/restricted-paths/server', from: './tests/files/restricted-paths/other' }], + }], parser, settings, }), test({ code: 'import type a from "../client/a.ts"', filename: testFilePath('./restricted-paths/server/b.ts'), - options: [ { - zones: [ { target: '**/*', from: './tests/files/restricted-paths/other' } ], - } ], + options: [{ + zones: [{ target: '**/*', from: './tests/files/restricted-paths/other' }], + }], parser, settings, }), test({ code: 'import type a from "../client/a.ts"', filename: testFilePath('./restricted-paths/client/b.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/!(client)/**/*', from: './tests/files/restricted-paths/client/**/*', - } ], - } ], + }], + }], parser, settings, }), test({ code: 'import type b from "../server/b.ts"', filename: testFilePath('./restricted-paths/client/a.ts'), - options: [ { - zones: [ { target: './tests/files/restricted-paths/client', from: './tests/files/restricted-paths/other' } ], - } ], + options: [{ + zones: [{ target: './tests/files/restricted-paths/client', from: './tests/files/restricted-paths/other' }], + }], parser, settings, }), test({ code: 'import type a from "./a.ts"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/server/one', from: './tests/files/restricted-paths/server', except: ['./one'], - } ], - } ], + }], + }], parser, settings, }), test({ code: 'import type a from "../two/a.ts"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/server/one', from: './tests/files/restricted-paths/server', except: ['./two'], - } ], - } ], + }], + }], parser, settings, }), test({ code: 'import type a from "../one/a.ts"', filename: testFilePath('./restricted-paths/server/two-new/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/server/two', from: './tests/files/restricted-paths/server', except: [], - } ], - } ], + }], + }], parser, settings, }), test({ code: 'import type A from "../two/a.ts"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: '**/*', from: './tests/files/restricted-paths/server/**/*', except: ['**/a.js'], - } ], - } ], + }], + }], parser, settings, }), @@ -819,40 +819,42 @@ context('Typescript', function () { test({ code: 'import type b from "../server/b"', filename: testFilePath('./restricted-paths/client/a.ts'), - options: [ { - zones: [ { target: './tests/files/restricted-paths/client', from: './tests/files/restricted-paths/server' } ], - } ], - errors: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/client', from: './tests/files/restricted-paths/server' }], + }], + errors: [{ message: 'Unexpected path "../server/b" imported in restricted zone.', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type b from "../server/b"', filename: testFilePath('./restricted-paths/client/a.ts'), - options: [ { - zones: [ { target: './tests/files/restricted-paths/client/**/*', from: './tests/files/restricted-paths/server' } ], - } ], - errors: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/client/**/*', from: './tests/files/restricted-paths/server' }], + }], + errors: [{ message: 'Unexpected path "../server/b" imported in restricted zone.', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type a from "../client/a"\nimport type c from "./c.ts"', filename: testFilePath('./restricted-paths/server/b.ts'), - options: [ { + options: [{ zones: [ - { target: './tests/files/restricted-paths/server', from: './tests/files/restricted-paths/client' }, - { target: './tests/files/restricted-paths/server', from: './tests/files/restricted-paths/server/c.ts' }, + { + target: './tests/files/restricted-paths/server', + from: ['./tests/files/restricted-paths/client', './tests/files/restricted-paths/server/c.ts'] + } ], - } ], + }], errors: [ { message: 'Unexpected path "../client/a" imported in restricted zone.', @@ -860,7 +862,7 @@ context('Typescript', function () { column: 20, }, { - message: 'Unexpected path "./c" imported in restricted zone.', + message: 'Unexpected path "./c.ts" imported in restricted zone.', line: 2, column: 20, }, @@ -871,106 +873,106 @@ context('Typescript', function () { test({ code: 'import type b from "../server/b"', filename: testFilePath('./restricted-paths/client/a'), - options: [ { - zones: [ { target: './client', from: './server' } ], + options: [{ + zones: [{ target: './client', from: './server' }], basePath: testFilePath('./restricted-paths'), - } ], - errors: [ { + }], + errors: [{ message: 'Unexpected path "../server/b" imported in restricted zone.', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type b from "../two/a"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/server/one', from: './tests/files/restricted-paths/server', except: ['./one'], - } ], - } ], - errors: [ { + }], + }], + errors: [{ message: 'Unexpected path "../two/a" imported in restricted zone.', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type b from "../two/a"', filename: testFilePath('./restricted-paths/server/one/a'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/server/one', from: './tests/files/restricted-paths/server', except: ['./one'], message: 'Custom message', - } ], - } ], - errors: [ { + }], + }], + errors: [{ message: 'Unexpected path "../two/a" imported in restricted zone. Custom message', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type b from "../two/a"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: './tests/files/restricted-paths/server/one', from: './tests/files/restricted-paths/server', except: ['../client/a'], - } ], - } ], - errors: [ { + }], + }], + errors: [{ message: 'Restricted path exceptions must be descendants of the configured ' + '`from` path for that zone.', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type A from "../two/a"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: '**/*', from: './tests/files/restricted-paths/server/**/*', - } ], - } ], - errors: [ { + }], + }], + errors: [{ message: 'Unexpected path "../two/a" imported in restricted zone.', line: 1, column: 20, - } ], + }], parser, settings, }), test({ code: 'import type A from "../two/a"', filename: testFilePath('./restricted-paths/server/one/a.ts'), - options: [ { - zones: [ { + options: [{ + zones: [{ target: '**/*', from: './tests/files/restricted-paths/server/**/*', except: ['a.ts'], - } ], - } ], - errors: [ { + }], + }], + errors: [{ message: 'Restricted path exceptions must be glob patterns when `from` contains glob patterns', line: 1, column: 20, - } ], + }], parser, settings, }),