Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] no-restricted-paths: false-positive matches #2090

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]

### Fixed
- [`no-restricted-paths`]: fix false positive matches ([#2090], thanks [@malykhinvi])

### Changed
- [Docs] Add `no-relative-packages` to list of to the list of rules ([#2075], thanks [@arvigeus])

Expand Down Expand Up @@ -786,6 +789,7 @@ for info on changes for earlier releases.

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

[#2090]: https://github.com/benmosher/eslint-plugin-import/pull/2090
[#2075]: https://github.com/benmosher/eslint-plugin-import/pull/2075
[#2071]: https://github.com/benmosher/eslint-plugin-import/pull/2071
[#2034]: https://github.com/benmosher/eslint-plugin-import/pull/2034
Expand Down Expand Up @@ -1238,7 +1242,6 @@ for info on changes for earlier releases.
[@wtgtybhertgeghgtwtg]: https://github.com/wtgtybhertgeghgtwtg
[@duncanbeevers]: https://github.com/duncanbeevers
[@giodamelio]: https://github.com/giodamelio
[@ntdb]: https://github.com/ntdb
[@ramasilveyra]: https://github.com/ramasilveyra
[@sompylasar]: https://github.com/sompylasar
[@kevin940726]: https://github.com/kevin940726
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"dependencies": {
"array-includes": "^3.1.3",
"array.prototype.flat": "^1.2.4",
"contains-path": "^1.0.0",
"debug": "^2.6.9",
"doctrine": "^2.1.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
6 changes: 5 additions & 1 deletion src/rules/no-restricted-paths.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import containsPath from 'contains-path';
import path from 'path';

import resolve from 'eslint-module-utils/resolve';
import moduleVisitor from 'eslint-module-utils/moduleVisitor';
import docsUrl from '../docsUrl';
import importType from '../core/importType';

const containsPath = (filepath, target) => {
const relative = path.relative(target, filepath);
return relative === '' || !relative.startsWith('..');
};

module.exports = {
meta: {
type: 'problem',
Expand Down
Empty file.
11 changes: 11 additions & 0 deletions tests/src/rules/no-restricted-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ ruleTester.run('no-restricted-paths', rule, {
} ],
} ],
}),
test({
code: 'import a from "../one/a.js"',
filename: testFilePath('./restricted-paths/server/two-new/a.js'),
options: [ {
zones: [ {
target: './tests/files/restricted-paths/server/two',
from: './tests/files/restricted-paths/server',
except: [],
} ],
} ],
}),


// irrelevant function calls
Expand Down