Is there a simple solution (lint rule perhaps?) which can help enforce clean code imports through index files? I'd like to prevent importing code from "cousin" files, except if it is made available through an index file.
Ex:
- app
+ dogs
| + index.ts
| + breeds
| | + retriever.ts
| | + schnauzer.ts
| + activities
| + playing.ts
| + walking.ts
+ cats
+ index.ts
+ breeds
| + siamese.ts
| + persion.ts
+ activities
+ sleeping.ts
+ hunting.ts
Importing from the perspective of cats/activities/hunting.ts
:
import { sleeping } from './sleeping' // VALID - inside same folder
import { siamese } from '../breeds/siamese' // VALID - inside cats module
import { playing } from '../../dogs' // VALID - importing from an index
import { retriever} from '../../dogs/activities/breeds' // INVALID - cousin file outside module possibly not exported from index