source: frontend/node_modules/eslint-plugin-testing-library/rules/no-node-access.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.2 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RULE_NAME = void 0;
4const utils_1 = require("@typescript-eslint/utils");
5const create_testing_library_rule_1 = require("../create-testing-library-rule");
6const utils_2 = require("../utils");
7exports.RULE_NAME = 'no-node-access';
8exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
9 name: exports.RULE_NAME,
10 meta: {
11 type: 'problem',
12 docs: {
13 description: 'Disallow direct Node access',
14 recommendedConfig: {
15 dom: false,
16 angular: 'error',
17 react: 'error',
18 vue: 'error',
19 marko: 'error',
20 },
21 },
22 messages: {
23 noNodeAccess: 'Avoid direct Node access. Prefer using the methods from Testing Library.',
24 },
25 schema: [
26 {
27 type: 'object',
28 properties: {
29 allowContainerFirstChild: {
30 type: 'boolean',
31 },
32 },
33 },
34 ],
35 },
36 defaultOptions: [
37 {
38 allowContainerFirstChild: false,
39 },
40 ],
41 create(context, [{ allowContainerFirstChild = false }], helpers) {
42 function showErrorForNodeAccess(node) {
43 if (!helpers.isTestingLibraryImported(true)) {
44 return;
45 }
46 if (utils_1.ASTUtils.isIdentifier(node.property) &&
47 utils_2.ALL_RETURNING_NODES.includes(node.property.name)) {
48 if (allowContainerFirstChild && node.property.name === 'firstChild') {
49 return;
50 }
51 if (utils_1.ASTUtils.isIdentifier(node.object) &&
52 node.object.name === 'props') {
53 return;
54 }
55 context.report({
56 node,
57 loc: node.property.loc.start,
58 messageId: 'noNodeAccess',
59 });
60 }
61 }
62 return {
63 'ExpressionStatement MemberExpression': showErrorForNodeAccess,
64 'VariableDeclarator MemberExpression': showErrorForNodeAccess,
65 };
66 },
67});
Note: See TracBrowser for help on using the repository browser.