prefer-strict-equal.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _utils = require("./utils");
  7. var _default = (0, _utils.createRule)({
  8. name: __filename,
  9. meta: {
  10. docs: {
  11. category: 'Best Practices',
  12. description: 'Suggest using `toStrictEqual()`',
  13. recommended: false,
  14. suggestion: true
  15. },
  16. messages: {
  17. useToStrictEqual: 'Use `toStrictEqual()` instead',
  18. suggestReplaceWithStrictEqual: 'Replace with `toStrictEqual()`'
  19. },
  20. type: 'suggestion',
  21. schema: []
  22. },
  23. defaultOptions: [],
  24. create(context) {
  25. return {
  26. CallExpression(node) {
  27. if (!(0, _utils.isExpectCall)(node)) {
  28. return;
  29. }
  30. const {
  31. matcher
  32. } = (0, _utils.parseExpectCall)(node);
  33. if (matcher && (0, _utils.isParsedEqualityMatcherCall)(matcher, _utils.EqualityMatcher.toEqual)) {
  34. context.report({
  35. messageId: 'useToStrictEqual',
  36. node: matcher.node.property,
  37. suggest: [{
  38. messageId: 'suggestReplaceWithStrictEqual',
  39. fix: fixer => [fixer.replaceText(matcher.node.property, _utils.EqualityMatcher.toStrictEqual)]
  40. }]
  41. });
  42. }
  43. }
  44. };
  45. }
  46. });
  47. exports.default = _default;