github-pages-deploy-action/node_modules/eslint/lib/rules/no-path-concat.js

64 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2020-03-07 11:45:40 +08:00
/**
* @fileoverview Disallow string concatenation when using __dirname and __filename
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
2020-05-15 05:33:08 +08:00
deprecated: true,
2020-06-06 22:11:37 +08:00
replacedBy: [],
2020-05-15 05:33:08 +08:00
2020-03-07 11:45:40 +08:00
type: "suggestion",
docs: {
description: "disallow string concatenation with `__dirname` and `__filename`",
category: "Node.js and CommonJS",
recommended: false,
url: "https://eslint.org/docs/rules/no-path-concat"
},
2020-05-15 05:33:08 +08:00
schema: [],
messages: {
usePathFunctions: "Use path.join() or path.resolve() instead of + to create paths."
}
2020-03-07 11:45:40 +08:00
},
create(context) {
const MATCHER = /^__(?:dir|file)name$/u;
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
return {
BinaryExpression(node) {
const left = node.left,
right = node.right;
if (node.operator === "+" &&
((left.type === "Identifier" && MATCHER.test(left.name)) ||
(right.type === "Identifier" && MATCHER.test(right.name)))
) {
2020-05-15 05:33:08 +08:00
context.report({
node,
messageId: "usePathFunctions"
});
2020-03-07 11:45:40 +08:00
}
}
};
}
};