Urara-Blog/node_modules/.pnpm-store/v3/files/0b/cad8bf46df84d90bd8518c3f56448000b00b33a1ea14a8803ccb9fcbd8a147daf61b228244bf4c28e3de280ab9514e8db64e4f35bc7db04cec8e17926c8ce6
2022-08-14 01:14:53 +08:00

64 lines
1.7 KiB
Text

/**
* @fileoverview Disallow string concatenation when using __dirname and __filename
* @author Nicholas C. Zakas
* @deprecated in ESLint v7.0.0
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "Disallow string concatenation with `__dirname` and `__filename`",
recommended: false,
url: "https://eslint.org/docs/rules/no-path-concat"
},
schema: [],
messages: {
usePathFunctions: "Use path.join() or path.resolve() instead of + to create paths."
}
},
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)))
) {
context.report({
node,
messageId: "usePathFunctions"
});
}
}
};
}
};