{"record":{"id":"df8b38e09f1d3f65","repo":"oxc-project/oxc","slug":"use-path-join-or-path-resolve-instead-of-s","errorCode":null,"errorMessage":"Use `path.join()` or `path.resolve()` instead of string concatenation","messagePattern":"Use `path\\.join\\(\\)` or `path\\.resolve\\(\\)` instead of string concatenation","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/node/no_path_concat.rs","lineNumber":15,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, TemplateLiteral},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::IsGlobalReference;\nuse oxc_span::Span;\nuse oxc_str::static_ident;\nuse oxc_syntax::operator::BinaryOperator;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_path_concat_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `path.join()` or `path.resolve()` instead of string concatenation\")\n        .with_help(\"Replace string concatenation of `__dirname` or `__filename` with `path.join()` or `path.resolve()`.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoPathConcat;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows string concatenation with `__dirname` and `__filename`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// In Node.js, the `__dirname` and `__filename` global variables contain the directory path and the file path of the currently executing script file, respectively.\n    /// Sometimes, developers try to use these variables to create paths to other files, such as:\n    ///\n    /// ```js","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/node/no_path_concat.rs#L1-L33","documentation":"Diagnostic from oxlint rule node/no-path-concat (restriction). Building filesystem paths by concatenating __dirname/__filename with literals (binary + or template literals) hard-codes forward slashes: the code happens to work on POSIX and breaks on Windows, where the separator is backslash. path.join()/path.resolve() insert the platform separator and normalize '.', '..' segments, so the rule demands them instead.","triggerScenarios":"A binary + expression or template literal with an operand referencing the unshadowed globals __dirname or __filename (checked via IsGlobalReference, so a local variable named __dirname does not trigger). Triggers: const p = __dirname + '/config.json'; const t = `${__dirname}/data/x.json`;","commonSituations":"Scripts and config loaders developed on macOS/Linux that fail for Windows coworkers or on Windows CI runners; file-server route mapping; test fixture paths; the classic silent cross-platform bug because '/' mostly works as a separator on Windows except drive-absolute and UNC cases.","solutions":["Use path.join(__dirname, 'config.json') — no leading slash on the segment","Use path.resolve(__dirname, 'a', 'b') when you specifically want an absolute path result","For file URLs (import() of assets) use pathToFileURL() from the 'url' module instead of concatenation","Keep node/no-path-concat on in CI to catch Windows-only path bugs before review"],"exampleFix":"// before\nconst configPath = __dirname + '/config.json';\n\n// after\nconst path = require('path');\nconst configPath = path.join(__dirname, 'config.json');","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n\"rules\": { \"node/no-path-concat\": \"error\" }\n\nnpx oxlint -c .oxlintrc.json --deny-warning .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build paths with path.join/path.resolve — never concatenate separators by hand","Run your test suite on Windows (or a windows CI runner) at least once per PR to catch separator bugs early","Use pathToFileURL() when a path must feed import() or URL-based APIs"],"tags":["node","filesystem","cross-platform","windows","oxlint"],"backgroundTag":"cross-platform-path-separators","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"}