@forge/lint
5.14.1-next.75.15.0-next.8
out/lint/linters/endpoint-linter/visitors/invoke-endpoint-call-visitor.jsout/lint/linters/endpoint-linter/visitors/invoke-endpoint-call-visitor.js+72
Index: package/out/lint/linters/endpoint-linter/visitors/invoke-endpoint-call-visitor.js
===================================================================
--- package/out/lint/linters/endpoint-linter/visitors/invoke-endpoint-call-visitor.js
+++ package/out/lint/linters/endpoint-linter/visitors/invoke-endpoint-call-visitor.js
@@ -0,0 +1,72 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.InvokeEndpointCallVisitor = void 0;
+const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
+const invoke_endpoint_interface_1 = require("../invoke-endpoint-interface");
+class InvokeEndpointCallVisitor {
+ visit(node, parent, callback) {
+ switch (node.type) {
+ case typescript_estree_1.AST_NODE_TYPES.ImportDeclaration:
+ if (node.source.value === invoke_endpoint_interface_1.INVOKE_ENDPOINT_PACKAGE_NAME) {
+ const imports = node.specifiers
+ .filter((spec) => spec.type === typescript_estree_1.AST_NODE_TYPES.ImportDefaultSpecifier ||
+ spec.type === typescript_estree_1.AST_NODE_TYPES.ImportNamespaceSpecifier ||
+ (spec.type === typescript_estree_1.AST_NODE_TYPES.ImportSpecifier &&
+ spec.imported.name === invoke_endpoint_interface_1.INVOKE_ENDPOINT_FUNCTION_NAME))
+ .map((spec) => ({
+ type: spec.type,
+ alias: spec.local.name,
+ column: spec.local.loc.start.column,
+ line: spec.local.loc.start.line
+ }));
+ callback({
+ type: invoke_endpoint_interface_1.InvokeEndpointTypes.IMPORT_LIST,
+ imports,
+ line: 0,
+ column: 0
+ });
+ }
+ break;
+ case typescript_estree_1.AST_NODE_TYPES.CallExpression:
+ if (node.callee.type === typescript_estree_1.AST_NODE_TYPES.Identifier) {
+ const [endpointKeyNode] = node.arguments;
+ if (this.endpointKeyCanBeChecked(endpointKeyNode)) {
+ const invokeEndpointCall = {
+ ...this.transformArgsToInvokeEndpointCall(endpointKeyNode),
+ type: invoke_endpoint_interface_1.InvokeEndpointTypes.DIRECT_CALL,
+ calleeName: node.callee.name
+ };
+ callback(invokeEndpointCall);
+ }
+ }
+ break;
+ case typescript_estree_1.AST_NODE_TYPES.MemberExpression:
+ if (node.property.type === typescript_estree_1.AST_NODE_TYPES.Identifier &&
+ node.object.type === typescript_estree_1.AST_NODE_TYPES.Identifier &&
+ node.property.name === invoke_endpoint_interface_1.INVOKE_ENDPOINT_FUNCTION_NAME &&
+ parent?.type === typescript_estree_1.AST_NODE_TYPES.CallExpression) {
+ const [endpointKeyNode] = parent.arguments;
+ if (this.endpointKeyCanBeChecked(endpointKeyNode)) {
+ const invokeEndpointMemberCall = {
+ ...this.transformArgsToInvokeEndpointCall(endpointKeyNode),
+ type: invoke_endpoint_interface_1.InvokeEndpointTypes.MEMBER_CALL,
+ objectName: node.object.name
+ };
+ callback(invokeEndpointMemberCall);
+ }
+ }
+ break;
+ }
+ }
+ endpointKeyCanBeChecked(endpointKeyNode) {
+ return (endpointKeyNode?.type === typescript_estree_1.AST_NODE_TYPES.Literal &&
+ typeof endpointKeyNode?.value === 'string' &&
+ endpointKeyNode.value.trim() !== '');
+ }
+ transformArgsToInvokeEndpointCall = (endpointKeyNode) => ({
+ endpointKey: endpointKeyNode.value,
+ line: endpointKeyNode.loc.start.line,
+ column: endpointKeyNode.loc.start.column
+ });
+}
+exports.InvokeEndpointCallVisitor = InvokeEndpointCallVisitor;