Skip to content

Commit

Permalink
fix(prefer-strict-equal): provide suggestion instead of autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jun 20, 2020
1 parent 782d8fa commit 2eaed2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/rules/__tests__/prefer-strict-equal.test.ts
Expand Up @@ -12,8 +12,19 @@ ruleTester.run('prefer-strict-equal', rule, {
invalid: [
{
code: 'expect(something).toEqual(somethingElse);',
errors: [{ messageId: 'useToStrictEqual', column: 19, line: 1 }],
output: 'expect(something).toStrictEqual(somethingElse);',
errors: [
{
messageId: 'useToStrictEqual',
column: 19,
line: 1,
suggestions: [
{
messageId: 'suggestReplaceWithStrictEqual',
output: 'expect(something).toStrictEqual(somethingElse);',
},
],
},
],
},
],
});
20 changes: 13 additions & 7 deletions src/rules/prefer-strict-equal.ts
Expand Up @@ -15,7 +15,8 @@ export default createRule({
recommended: false,
},
messages: {
useToStrictEqual: 'Use toStrictEqual() instead',
useToStrictEqual: 'Use `toStrictEqual()` instead',
suggestReplaceWithStrictEqual: 'Replace with `toStrictEqual()`',
},
fixable: 'code',
type: 'suggestion',
Expand All @@ -36,14 +37,19 @@ export default createRule({
isParsedEqualityMatcherCall(matcher, EqualityMatcher.toEqual)
) {
context.report({
fix: fixer => [
fixer.replaceText(
matcher.node.property,
EqualityMatcher.toStrictEqual,
),
],
messageId: 'useToStrictEqual',
node: matcher.node.property,
suggest: [
{
messageId: 'suggestReplaceWithStrictEqual',
fix: fixer => [
fixer.replaceText(
matcher.node.property,
EqualityMatcher.toStrictEqual,
),
],
},
],
});
}
},
Expand Down

0 comments on commit 2eaed2b

Please sign in to comment.