no-compare-against-boolean-literals.js 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * @fileoverview Restrict comparing against `true` or `false`.
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. "use strict";
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. url:
  13. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/no-compare-against-boolean-literals.html",
  14. },
  15. type: "suggestion",
  16. },
  17. create(context) {
  18. return {
  19. BinaryExpression(node) {
  20. if (
  21. ["==", "!="].includes(node.operator) &&
  22. (["true", "false"].includes(node.left.raw) ||
  23. ["true", "false"].includes(node.right.raw))
  24. ) {
  25. context.report(
  26. node,
  27. "Don't compare for inexact equality against boolean literals"
  28. );
  29. }
  30. },
  31. };
  32. },
  33. };