no-import-private
ℹ️ This rule is not included in the recommended rules.
This rule disallows importing modules from private
directories at different hierarchical levels.
When setting it, you need to write the following:
js
// eslint.config.mjs
import eslintCdkPlugin from "eslint-cdk-plugin";
export default [
{
plugins: {
cdk: eslintCdkPlugin,
},
rules: {
...cdkPlugin.configs.recommended.rules,
"cdk/no-import-private": "error",
},
},
];
The private directory is intended to contain internal implementation that should only be used within its parent directory.
By disallowing imports from a different hierarchy, it promotes proper modularization and encapsulation.
✅ Correct Example
ts
// src/constructs/my-construct.ts
import { MyConstruct } from "./private/my-construct";
❌ Incorrect Example
ts
// src/constructs/my-construct.ts
import { MyConstruct } from "../private/my-construct";
import { MyConstruct } from "../my-app/private/my-construct";