source: frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-have-length.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 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 _utils = require("./utils");
11
12var _default = (0, _utils.createRule)({
13 name: __filename,
14 meta: {
15 docs: {
16 category: 'Best Practices',
17 description: 'Suggest using `toHaveLength()`',
18 recommended: false
19 },
20 messages: {
21 useToHaveLength: 'Use toHaveLength() instead'
22 },
23 fixable: 'code',
24 type: 'suggestion',
25 schema: []
26 },
27 defaultOptions: [],
28
29 create(context) {
30 return {
31 CallExpression(node) {
32 if (!(0, _utils.isExpectCall)(node)) {
33 return;
34 }
35
36 const {
37 expect: {
38 arguments: [argument]
39 },
40 matcher
41 } = (0, _utils.parseExpectCall)(node);
42
43 if (!matcher || !(0, _utils.isParsedEqualityMatcherCall)(matcher) || (argument === null || argument === void 0 ? void 0 : argument.type) !== _experimentalUtils.AST_NODE_TYPES.MemberExpression || !(0, _utils.isSupportedAccessor)(argument.property, 'length')) {
44 return;
45 }
46
47 context.report({
48 fix(fixer) {
49 return [// remove the "length" property accessor
50 fixer.removeRange([argument.property.range[0] - 1, argument.range[1]]), // replace the current matcher with "toHaveLength"
51 fixer.replaceTextRange([matcher.node.object.range[1], matcher.node.range[1]], '.toHaveLength')];
52 },
53
54 messageId: 'useToHaveLength',
55 node: matcher.node.property
56 });
57 }
58
59 };
60 }
61
62});
63
64exports.default = _default;
Note: See TracBrowser for help on using the repository browser.