no-ternary.js 882 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @fileoverview Rule to flag use of ternary operators.
  3. * @author Ian Christian Myers
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. /** @type {import('../shared/types').Rule} */
  10. module.exports = {
  11. meta: {
  12. type: "suggestion",
  13. docs: {
  14. description: "Disallow ternary operators",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-ternary"
  17. },
  18. schema: [],
  19. messages: {
  20. noTernaryOperator: "Ternary operator used."
  21. }
  22. },
  23. create(context) {
  24. return {
  25. ConditionalExpression(node) {
  26. context.report({ node, messageId: "noTernaryOperator" });
  27. }
  28. };
  29. }
  30. };