Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-path-concat.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @fileoverview Disallow string concatenation when using __dirname and __filename
  3. * @author Nicholas C. Zakas
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow string concatenation with `__dirname` and `__filename`",
  14. category: "Node.js and CommonJS",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-path-concat"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. const MATCHER = /^__(?:dir|file)name$/;
  22. //--------------------------------------------------------------------------
  23. // Public
  24. //--------------------------------------------------------------------------
  25. return {
  26. BinaryExpression(node) {
  27. const left = node.left,
  28. right = node.right;
  29. if (node.operator === "+" &&
  30. ((left.type === "Identifier" && MATCHER.test(left.name)) ||
  31. (right.type === "Identifier" && MATCHER.test(right.name)))
  32. ) {
  33. context.report({ node, message: "Use path.join() or path.resolve() instead of + to create paths." });
  34. }
  35. }
  36. };
  37. }
  38. };