Skip to content

Commit

Permalink
eslint no-restricted-path false positive: bug caused by dir names tha…
Browse files Browse the repository at this point in the history
…t start with "index". (elastic#46544)

* index* to index.{ts,tsx}

* Added test.

* Added invalid test.

* Added js.
  • Loading branch information
sainthkh authored and Liza K committed Oct 31, 2019
1 parent 5a67403 commit 7b41019
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,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,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* eslint-disable */
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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,
},
],
},
],
});

0 comments on commit 7b41019

Please sign in to comment.