eslint-plugin-jest 26.5.2 → 26.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,16 +64,26 @@ var _default = (0, _utils2.createRule)({
64
64
  return;
65
65
  }
66
66
 
67
- const matcherValue = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value; // we need to negate the expectation if the current expected
67
+ const matcherValue = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value;
68
+ const negation = modifier !== null && modifier !== void 0 && modifier.negation ? {
69
+ node: modifier.negation
70
+ } : (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not ? modifier : null; // we need to negate the expectation if the current expected
68
71
  // value is itself negated by the "not" modifier
69
72
 
70
- const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === !!modifier;
73
+ const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === !!negation;
71
74
 
72
75
  const buildFixer = equalityMatcher => fixer => {
73
- const sourceCode = context.getSourceCode();
76
+ const sourceCode = context.getSourceCode(); // preserve the existing modifier if it's not a negation
77
+
78
+ let modifierText = modifier && (modifier === null || modifier === void 0 ? void 0 : modifier.node) !== (negation === null || negation === void 0 ? void 0 : negation.node) ? `.${modifier.name}` : '';
79
+
80
+ if (addNotModifier) {
81
+ modifierText += `.${_utils2.ModifierName.not}`;
82
+ }
83
+
74
84
  return [// replace the comparison argument with the left-hand side of the comparison
75
85
  fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
76
- fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils2.ModifierName.not}.${equalityMatcher}` : `.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
86
+ fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], `${modifierText}.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
77
87
  fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
78
88
  };
79
89
 
@@ -86,7 +96,7 @@ var _default = (0, _utils2.createRule)({
86
96
  },
87
97
  fix: buildFixer(equalityMatcher)
88
98
  })),
89
- node: (modifier || matcher).node.property
99
+ node: (negation || matcher).node.property
90
100
  });
91
101
  }
92
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "26.5.2",
3
+ "version": "26.5.3",
4
4
  "description": "ESLint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",