source: frontend/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
10var _detectJestVersion = require("./detectJestVersion");
11
12var _utils = require("./utils");
13
14const parseJestVersion = rawVersion => {
15 if (typeof rawVersion === 'number') {
16 return rawVersion;
17 }
18
19 const [majorVersion] = rawVersion.split('.');
20 return parseInt(majorVersion, 10);
21};
22
23var _default = (0, _utils.createRule)({
24 name: __filename,
25 meta: {
26 docs: {
27 category: 'Best Practices',
28 description: 'Disallow use of deprecated functions',
29 recommended: 'error'
30 },
31 messages: {
32 deprecatedFunction: '`{{ deprecation }}` has been deprecated in favor of `{{ replacement }}`'
33 },
34 type: 'suggestion',
35 schema: [],
36 fixable: 'code'
37 },
38 defaultOptions: [],
39
40 create(context) {
41 var _context$settings, _context$settings$jes;
42
43 const jestVersion = parseJestVersion(((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || (0, _detectJestVersion.detectJestVersion)());
44 const deprecations = { ...(jestVersion >= 15 && {
45 'jest.resetModuleRegistry': 'jest.resetModules'
46 }),
47 ...(jestVersion >= 17 && {
48 'jest.addMatchers': 'expect.extend'
49 }),
50 ...(jestVersion >= 21 && {
51 'require.requireMock': 'jest.requireMock',
52 'require.requireActual': 'jest.requireActual'
53 }),
54 ...(jestVersion >= 22 && {
55 'jest.runTimersToTime': 'jest.advanceTimersByTime'
56 }),
57 ...(jestVersion >= 26 && {
58 'jest.genMockFromModule': 'jest.createMockFromModule'
59 })
60 };
61 return {
62 CallExpression(node) {
63 if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
64 return;
65 }
66
67 const deprecation = (0, _utils.getNodeName)(node);
68
69 if (!deprecation || !(deprecation in deprecations)) {
70 return;
71 }
72
73 const replacement = deprecations[deprecation];
74 const {
75 callee
76 } = node;
77 context.report({
78 messageId: 'deprecatedFunction',
79 data: {
80 deprecation,
81 replacement
82 },
83 node,
84
85 fix(fixer) {
86 let [name, func] = replacement.split('.');
87
88 if (callee.property.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
89 func = `'${func}'`;
90 }
91
92 return [fixer.replaceText(callee.object, name), fixer.replaceText(callee.property, func)];
93 }
94
95 });
96 }
97
98 };
99 }
100
101});
102
103exports.default = _default;
Note: See TracBrowser for help on using the repository browser.