no-path-concat
Disallow building paths with + from __dirname or __filename
deprecated
A path built with + has the separator written into the string. __dirname + "/config.json" mixes \ and / on Windows, and a forgotten slash gives you the wrong path without an error. path.join() and path.resolve() put in the right separator and clean up .. and doubled slashes.
ESLint has deprecated this rule. Use n/no-path-concat instead.
Examples#
example.js1 problem
const configPath = __dirname + "/config.json"Use path.join() or path.resolve() instead of + to create paths.;example.jsNo problems
const path = require("node:path");
const configPath = path.join(__dirname, "config.json");Only + is checked. A template literal has the same problem, but it isn't reported:
example.jsNo problems
const configPath = `${__dirname}/config.json`;