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

Make no-restricted-paths more generic #834

Closed
gaearon opened this issue May 16, 2017 · 3 comments · Fixed by #1238
Closed

Make no-restricted-paths more generic #834

gaearon opened this issue May 16, 2017 · 3 comments · Fixed by #1238

Comments

@gaearon
Copy link

gaearon commented May 16, 2017

no-restricted-paths seems like a great rule.
For example, it lets you ensure nothing in ./a could reach into ./b.

My use case is a bit different. I want to ensure that nothing in ./a could import anything outside of ./a except for node_modules. So if I’m in ./a, I want it to be impossible to import ../index, ../b, or ../../whatever. However I want to preserve the ability to import Node modules, like 'my-package' which can technically occur at any level above, and could even symlink to ./b.

Does this request make sense? Basically I’m trying to confine the use of relative paths to a specific folder, and disallow any relative imports outside of it.

@ljharb
Copy link
Member

ljharb commented May 16, 2017

I think you could do .eslintrc inside the a dir with "no-restricted-imports": [2, { "patterns": ["../*"] }], "no-restricted-modules": [2, { "patterns": ["../*"] }] (core rules), but that would prohibit any backtracking, even from deeply inside a up to a higher level that was still within 'a'.

tbh I think this is probably better as a separate rule, that ensures exactly what you're trying to achieve. It'd be a good rule to enable by default in every dir with a package.json, for example - or better, the rule could have a mode that prevents any relative imports that come from outside a package.json hierarchy?

@gaearon
Copy link
Author

gaearon commented May 17, 2017

Yes you're right I want to allow backtracking inside of it. I agree this could be a separate rule.

I'd rather have flexibility over just relying on package.json. For example in case of Create React App the sources are confined to ./src, and while package.json is one level above, you're still not supposed to import from, for example, ./public

@ljharb
Copy link
Member

ljharb commented May 17, 2017

Sure, I agree there's a case where you want to define a more restrictive jail than "package.json", and that absolutely should be doable - but I think the default/base case is "jailing to package.json", which limiting to "src" would trump within that directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants