eslint no-restricted-path false positive: bug caused by dir names that start with "index". (#46544)

* index* to index.{ts,tsx}

* Added test.

* Added invalid test.

* Added js.
This commit is contained in:
sainthkh 2019-10-31 19:40:53 +09:00 committed by Liza Katz
parent 9e00c78f4c
commit faa48d591d
3 changed files with 53 additions and 2 deletions

View file

@ -362,10 +362,10 @@ module.exports = {
'!src/core/server/*.test.mocks.ts',
'src/plugins/**/public/**/*',
'!src/plugins/**/public/index*',
'!src/plugins/**/public/index.{js,ts,tsx}',
'src/plugins/**/server/**/*',
'!src/plugins/**/server/index*',
'!src/plugins/**/server/index.{js,ts,tsx}',
],
allowSameFolder: true,
},

View file

@ -172,6 +172,27 @@ 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: [
{
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: [
@ -369,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,
},
],
},
],
});