no-nested-ternary.js 957 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @fileoverview Rule to flag nested ternary expressions
  3. * @author Ian Christian Myers
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description: "disallow nested ternary expressions",
  13. category: "Stylistic Issues",
  14. recommended: false,
  15. url: "https://eslint.org/docs/rules/no-nested-ternary"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. return {
  21. ConditionalExpression(node) {
  22. if (node.alternate.type === "ConditionalExpression" ||
  23. node.consequent.type === "ConditionalExpression") {
  24. context.report({ node, message: "Do not nest ternary expressions." });
  25. }
  26. }
  27. };
  28. }
  29. };