no-multi-assign.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @fileoverview Rule to check use of chained assignment expressions
  3. * @author Stewart Rand
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow use of chained assignment expressions",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-multi-assign"
  17. },
  18. schema: [],
  19. messages: {
  20. unexpectedChain: "Unexpected chained assignment."
  21. }
  22. },
  23. create(context) {
  24. //--------------------------------------------------------------------------
  25. // Public
  26. //--------------------------------------------------------------------------
  27. return {
  28. AssignmentExpression(node) {
  29. if (["AssignmentExpression", "VariableDeclarator"].indexOf(node.parent.type) !== -1) {
  30. context.report({
  31. node,
  32. messageId: "unexpectedChain"
  33. });
  34. }
  35. }
  36. };
  37. }
  38. };