source: frontend/node_modules/eslint-plugin-jest/lib/rules/no-alias-methods.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _utils = require("./utils");
9
10var _default = (0, _utils.createRule)({
11 name: __filename,
12 meta: {
13 docs: {
14 category: 'Best Practices',
15 description: 'Disallow alias methods',
16 recommended: false
17 },
18 messages: {
19 replaceAlias: `Replace {{ alias }}() with its canonical name of {{ canonical }}()`
20 },
21 fixable: 'code',
22 type: 'suggestion',
23 schema: []
24 },
25 defaultOptions: [],
26
27 create(context) {
28 // map of jest matcher aliases & their canonical names
29 const methodNames = {
30 toBeCalled: 'toHaveBeenCalled',
31 toBeCalledTimes: 'toHaveBeenCalledTimes',
32 toBeCalledWith: 'toHaveBeenCalledWith',
33 lastCalledWith: 'toHaveBeenLastCalledWith',
34 nthCalledWith: 'toHaveBeenNthCalledWith',
35 toReturn: 'toHaveReturned',
36 toReturnTimes: 'toHaveReturnedTimes',
37 toReturnWith: 'toHaveReturnedWith',
38 lastReturnedWith: 'toHaveLastReturnedWith',
39 nthReturnedWith: 'toHaveNthReturnedWith',
40 toThrowError: 'toThrow'
41 };
42 return {
43 CallExpression(node) {
44 if (!(0, _utils.isExpectCall)(node)) {
45 return;
46 }
47
48 const {
49 matcher
50 } = (0, _utils.parseExpectCall)(node);
51
52 if (!matcher) {
53 return;
54 }
55
56 const alias = matcher.name;
57
58 if (alias in methodNames) {
59 const canonical = methodNames[alias];
60 context.report({
61 messageId: 'replaceAlias',
62 data: {
63 alias,
64 canonical
65 },
66 node: matcher.node.property,
67 fix: fixer => [fixer.replaceText(matcher.node.property, canonical)]
68 });
69 }
70 }
71
72 };
73 }
74
75});
76
77exports.default = _default;
Note: See TracBrowser for help on using the repository browser.