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-plusplus.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @fileoverview Rule to flag use of unary increment and decrement operators.
  3. * @author Ian Christian Myers
  4. * @author Brody McKee (github.com/mrmckeb)
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: "suggestion",
  13. docs: {
  14. description: "disallow the unary operators `++` and `--`",
  15. category: "Stylistic Issues",
  16. recommended: false,
  17. url: "https://eslint.org/docs/rules/no-plusplus"
  18. },
  19. schema: [
  20. {
  21. type: "object",
  22. properties: {
  23. allowForLoopAfterthoughts: {
  24. type: "boolean"
  25. }
  26. },
  27. additionalProperties: false
  28. }
  29. ]
  30. },
  31. create(context) {
  32. const config = context.options[0];
  33. let allowInForAfterthought = false;
  34. if (typeof config === "object") {
  35. allowInForAfterthought = config.allowForLoopAfterthoughts === true;
  36. }
  37. return {
  38. UpdateExpression(node) {
  39. if (allowInForAfterthought && node.parent.type === "ForStatement") {
  40. return;
  41. }
  42. context.report({
  43. node,
  44. message: "Unary operator '{{operator}}' used.",
  45. data: {
  46. operator: node.operator
  47. }
  48. });
  49. }
  50. };
  51. }
  52. };