blob: 184c9182b4d536f82d39093ed84f0e51306e5881 [file] [log] [blame]
Yang Guo4fd355c2019-09-19 10:59:03 +02001/**
2 * @fileoverview Disallow string concatenation when using __dirname and __filename
3 * @author Nicholas C. Zakas
Tim van der Lippe0fb47802021-11-08 16:23:10 +00004 * @deprecated in ESLint v7.0.0
Yang Guo4fd355c2019-09-19 10:59:03 +02005 */
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
Tim van der Lippe16aca392020-11-13 11:37:13 +000014 deprecated: true,
15
16 replacedBy: [],
17
Yang Guo4fd355c2019-09-19 10:59:03 +020018 type: "suggestion",
19
20 docs: {
21 description: "disallow string concatenation with `__dirname` and `__filename`",
Yang Guo4fd355c2019-09-19 10:59:03 +020022 recommended: false,
23 url: "https://eslint.org/docs/rules/no-path-concat"
24 },
25
Tim van der Lippe16aca392020-11-13 11:37:13 +000026 schema: [],
27
28 messages: {
29 usePathFunctions: "Use path.join() or path.resolve() instead of + to create paths."
30 }
Yang Guo4fd355c2019-09-19 10:59:03 +020031 },
32
33 create(context) {
34
35 const MATCHER = /^__(?:dir|file)name$/u;
36
37 //--------------------------------------------------------------------------
38 // Public
39 //--------------------------------------------------------------------------
40
41 return {
42
43 BinaryExpression(node) {
44
45 const left = node.left,
46 right = node.right;
47
48 if (node.operator === "+" &&
49 ((left.type === "Identifier" && MATCHER.test(left.name)) ||
50 (right.type === "Identifier" && MATCHER.test(right.name)))
51 ) {
52
Tim van der Lippe16aca392020-11-13 11:37:13 +000053 context.report({
54 node,
55 messageId: "usePathFunctions"
56 });
Yang Guo4fd355c2019-09-19 10:59:03 +020057 }
58 }
59
60 };
61
62 }
63};