From 5f8b22478ae5e6f3d0beffab1b4f484530603894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 10 Apr 2024 12:44:17 +0200 Subject: [PATCH] refactor(core): Lint for cyclomatic complexity in BE packages (no-changelog) --- packages/cli/.eslintrc.js | 1 + packages/cli/src/CurlConverterHelper.ts | 1 + packages/cli/src/InternalHooks.ts | 1 + .../PublicApi/v1/handlers/credentials/credentials.service.ts | 1 + packages/cli/src/WebhookHelpers.ts | 2 ++ packages/cli/src/commands/executeBatch.ts | 1 + packages/cli/src/commands/export/credentials.ts | 1 + packages/cli/src/commands/export/workflow.ts | 1 + packages/cli/src/databases/dsl/Column.ts | 1 + packages/cli/src/eventbus/MessageEventBus/MessageEventBus.ts | 1 + .../MessageEventBusDestinationWebhook.ee.ts | 1 + packages/cli/src/eventbus/executionDataRecovery.service.ts | 1 + packages/cli/src/services/credentials-tester.service.ts | 1 + .../services/orchestration/main/handleCommandMessageMain.ts | 1 + .../orchestration/worker/handleCommandMessageWorker.ts | 1 + packages/cli/src/workflows/workflow.service.ts | 1 + packages/cli/test/integration/shared/utils/testServer.ts | 1 + packages/core/.eslintrc.js | 2 ++ packages/core/src/NodeExecuteFunctions.ts | 4 ++++ packages/core/src/WorkflowExecute.ts | 4 +++- packages/workflow/.eslintrc.js | 2 ++ packages/workflow/src/Expression.ts | 1 + packages/workflow/src/Extensions/ExpressionExtension.ts | 1 + packages/workflow/src/NodeHelpers.ts | 2 ++ packages/workflow/src/NodeParameters/FilterParameter.ts | 1 + packages/workflow/src/RoutingNode.ts | 1 + packages/workflow/src/TelemetryHelpers.ts | 1 + packages/workflow/src/TypeValidation.ts | 1 + packages/workflow/src/Workflow.ts | 1 + packages/workflow/src/WorkflowDataProxy.ts | 1 + packages/workflow/src/errors/node-api.error.ts | 1 + 31 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/cli/.eslintrc.js b/packages/cli/.eslintrc.js index 1840061479716..736003d7b842e 100644 --- a/packages/cli/.eslintrc.js +++ b/packages/cli/.eslintrc.js @@ -20,6 +20,7 @@ module.exports = { rules: { 'n8n-local-rules/no-dynamic-import-template': 'error', + complexity: 'error', // TODO: Remove this 'import/no-cycle': 'warn', diff --git a/packages/cli/src/CurlConverterHelper.ts b/packages/cli/src/CurlConverterHelper.ts index 3f6be3ba98e4f..d89c9ef3f9904 100644 --- a/packages/cli/src/CurlConverterHelper.ts +++ b/packages/cli/src/CurlConverterHelper.ts @@ -262,6 +262,7 @@ const mapCookies = (cookies: CurlJson['cookies']): { cookie: string } | {} => { }; }; +// eslint-disable-next-line complexity export const toHttpNodeParameters = (curlCommand: string): HttpNodeParameters => { const curlJson = curlToJson(curlCommand); diff --git a/packages/cli/src/InternalHooks.ts b/packages/cli/src/InternalHooks.ts index 6d01bd65d4a97..70b3030f23c10 100644 --- a/packages/cli/src/InternalHooks.ts +++ b/packages/cli/src/InternalHooks.ts @@ -339,6 +339,7 @@ export class InternalHooks { ]); } + // eslint-disable-next-line complexity async onWorkflowPostExecute( executionId: string, workflow: IWorkflowBase, diff --git a/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.service.ts b/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.service.ts index 38a2413716e57..935956df2ecdb 100644 --- a/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.service.ts +++ b/packages/cli/src/PublicApi/v1/handlers/credentials/credentials.service.ts @@ -158,6 +158,7 @@ export function toJsonSchema(properties: INodeProperties[]): IDataObject { // object in the JSON Schema definition. This allows us // to later validate that only this properties are set in // the credentials sent in the API call. + // eslint-disable-next-line complexity properties.forEach((property) => { if (property.required) { requiredFields.push(property.name); diff --git a/packages/cli/src/WebhookHelpers.ts b/packages/cli/src/WebhookHelpers.ts index 0452da8be2372..8d8d75a7c6c5f 100644 --- a/packages/cli/src/WebhookHelpers.ts +++ b/packages/cli/src/WebhookHelpers.ts @@ -217,6 +217,7 @@ const normalizeFormData = (values: Record) => { /** * Executes a webhook */ +// eslint-disable-next-line complexity export async function executeWebhook( workflow: Workflow, webhookData: IWebhookData, @@ -625,6 +626,7 @@ export async function executeWebhook( executionId, ) as Promise; executePromise + // eslint-disable-next-line complexity .then(async (data) => { if (data === undefined) { if (!didSendResponse) { diff --git a/packages/cli/src/commands/executeBatch.ts b/packages/cli/src/commands/executeBatch.ts index 9d29ee4adc1ec..affec09e52fc3 100644 --- a/packages/cli/src/commands/executeBatch.ts +++ b/packages/cli/src/commands/executeBatch.ts @@ -166,6 +166,7 @@ export class ExecuteBatch extends BaseCommand { await this.initExternalHooks(); } + // eslint-disable-next-line complexity async run() { const { flags } = await this.parse(ExecuteBatch); ExecuteBatch.debug = flags.debug; diff --git a/packages/cli/src/commands/export/credentials.ts b/packages/cli/src/commands/export/credentials.ts index e02c5e3a44d99..5fb10dcb2caa0 100644 --- a/packages/cli/src/commands/export/credentials.ts +++ b/packages/cli/src/commands/export/credentials.ts @@ -48,6 +48,7 @@ export class ExportCredentialsCommand extends BaseCommand { }), }; + // eslint-disable-next-line complexity async run() { const { flags } = await this.parse(ExportCredentialsCommand); diff --git a/packages/cli/src/commands/export/workflow.ts b/packages/cli/src/commands/export/workflow.ts index c747608b1d509..19aa2b9e0876b 100644 --- a/packages/cli/src/commands/export/workflow.ts +++ b/packages/cli/src/commands/export/workflow.ts @@ -41,6 +41,7 @@ export class ExportWorkflowsCommand extends BaseCommand { }), }; + // eslint-disable-next-line complexity async run() { const { flags } = await this.parse(ExportWorkflowsCommand); diff --git a/packages/cli/src/databases/dsl/Column.ts b/packages/cli/src/databases/dsl/Column.ts index aa5ff04e0d839..359ffd65af0d7 100644 --- a/packages/cli/src/databases/dsl/Column.ts +++ b/packages/cli/src/databases/dsl/Column.ts @@ -72,6 +72,7 @@ export class Column { return this; } + // eslint-disable-next-line complexity toOptions(driver: Driver): TableColumnOptions { const { name, type, isNullable, isPrimary, isGenerated, length } = this; const isMysql = 'mysql' in driver; diff --git a/packages/cli/src/eventbus/MessageEventBus/MessageEventBus.ts b/packages/cli/src/eventbus/MessageEventBus/MessageEventBus.ts index 1b2fe14026e1e..2f8626f6e6cec 100644 --- a/packages/cli/src/eventbus/MessageEventBus/MessageEventBus.ts +++ b/packages/cli/src/eventbus/MessageEventBus/MessageEventBus.ts @@ -85,6 +85,7 @@ export class MessageEventBus extends EventEmitter { * * Sets `isInitialized` to `true` once finished. */ + // eslint-disable-next-line complexity async initialize(options?: MessageEventBusInitializeOptions): Promise { if (this.isInitialized) { return; diff --git a/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts b/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts index 3fba5e7e3cc5c..59070a023b5b5 100644 --- a/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts +++ b/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts @@ -250,6 +250,7 @@ export class MessageEventBusDestinationWebhook return null; } + // eslint-disable-next-line complexity async receiveFromEventBus(emitterPayload: MessageWithCallback): Promise { const { msg, confirmCallback } = emitterPayload; let sendResult = false; diff --git a/packages/cli/src/eventbus/executionDataRecovery.service.ts b/packages/cli/src/eventbus/executionDataRecovery.service.ts index 8ebacd7885ae3..3ddee5edc71e4 100644 --- a/packages/cli/src/eventbus/executionDataRecovery.service.ts +++ b/packages/cli/src/eventbus/executionDataRecovery.service.ts @@ -16,6 +16,7 @@ export class ExecutionDataRecoveryService { private readonly executionRepository: ExecutionRepository, ) {} + // eslint-disable-next-line complexity async recoverExecutionData( executionId: string, messages: EventMessageTypes[], diff --git a/packages/cli/src/services/credentials-tester.service.ts b/packages/cli/src/services/credentials-tester.service.ts index 2ecdfe3f44768..a144c607e535c 100644 --- a/packages/cli/src/services/credentials-tester.service.ts +++ b/packages/cli/src/services/credentials-tester.service.ts @@ -166,6 +166,7 @@ export class CredentialsTester { return undefined; } + // eslint-disable-next-line complexity async testCredentials( user: User, credentialType: string, diff --git a/packages/cli/src/services/orchestration/main/handleCommandMessageMain.ts b/packages/cli/src/services/orchestration/main/handleCommandMessageMain.ts index 4becc95240793..2878c067ea050 100644 --- a/packages/cli/src/services/orchestration/main/handleCommandMessageMain.ts +++ b/packages/cli/src/services/orchestration/main/handleCommandMessageMain.ts @@ -11,6 +11,7 @@ import { TestWebhooks } from '@/TestWebhooks'; import { OrchestrationService } from '@/services/orchestration.service'; import { WorkflowRepository } from '@/databases/repositories/workflow.repository'; +// eslint-disable-next-line complexity export async function handleCommandMessageMain(messageString: string) { const queueModeId = config.getEnv('redis.queueModeId'); const isMainInstance = config.getEnv('generic.instanceType') === 'main'; diff --git a/packages/cli/src/services/orchestration/worker/handleCommandMessageWorker.ts b/packages/cli/src/services/orchestration/worker/handleCommandMessageWorker.ts index 8930189daae6e..d825428f9e02c 100644 --- a/packages/cli/src/services/orchestration/worker/handleCommandMessageWorker.ts +++ b/packages/cli/src/services/orchestration/worker/handleCommandMessageWorker.ts @@ -12,6 +12,7 @@ import { Logger } from '@/Logger'; import { N8N_VERSION } from '@/constants'; export function getWorkerCommandReceivedHandler(options: WorkerCommandReceivedHandlerOptions) { + // eslint-disable-next-line complexity return async (channel: string, messageString: string) => { if (channel === COMMAND_REDIS_CHANNEL) { if (!messageString) return; diff --git a/packages/cli/src/workflows/workflow.service.ts b/packages/cli/src/workflows/workflow.service.ts index 1bea71481ffd6..afb6e6f2434f6 100644 --- a/packages/cli/src/workflows/workflow.service.ts +++ b/packages/cli/src/workflows/workflow.service.ts @@ -55,6 +55,7 @@ export class WorkflowService { : { workflows, count }; } + // eslint-disable-next-line complexity async update( user: User, workflow: WorkflowEntity, diff --git a/packages/cli/test/integration/shared/utils/testServer.ts b/packages/cli/test/integration/shared/utils/testServer.ts index 4d94c56595cce..d6b9aa40efd04 100644 --- a/packages/cli/test/integration/shared/utils/testServer.ts +++ b/packages/cli/test/integration/shared/utils/testServer.ts @@ -95,6 +95,7 @@ export const setupTestServer = ({ license: new LicenseMocker(), }; + // eslint-disable-next-line complexity beforeAll(async () => { await testDb.init(); diff --git a/packages/core/.eslintrc.js b/packages/core/.eslintrc.js index 479dcfe8725e4..cd962bad5cb33 100644 --- a/packages/core/.eslintrc.js +++ b/packages/core/.eslintrc.js @@ -15,6 +15,8 @@ module.exports = { ignorePatterns: ['bin/*.js'], rules: { + complexity: 'error', + // TODO: Remove this 'import/order': 'off', '@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }], diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 23b54432c84c1..0367d292566db 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -274,6 +274,7 @@ const getBeforeRedirectFn = } }; +// eslint-disable-next-line complexity export async function parseRequestObject(requestObject: IRequestOptions) { // This function is a temporary implementation // That translates all http requests done via @@ -866,6 +867,7 @@ export async function proxyRequestToAxios( } } +// eslint-disable-next-line complexity function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequestConfig { // Destructure properties with the same name first. const { headers, method, timeout, auth, proxy, url } = n8nRequest; @@ -1175,6 +1177,7 @@ export async function copyBinaryFile( * Takes a buffer and converts it into the format n8n uses. It encodes the binary data as * base64 and adds metadata. */ +// eslint-disable-next-line complexity async function prepareBinaryData( binaryData: Buffer | Readable, executionId: string, @@ -2894,6 +2897,7 @@ const getRequestHelperFunctions = ( return { httpRequest, + // eslint-disable-next-line complexity async requestWithAuthenticationPaginated( this: IExecuteFunctions, requestOptions: IRequestOptions, diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 8df1f480e473d..f11ab58cdf529 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -154,7 +154,7 @@ export class WorkflowExecute { // IMPORTANT: Do not add "async" to this function, it will then convert the // PCancelable to a regular Promise and does so not allow canceling // active executions anymore - // eslint-disable-next-line @typescript-eslint/promise-function-async + // eslint-disable-next-line @typescript-eslint/promise-function-async, complexity runPartialWorkflow( workflow: Workflow, runData: IRunData, @@ -371,6 +371,7 @@ export class WorkflowExecute { } } + // eslint-disable-next-line complexity addNodeToBeExecuted( workflow: Workflow, connectionData: IConnection, @@ -836,6 +837,7 @@ export class WorkflowExecute { setTimeout(() => resolve(fullRunData), 10); }); + // eslint-disable-next-line complexity const returnPromise = (async () => { try { if (!this.additionalData.restartExecutionId) { diff --git a/packages/workflow/.eslintrc.js b/packages/workflow/.eslintrc.js index f7f7251b35b3f..32422b284657d 100644 --- a/packages/workflow/.eslintrc.js +++ b/packages/workflow/.eslintrc.js @@ -9,6 +9,8 @@ module.exports = { ...sharedOptions(__dirname), rules: { + complexity: 'error', + // TODO: remove these 'import/order': 'off', '@typescript-eslint/no-base-to-string': 'warn', diff --git a/packages/workflow/src/Expression.ts b/packages/workflow/src/Expression.ts index 598781fbb9ab7..35f0ddca6c165 100644 --- a/packages/workflow/src/Expression.ts +++ b/packages/workflow/src/Expression.ts @@ -104,6 +104,7 @@ export class Expression { * @param {boolean} [returnObjectAsString=false] */ // TODO: Clean that up at some point and move all the options into an options object + // eslint-disable-next-line complexity resolveSimpleParameterValue( parameterValue: NodeParameterValue, siblingParameters: INodeParameters, diff --git a/packages/workflow/src/Extensions/ExpressionExtension.ts b/packages/workflow/src/Extensions/ExpressionExtension.ts index 097156b171308..3231abfaf0843 100644 --- a/packages/workflow/src/Extensions/ExpressionExtension.ts +++ b/packages/workflow/src/Extensions/ExpressionExtension.ts @@ -127,6 +127,7 @@ export const extendTransform = (expression: string): { code: string } | undefine // Polyfill optional chaining visit(ast, { + // eslint-disable-next-line complexity visitChainExpression(path) { this.traverse(path); const chainNumber = currentChain; diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 101dd20e1b580..8a097c2a9122b 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -607,6 +607,7 @@ export function getParameterResolveOrder( * @param {boolean} [dataIsResolved=false] If nodeValues are already fully resolved (so that all default values got added already) * @param {INodeParameters} [nodeValuesRoot] The root node-parameter-data */ +// eslint-disable-next-line complexity export function getNodeParameters( nodePropertiesArray: INodeProperties[], nodeValues: INodeParameters | null, @@ -1388,6 +1389,7 @@ function isINodeParameterResourceLocator(value: unknown): value is INodeParamete * @param {INodeParameters} nodeValues The values of the node * @param {string} path The path to the properties */ +// eslint-disable-next-line complexity export function getParameterIssues( nodeProperties: INodeProperties, nodeValues: INodeParameters, diff --git a/packages/workflow/src/NodeParameters/FilterParameter.ts b/packages/workflow/src/NodeParameters/FilterParameter.ts index 5bbeaea569d63..fdaee8e71daa4 100644 --- a/packages/workflow/src/NodeParameters/FilterParameter.ts +++ b/packages/workflow/src/NodeParameters/FilterParameter.ts @@ -121,6 +121,7 @@ function parseRegexPattern(pattern: string): RegExp { return regex; } +// eslint-disable-next-line complexity export function executeFilterCondition( condition: FilterConditionValue, filterOptions: FilterOptionsValue, diff --git a/packages/workflow/src/RoutingNode.ts b/packages/workflow/src/RoutingNode.ts index c53b0beef7218..99935ede325b0 100644 --- a/packages/workflow/src/RoutingNode.ts +++ b/packages/workflow/src/RoutingNode.ts @@ -743,6 +743,7 @@ export class RoutingNode { return parameterValue; } + // eslint-disable-next-line complexity getRequestOptionsFromParameters( executeSingleFunctions: IExecuteSingleFunctions, nodeProperties: INodeProperties | INodePropertyOptions, diff --git a/packages/workflow/src/TelemetryHelpers.ts b/packages/workflow/src/TelemetryHelpers.ts index dc2a6c58470da..f93b7337d4d2e 100644 --- a/packages/workflow/src/TelemetryHelpers.ts +++ b/packages/workflow/src/TelemetryHelpers.ts @@ -151,6 +151,7 @@ export function generateNodesGraph( }; }); + // eslint-disable-next-line complexity otherNodes.forEach((node: INode, index: number) => { nodeGraph.node_types.push(node.type); const nodeItem: INodeGraphItem = { diff --git a/packages/workflow/src/TypeValidation.ts b/packages/workflow/src/TypeValidation.ts index 01a2fdb35e3d4..ea19af07c6786 100644 --- a/packages/workflow/src/TypeValidation.ts +++ b/packages/workflow/src/TypeValidation.ts @@ -178,6 +178,7 @@ type ValidateFieldTypeOptions = Partial<{ parseStrings: boolean; }>; // Validates field against the schema and tries to parse it to the correct type +// eslint-disable-next-line complexity export const validateFieldType = ( fieldName: string, value: unknown, diff --git a/packages/workflow/src/Workflow.ts b/packages/workflow/src/Workflow.ts index 33d6ac78f362b..1b18936e3d4a4 100644 --- a/packages/workflow/src/Workflow.ts +++ b/packages/workflow/src/Workflow.ts @@ -1264,6 +1264,7 @@ export class Workflow { * Executes the given node. * */ + // eslint-disable-next-line complexity async runNode( executionData: IExecuteData, runExecutionData: IRunExecutionData, diff --git a/packages/workflow/src/WorkflowDataProxy.ts b/packages/workflow/src/WorkflowDataProxy.ts index f2942bea01a20..5cc245f330114 100644 --- a/packages/workflow/src/WorkflowDataProxy.ts +++ b/packages/workflow/src/WorkflowDataProxy.ts @@ -738,6 +738,7 @@ export class WorkflowDataProxy { }); }; + // eslint-disable-next-line complexity const getPairedItem = ( destinationNodeName: string, incomingSourceData: ISourceData | null, diff --git a/packages/workflow/src/errors/node-api.error.ts b/packages/workflow/src/errors/node-api.error.ts index 17fd3871e5d16..f1f6c8175a5d0 100644 --- a/packages/workflow/src/errors/node-api.error.ts +++ b/packages/workflow/src/errors/node-api.error.ts @@ -115,6 +115,7 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = { export class NodeApiError extends NodeError { httpCode: string | null; + // eslint-disable-next-line complexity constructor( node: INode, errorResponse: JsonObject,