1 | /**
|
2 | * @fileoverview Disallow string concatenation when using __dirname and __filename
|
3 | * @author Nicholas C. Zakas
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Rule Definition
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | module.exports = function(context) {
|
12 |
|
13 | var MATCHER = /^__(?:dir|file)name$/;
|
14 |
|
15 | //--------------------------------------------------------------------------
|
16 | // Public
|
17 | //--------------------------------------------------------------------------
|
18 |
|
19 | return {
|
20 |
|
21 | "BinaryExpression": function(node) {
|
22 |
|
23 | var left = node.left,
|
24 | right = node.right;
|
25 |
|
26 | if (node.operator === "+" &&
|
27 | ((left.type === "Identifier" && MATCHER.test(left.name)) ||
|
28 | (right.type === "Identifier" && MATCHER.test(right.name)))
|
29 | ) {
|
30 |
|
31 | context.report(node, "Use path.join() or path.resolve() instead of + to create paths.");
|
32 | }
|
33 | }
|
34 |
|
35 | };
|
36 |
|
37 | };
|
38 |
|
39 | module.exports.schema = [];
|