Skip to content

Commit

Permalink
fix(prefer-strict-equal): only run if expect is used (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyking authored and SimenB committed Sep 30, 2018
1 parent 2894eaa commit ee2647e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion rules/__tests__/prefer-strict-equal.test.js
Expand Up @@ -6,7 +6,10 @@ const rule = require('../prefer-strict-equal');
const ruleTester = new RuleTester();

ruleTester.run('prefer-strict-equal', rule, {
valid: ['expect(something).toStrictEqual(somethingElse);'],
valid: [
'expect(something).toStrictEqual(somethingElse);',
"a().toEqual('b')",
],
invalid: [
{
code: 'expect(something).toEqual(somethingElse);',
Expand Down
13 changes: 10 additions & 3 deletions rules/prefer-strict-equal.js
@@ -1,6 +1,8 @@
'use strict';

const expectCase = require('./util').expectCase;
const getDocsUrl = require('./util').getDocsUrl;
const method = require('./util').method;

module.exports = {
meta: {
Expand All @@ -12,14 +14,19 @@ module.exports = {
create(context) {
return {
CallExpression(node) {
const propertyName = node.callee.property && node.callee.property.name;
if (!expectCase(node)) {
return;
}

const propertyName = method(node) && method(node).name;

if (propertyName === 'toEqual') {
context.report({
fix(fixer) {
return [fixer.replaceText(node.callee.property, 'toStrictEqual')];
return [fixer.replaceText(method(node), 'toStrictEqual')];
},
message: 'Use toStrictEqual() instead',
node: node.callee.property,
node: method(node),
});
}
},
Expand Down

0 comments on commit ee2647e

Please sign in to comment.