{"record":{"id":"3cb2b27f0e7149bc","repo":"oxc-project/oxc","slug":"relative-imports-from-parent-directories-are-not-a","errorCode":null,"errorMessage":"Relative imports from parent directories are not allowed","messagePattern":"Relative imports from parent directories are not allowed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/no_relative_parent_imports.rs","lineNumber":9,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_relative_parent_imports_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Relative imports from parent directories are not allowed\")\n        .with_help(\n            \"Move the file to the same directory, use dependency injection, or convert to a package.\",\n        )\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoRelativeParentImports;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Forbids importing modules from parent directories using relative paths.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This restriction enforces tree-like folder structures instead of complex\n    /// graph-like structures, making large codebases easier to maintain.","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_relative_parent_imports.rs#L1-L27","documentation":"Diagnostic from the oxlint rule import/no-relative-parent-imports (restriction category). It fires on any import that reaches into a parent directory via `../`, enforcing a layered architecture where modules may only import downward (their own subtree and packages). The help offers the three standard escapes: move the file, inject the dependency, or package the shared code.","triggerScenarios":"Any import whose specifier contains a parent-relative segment (`import x from '../shared/x'`, `../../lib/util`) in a linted file — reported from no_relative_parent_imports_diagnostic at crates/oxc_linter/src/rules/import/no_relative_parent_imports.rs:9.","commonSituations":"Enforced layering (feature folders that must not reach into siblings via ..); monorepos converting relative webs into package imports; refactors where a file moved deeper and its imports were mechanically updated with ../ prefixes.","solutions":["Move the shared code into a common ancestor directory both importers can reach downward, or extract it into a workspace package imported by name","Configure path aliases (tsconfig paths / bundler alias) so imports go through a stable package-style specifier instead of ../","Invert the dependency: pass the value/function in as a parameter (dependency injection) instead of importing upward","If the policy does not fit a corner of the repo, scope the rule off for those paths"],"exampleFix":"// before (src/features/auth/session.ts)\nimport { formatDate } from '../../utils/date';\n\n// after (with tsconfig paths: \"@utils/*\": [\"src/utils/*\"])\nimport { formatDate } from '@utils/date';","handlingStrategy":"validation","validationCode":"// rg -n \"from\\\\s+['\\\"]\\\\.\\\\./\" src\n// .oxlintrc.json: { \"rules\": { \"import/no-relative-parent-imports\": \"warn\" } }\n// tsconfig escape hatch: { \"compilerOptions\": { \"baseUrl\": \"src\", \"paths\": { \"@/*\": [\"*\"] } } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set up path aliases (@/ or package names) before the codebase grows relative webs","Place shared code in common ancestors, never reach upward with ../","In monorepos, extract cross-cutting utils into a workspace package imported by name"],"tags":["lint","oxlint","imports","relative-import","architecture","layering","monorepo"],"backgroundTag":"relative-parent-import","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}