UNPKG

2.76 kBJavaScriptView Raw
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5}) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
7 o[k2] = m[k];
8}));
9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
11}) : function(o, v) {
12 o["default"] = v;
13});
14var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
16 var result = {};
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
19 return result;
20};
21Object.defineProperty(exports, "__esModule", { value: true });
22const utils_1 = require("@typescript-eslint/utils");
23const util = __importStar(require("../util"));
24exports.default = util.createRule({
25 name: 'no-var-requires',
26 meta: {
27 type: 'problem',
28 docs: {
29 description: 'Disallows the use of require statements except in import statements',
30 recommended: 'error',
31 },
32 messages: {
33 noVarReqs: 'Require statement not part of import statement.',
34 },
35 schema: [],
36 },
37 defaultOptions: [],
38 create(context) {
39 return {
40 'CallExpression[callee.name="require"]'(node) {
41 var _a;
42 const parent = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ChainExpression
43 ? node.parent.parent
44 : node.parent;
45 if (parent &&
46 [
47 utils_1.AST_NODE_TYPES.CallExpression,
48 utils_1.AST_NODE_TYPES.MemberExpression,
49 utils_1.AST_NODE_TYPES.NewExpression,
50 utils_1.AST_NODE_TYPES.TSAsExpression,
51 utils_1.AST_NODE_TYPES.TSTypeAssertion,
52 utils_1.AST_NODE_TYPES.VariableDeclarator,
53 ].includes(parent.type)) {
54 const variable = utils_1.ASTUtils.findVariable(context.getScope(), 'require');
55 if (!(variable === null || variable === void 0 ? void 0 : variable.identifiers.length)) {
56 context.report({
57 node,
58 messageId: 'noVarReqs',
59 });
60 }
61 }
62 },
63 };
64 },
65});
66//# sourceMappingURL=no-var-requires.js.map
\No newline at end of file