Skip to content

Commit ddb2132

Browse files
malykhinviljharb
authored andcommitted
[Fix] no-restricted-paths: fix false positive matches
Fixes #2089
1 parent bc99b86 commit ddb2132

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66

77
## [Unreleased]
88

9+
### Fixed
10+
- [`no-restricted-paths`]: fix false positive matches ([#2090], thanks [@malykhinvi])
11+
912
### Changed
1013
- [Docs] Add `no-relative-packages` to list of to the list of rules ([#2075], thanks [@arvigeus])
1114

@@ -786,6 +789,7 @@ for info on changes for earlier releases.
786789

787790
[`memo-parser`]: ./memo-parser/README.md
788791

792+
[#2090]: https://github.com/benmosher/eslint-plugin-import/pull/2090
789793
[#2075]: https://github.com/benmosher/eslint-plugin-import/pull/2075
790794
[#2071]: https://github.com/benmosher/eslint-plugin-import/pull/2071
791795
[#2034]: https://github.com/benmosher/eslint-plugin-import/pull/2034
@@ -1238,7 +1242,6 @@ for info on changes for earlier releases.
12381242
[@wtgtybhertgeghgtwtg]: https://github.com/wtgtybhertgeghgtwtg
12391243
[@duncanbeevers]: https://github.com/duncanbeevers
12401244
[@giodamelio]: https://github.com/giodamelio
1241-
[@ntdb]: https://github.com/ntdb
12421245
[@ramasilveyra]: https://github.com/ramasilveyra
12431246
[@sompylasar]: https://github.com/sompylasar
12441247
[@kevin940726]: https://github.com/kevin940726

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"dependencies": {
102102
"array-includes": "^3.1.3",
103103
"array.prototype.flat": "^1.2.4",
104-
"contains-path": "^1.0.0",
105104
"debug": "^2.6.9",
106105
"doctrine": "^2.1.0",
107106
"eslint-import-resolver-node": "^0.3.4",

src/rules/no-restricted-paths.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import containsPath from 'contains-path';
21
import path from 'path';
32

43
import resolve from 'eslint-module-utils/resolve';
54
import moduleVisitor from 'eslint-module-utils/moduleVisitor';
65
import docsUrl from '../docsUrl';
76
import importType from '../core/importType';
87

8+
const containsPath = (filepath, target) => {
9+
const relative = path.relative(target, filepath);
10+
return relative === '' || !relative.startsWith('..');
11+
};
12+
913
module.exports = {
1014
meta: {
1115
type: 'problem',

tests/files/restricted-paths/server/two-new/a.js

Whitespace-only changes.

tests/src/rules/no-restricted-paths.js

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ ruleTester.run('no-restricted-paths', rule, {
5050
} ],
5151
} ],
5252
}),
53+
test({
54+
code: 'import a from "../one/a.js"',
55+
filename: testFilePath('./restricted-paths/server/two-new/a.js'),
56+
options: [ {
57+
zones: [ {
58+
target: './tests/files/restricted-paths/server/two',
59+
from: './tests/files/restricted-paths/server',
60+
except: [],
61+
} ],
62+
} ],
63+
}),
5364

5465

5566
// irrelevant function calls

0 commit comments

Comments
 (0)