no-negated-in-lhs.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @fileoverview A rule to disallow negated left operands of the `in` operator
  3. * @author Michael Ficarra
  4. * @deprecated in ESLint v3.3.0
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. /** @type {import('../types').Rule.RuleModule} */
  11. module.exports = {
  12. meta: {
  13. type: "problem",
  14. docs: {
  15. description:
  16. "Disallow negating the left operand in `in` expressions",
  17. recommended: false,
  18. url: "https://eslint.org/docs/latest/rules/no-negated-in-lhs",
  19. },
  20. deprecated: {
  21. message: "Renamed rule.",
  22. url: "https://eslint.org/blog/2016/08/eslint-v3.3.0-released/#deprecated-rules",
  23. deprecatedSince: "3.3.0",
  24. availableUntil: "11.0.0",
  25. replacedBy: [
  26. {
  27. rule: {
  28. name: "no-unsafe-negation",
  29. url: "https://eslint.org/docs/rules/no-unsafe-negation",
  30. },
  31. },
  32. ],
  33. },
  34. schema: [],
  35. messages: {
  36. negatedLHS: "The 'in' expression's left operand is negated.",
  37. },
  38. },
  39. create(context) {
  40. return {
  41. BinaryExpression(node) {
  42. if (
  43. node.operator === "in" &&
  44. node.left.type === "UnaryExpression" &&
  45. node.left.operator === "!"
  46. ) {
  47. context.report({ node, messageId: "negatedLHS" });
  48. }
  49. },
  50. };
  51. },
  52. };