Skip to content

Commit

Permalink
chore(prefer-called-with): convert to typescript (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored and SimenB committed Aug 12, 2019
1 parent 538ec03 commit 4ca5889
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
@@ -1,7 +1,7 @@
import { RuleTester } from 'eslint';
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../prefer-called-with';

const ruleTester = new RuleTester();
const ruleTester = new TSESLint.RuleTester();

ruleTester.run('prefer-called-with', rule, {
valid: [
Expand Down
36 changes: 0 additions & 36 deletions src/rules/prefer-called-with.js

This file was deleted.

41 changes: 41 additions & 0 deletions src/rules/prefer-called-with.ts
@@ -0,0 +1,41 @@
import { createRule, isExpectCall, parseExpectCall } from './tsUtils';

export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Suggest using `toBeCalledWith()` OR `toHaveBeenCalledWith()`',
recommended: false,
},
messages: {
preferCalledWith: 'Prefer {{name}}With(/* expected args */)',
},
type: 'suggestion',
schema: [],
},
defaultOptions: [],
create(context) {
return {
CallExpression(node) {
if (!isExpectCall(node)) {
return;
}

const { modifier, matcher } = parseExpectCall(node);

// Could check resolves/rejects here but not a likely idiom.
if (matcher && !modifier) {
if (['toBeCalled', 'toHaveBeenCalled'].includes(matcher.name)) {
context.report({
data: { name: matcher.name }, // todo: rename to 'matcherName'
messageId: 'preferCalledWith',
node: matcher.node.property,
});
}
}
},
};
},
});

0 comments on commit 4ca5889

Please sign in to comment.