2 * @fileoverview Disallow string concatenation when using __dirname and __filename
3 * @author Nicholas C. Zakas
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
16 description: "disallow string concatenation with `__dirname` and `__filename`",
17 category: "Node.js and CommonJS",
19 url: "https://eslint.org/docs/rules/no-path-concat"
27 const MATCHER = /^__(?:dir|file)name$/u;
29 //--------------------------------------------------------------------------
31 //--------------------------------------------------------------------------
35 BinaryExpression(node) {
37 const left = node.left,
40 if (node.operator === "+" &&
41 ((left.type === "Identifier" && MATCHER.test(left.name)) ||
42 (right.type === "Identifier" && MATCHER.test(right.name)))
45 context.report({ node, message: "Use path.join() or path.resolve() instead of + to create paths." });