From 8c90c48a527f2ed741c971077a925e0d82265df0 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Tue, 24 Sep 2019 19:38:20 +0900 Subject: [PATCH 1/4] index* to index.{ts,tsx} --- .eslintrc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 14567f4343006..7809e0dd74d19 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -152,10 +152,10 @@ module.exports = { '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', - '!src/plugins/**/public/index*', + '!src/plugins/**/public/index.{ts,tsx}', 'src/plugins/**/server/**/*', - '!src/plugins/**/server/index*', + '!src/plugins/**/server/index.{ts,tsx}', ], allowSameFolder: true, }, From 6e7a548cad3e1732279410f04f158d8271cec9e4 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Wed, 25 Sep 2019 12:22:00 +0900 Subject: [PATCH 2/4] Added test. --- .../server/index_patterns/index.js | 1 + .../rules/__tests__/no_restricted_paths.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/kbn-eslint-plugin-eslint/rules/__tests__/files/no_restricted_paths/server/index_patterns/index.js diff --git a/packages/kbn-eslint-plugin-eslint/rules/__tests__/files/no_restricted_paths/server/index_patterns/index.js b/packages/kbn-eslint-plugin-eslint/rules/__tests__/files/no_restricted_paths/server/index_patterns/index.js new file mode 100644 index 0000000000000..d15de7d98a9e0 --- /dev/null +++ b/packages/kbn-eslint-plugin-eslint/rules/__tests__/files/no_restricted_paths/server/index_patterns/index.js @@ -0,0 +1 @@ +/* eslint-disable */ diff --git a/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js b/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js index c821aafb09285..9a9036997ce4b 100644 --- a/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js +++ b/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js @@ -172,6 +172,26 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, { }, ], }, + + { + code: 'import { X } from "./index_patterns"', + filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'), + options: [ + { + basePath: __dirname, + zones: [ + { + target: ['files/no_restricted_paths/(public|server)/**/*'], + from: [ + 'files/no_restricted_paths/server/**/*', + '!files/no_restricted_paths/server/index.{ts,tsx}', + ], + allowSameFolder: true, + }, + ], + }, + ], + }, ], invalid: [ From 218aa12d0fc944d076a94c80b93c933fb9bb9d61 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Wed, 25 Sep 2019 12:28:43 +0900 Subject: [PATCH 3/4] Added invalid test. --- .../rules/__tests__/no_restricted_paths.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js b/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js index 9a9036997ce4b..04998132d99db 100644 --- a/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js +++ b/packages/kbn-eslint-plugin-eslint/rules/__tests__/no_restricted_paths.js @@ -174,6 +174,7 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, { }, { + // Check if dirs that start with 'index' work correctly. code: 'import { X } from "./index_patterns"', filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'), options: [ @@ -389,5 +390,34 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, { }, ], }, + + { + // Don't use index*. + // It won't work with dirs that start with 'index'. + code: 'import { X } from "./index_patterns"', + filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'), + options: [ + { + basePath: __dirname, + zones: [ + { + target: ['files/no_restricted_paths/(public|server)/**/*'], + from: [ + 'files/no_restricted_paths/server/**/*', + '!files/no_restricted_paths/server/index*', + ], + allowSameFolder: true, + }, + ], + }, + ], + errors: [ + { + message: 'Unexpected path "./index_patterns" imported in restricted zone.', + line: 1, + column: 19, + }, + ], + }, ], }); From e64b07f52759c02646a271a74463bb9ff25544b4 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Thu, 31 Oct 2019 08:12:49 +0900 Subject: [PATCH 4/4] Added js. --- .eslintrc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5a314714bc475..310ee47819e30 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -362,10 +362,10 @@ module.exports = { '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', - '!src/plugins/**/public/index.{ts,tsx}', + '!src/plugins/**/public/index.{js,ts,tsx}', 'src/plugins/**/server/**/*', - '!src/plugins/**/server/index.{ts,tsx}', + '!src/plugins/**/server/index.{js,ts,tsx}', ], allowSameFolder: true, },