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鈥檓 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鈥檓 trying to confine the use of relative paths to a specific folder, and disallow any relative imports outside of it.
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?
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
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.
Most helpful comment
I think you could do
.eslintrcinside theadir with"no-restricted-imports": [2, { "patterns": ["../*"] }], "no-restricted-modules": [2, { "patterns": ["../*"] }](core rules), but that would prohibit any backtracking, even from deeply insideaup 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?