{"record":{"id":"d27e534229c505bf","repo":"oxc-project/oxc","slug":"do-not-construct-filename-using-fileurltopath","errorCode":null,"errorMessage":"Do not construct filename using `fileURLToPath()`.","messagePattern":"Do not construct filename using `fileURLToPath\\(\\)`\\.","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 converts `import.meta.url` to a file path with `fileURLToPath()` to obtain the current module's file name; `import.meta.filename` provides this directly in modern Node.js. The flagged input is the `fileURLToPath(import.meta.url)` expression. 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 `fileURLToPath(import.meta.url)` with `import.meta.filename` when only the file path is needed","Use `import.meta.dirname`/`path.join` if a specific path composition is intended","Drop the unused `node:url` import and 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-14T00:17:10.932Z"}