{"record":{"id":"ed1a15267dc7a399","repo":"oxc-project/oxc","slug":"do-not-construct-dirname","errorCode":null,"errorMessage":"Do not construct dirname.","messagePattern":"Do not construct dirname\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_import_meta_properties.rs","lineNumber":48,"sourceCode":"\nimpl ProblemKind {\n    fn message(self) -> &'static str {\n        match self {\n            Self::Dirname => \"Do not construct dirname.\",\n            Self::Filename => \"Do not construct filename using `fileURLToPath()`.\",\n        }\n    }\n\n    fn property(self) -> &'static str {\n        match self {\n            Self::Dirname => \"dirname\",\n            Self::Filename => \"filename\",\n        }\n    }\n}\n\nfn prefer_import_meta_diagnostic(span: Span, kind: ProblemKind) -> OxcDiagnostic {\n    OxcDiagnostic::warn(kind.message())\n        .with_help(format!(\"Replace this expression with `import.meta.{}`.\", kind.property()))\n        .with_label(span)\n}\n\nfn report_problem(ctx: &LintContext<'_>, span: Span, kind: ProblemKind) {\n    ctx.diagnostic_with_fix(prefer_import_meta_diagnostic(span, kind), |fixer| {\n        fixer.replace(span, format!(\"import.meta.{}\", kind.property()))\n    });\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferImportMetaProperties;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prefer `import.meta.{dirname,filename}` over legacy\n    /// techniques for getting file paths.","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_import_meta_properties.rs#L30-L66","documentation":"Diagnostic from the unicorn/prefer-import-meta-properties lint rule. It fires when code manually derives a directory path from `import.meta.url` (typically via `fileURLToPath()` plus `dirname()` from `node:path`) instead of using the built-in `import.meta.dirname` property available in modern Node.js. The flagged input is the expression computing the directory of the current module. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_import_meta_properties.rs:48 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the `dirname(fileURLToPath(import.meta.url))` expression with `import.meta.dirname`","Drop the now-unused `node:path` and `node:url` imports","Apply the rule's auto-fix"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}