I'm not sure if this is possible with any existing rule.
I have a monorepo and I would like to ensure that packages don't import each others files using relative imports. For example:
βββ packages
βΒ Β βββ first
βΒ Β β βββ index.js
βΒ Β β βββ package.json
βΒ Β βββ second
βΒ Β βββ b.js
βΒ Β βββ package.json
βββ base.js
βββ package.json
packages/first/index.js it disallows require('../../base') packages/first/index.js it disallows require('../second/b') but allows require('second/b') (assuming second is the package name).packages/second/b.js it disallows require('../first') but allows require('first') (assuming first is the package name)base.js it disallows require('./packages/second/b') but allows require('second/b') (this is less important than the above cases).I think the formulation of the rule would be that any folder that contains a package.json forms a boundary that no relative imports can cross.
I donβt think the rule should handle bare imports of other sub projects, but a rule that specifies boundaries - dirs from which relative imports can not escape - seems quite useful.
Totally agree with @ljharb, need this too.
It looks like this may cover this case pretty well.
Most helpful comment
I donβt think the rule should handle bare imports of other sub projects, but a rule that specifies boundaries - dirs from which relative imports can not escape - seems quite useful.