mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
refactor(core): Lint for cyclomatic complexity in BE packages (no-changelog) (#9111)
This commit is contained in:
parent
9eab357b75
commit
a3b59843d5
|
@ -20,6 +20,7 @@ module.exports = {
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
'n8n-local-rules/no-dynamic-import-template': 'error',
|
'n8n-local-rules/no-dynamic-import-template': 'error',
|
||||||
|
complexity: 'error',
|
||||||
|
|
||||||
// TODO: Remove this
|
// TODO: Remove this
|
||||||
'import/no-cycle': 'warn',
|
'import/no-cycle': 'warn',
|
||||||
|
|
|
@ -262,6 +262,7 @@ const mapCookies = (cookies: CurlJson['cookies']): { cookie: string } | {} => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export const toHttpNodeParameters = (curlCommand: string): HttpNodeParameters => {
|
export const toHttpNodeParameters = (curlCommand: string): HttpNodeParameters => {
|
||||||
const curlJson = curlToJson(curlCommand);
|
const curlJson = curlToJson(curlCommand);
|
||||||
|
|
||||||
|
|
|
@ -339,6 +339,7 @@ export class InternalHooks {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async onWorkflowPostExecute(
|
async onWorkflowPostExecute(
|
||||||
executionId: string,
|
executionId: string,
|
||||||
workflow: IWorkflowBase,
|
workflow: IWorkflowBase,
|
||||||
|
|
|
@ -158,6 +158,7 @@ export function toJsonSchema(properties: INodeProperties[]): IDataObject {
|
||||||
// object in the JSON Schema definition. This allows us
|
// object in the JSON Schema definition. This allows us
|
||||||
// to later validate that only this properties are set in
|
// to later validate that only this properties are set in
|
||||||
// the credentials sent in the API call.
|
// the credentials sent in the API call.
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
properties.forEach((property) => {
|
properties.forEach((property) => {
|
||||||
if (property.required) {
|
if (property.required) {
|
||||||
requiredFields.push(property.name);
|
requiredFields.push(property.name);
|
||||||
|
|
|
@ -217,6 +217,7 @@ const normalizeFormData = <T>(values: Record<string, T | T[]>) => {
|
||||||
/**
|
/**
|
||||||
* Executes a webhook
|
* Executes a webhook
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export async function executeWebhook(
|
export async function executeWebhook(
|
||||||
workflow: Workflow,
|
workflow: Workflow,
|
||||||
webhookData: IWebhookData,
|
webhookData: IWebhookData,
|
||||||
|
@ -625,6 +626,7 @@ export async function executeWebhook(
|
||||||
executionId,
|
executionId,
|
||||||
) as Promise<IExecutionDb | undefined>;
|
) as Promise<IExecutionDb | undefined>;
|
||||||
executePromise
|
executePromise
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
.then(async (data) => {
|
.then(async (data) => {
|
||||||
if (data === undefined) {
|
if (data === undefined) {
|
||||||
if (!didSendResponse) {
|
if (!didSendResponse) {
|
||||||
|
|
|
@ -166,6 +166,7 @@ export class ExecuteBatch extends BaseCommand {
|
||||||
await this.initExternalHooks();
|
await this.initExternalHooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async run() {
|
async run() {
|
||||||
const { flags } = await this.parse(ExecuteBatch);
|
const { flags } = await this.parse(ExecuteBatch);
|
||||||
ExecuteBatch.debug = flags.debug;
|
ExecuteBatch.debug = flags.debug;
|
||||||
|
|
|
@ -48,6 +48,7 @@ export class ExportCredentialsCommand extends BaseCommand {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async run() {
|
async run() {
|
||||||
const { flags } = await this.parse(ExportCredentialsCommand);
|
const { flags } = await this.parse(ExportCredentialsCommand);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ export class ExportWorkflowsCommand extends BaseCommand {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async run() {
|
async run() {
|
||||||
const { flags } = await this.parse(ExportWorkflowsCommand);
|
const { flags } = await this.parse(ExportWorkflowsCommand);
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ export class Column {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
toOptions(driver: Driver): TableColumnOptions {
|
toOptions(driver: Driver): TableColumnOptions {
|
||||||
const { name, type, isNullable, isPrimary, isGenerated, length } = this;
|
const { name, type, isNullable, isPrimary, isGenerated, length } = this;
|
||||||
const isMysql = 'mysql' in driver;
|
const isMysql = 'mysql' in driver;
|
||||||
|
|
|
@ -85,6 +85,7 @@ export class MessageEventBus extends EventEmitter {
|
||||||
*
|
*
|
||||||
* Sets `isInitialized` to `true` once finished.
|
* Sets `isInitialized` to `true` once finished.
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async initialize(options?: MessageEventBusInitializeOptions): Promise<void> {
|
async initialize(options?: MessageEventBusInitializeOptions): Promise<void> {
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -250,6 +250,7 @@ export class MessageEventBusDestinationWebhook
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async receiveFromEventBus(emitterPayload: MessageWithCallback): Promise<boolean> {
|
async receiveFromEventBus(emitterPayload: MessageWithCallback): Promise<boolean> {
|
||||||
const { msg, confirmCallback } = emitterPayload;
|
const { msg, confirmCallback } = emitterPayload;
|
||||||
let sendResult = false;
|
let sendResult = false;
|
||||||
|
|
|
@ -16,6 +16,7 @@ export class ExecutionDataRecoveryService {
|
||||||
private readonly executionRepository: ExecutionRepository,
|
private readonly executionRepository: ExecutionRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async recoverExecutionData(
|
async recoverExecutionData(
|
||||||
executionId: string,
|
executionId: string,
|
||||||
messages: EventMessageTypes[],
|
messages: EventMessageTypes[],
|
||||||
|
|
|
@ -166,6 +166,7 @@ export class CredentialsTester {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async testCredentials(
|
async testCredentials(
|
||||||
user: User,
|
user: User,
|
||||||
credentialType: string,
|
credentialType: string,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { TestWebhooks } from '@/TestWebhooks';
|
||||||
import { OrchestrationService } from '@/services/orchestration.service';
|
import { OrchestrationService } from '@/services/orchestration.service';
|
||||||
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export async function handleCommandMessageMain(messageString: string) {
|
export async function handleCommandMessageMain(messageString: string) {
|
||||||
const queueModeId = config.getEnv('redis.queueModeId');
|
const queueModeId = config.getEnv('redis.queueModeId');
|
||||||
const isMainInstance = config.getEnv('generic.instanceType') === 'main';
|
const isMainInstance = config.getEnv('generic.instanceType') === 'main';
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { Logger } from '@/Logger';
|
||||||
import { N8N_VERSION } from '@/constants';
|
import { N8N_VERSION } from '@/constants';
|
||||||
|
|
||||||
export function getWorkerCommandReceivedHandler(options: WorkerCommandReceivedHandlerOptions) {
|
export function getWorkerCommandReceivedHandler(options: WorkerCommandReceivedHandlerOptions) {
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
return async (channel: string, messageString: string) => {
|
return async (channel: string, messageString: string) => {
|
||||||
if (channel === COMMAND_REDIS_CHANNEL) {
|
if (channel === COMMAND_REDIS_CHANNEL) {
|
||||||
if (!messageString) return;
|
if (!messageString) return;
|
||||||
|
|
|
@ -55,6 +55,7 @@ export class WorkflowService {
|
||||||
: { workflows, count };
|
: { workflows, count };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async update(
|
async update(
|
||||||
user: User,
|
user: User,
|
||||||
workflow: WorkflowEntity,
|
workflow: WorkflowEntity,
|
||||||
|
|
|
@ -95,6 +95,7 @@ export const setupTestServer = ({
|
||||||
license: new LicenseMocker(),
|
license: new LicenseMocker(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await testDb.init();
|
await testDb.init();
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ module.exports = {
|
||||||
ignorePatterns: ['bin/*.js'],
|
ignorePatterns: ['bin/*.js'],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
complexity: 'error',
|
||||||
|
|
||||||
// TODO: Remove this
|
// TODO: Remove this
|
||||||
'import/order': 'off',
|
'import/order': 'off',
|
||||||
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }],
|
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }],
|
||||||
|
|
|
@ -274,6 +274,7 @@ const getBeforeRedirectFn =
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export async function parseRequestObject(requestObject: IRequestOptions) {
|
export async function parseRequestObject(requestObject: IRequestOptions) {
|
||||||
// This function is a temporary implementation
|
// This function is a temporary implementation
|
||||||
// That translates all http requests done via
|
// 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 {
|
function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequestConfig {
|
||||||
// Destructure properties with the same name first.
|
// Destructure properties with the same name first.
|
||||||
const { headers, method, timeout, auth, proxy, url } = n8nRequest;
|
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
|
* Takes a buffer and converts it into the format n8n uses. It encodes the binary data as
|
||||||
* base64 and adds metadata.
|
* base64 and adds metadata.
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async function prepareBinaryData(
|
async function prepareBinaryData(
|
||||||
binaryData: Buffer | Readable,
|
binaryData: Buffer | Readable,
|
||||||
executionId: string,
|
executionId: string,
|
||||||
|
@ -2894,6 +2897,7 @@ const getRequestHelperFunctions = (
|
||||||
|
|
||||||
return {
|
return {
|
||||||
httpRequest,
|
httpRequest,
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async requestWithAuthenticationPaginated(
|
async requestWithAuthenticationPaginated(
|
||||||
this: IExecuteFunctions,
|
this: IExecuteFunctions,
|
||||||
requestOptions: IRequestOptions,
|
requestOptions: IRequestOptions,
|
||||||
|
|
|
@ -154,7 +154,7 @@ export class WorkflowExecute {
|
||||||
// IMPORTANT: Do not add "async" to this function, it will then convert the
|
// IMPORTANT: Do not add "async" to this function, it will then convert the
|
||||||
// PCancelable to a regular Promise and does so not allow canceling
|
// PCancelable to a regular Promise and does so not allow canceling
|
||||||
// active executions anymore
|
// active executions anymore
|
||||||
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
// eslint-disable-next-line @typescript-eslint/promise-function-async, complexity
|
||||||
runPartialWorkflow(
|
runPartialWorkflow(
|
||||||
workflow: Workflow,
|
workflow: Workflow,
|
||||||
runData: IRunData,
|
runData: IRunData,
|
||||||
|
@ -371,6 +371,7 @@ export class WorkflowExecute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
addNodeToBeExecuted(
|
addNodeToBeExecuted(
|
||||||
workflow: Workflow,
|
workflow: Workflow,
|
||||||
connectionData: IConnection,
|
connectionData: IConnection,
|
||||||
|
@ -836,6 +837,7 @@ export class WorkflowExecute {
|
||||||
setTimeout(() => resolve(fullRunData), 10);
|
setTimeout(() => resolve(fullRunData), 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
const returnPromise = (async () => {
|
const returnPromise = (async () => {
|
||||||
try {
|
try {
|
||||||
if (!this.additionalData.restartExecutionId) {
|
if (!this.additionalData.restartExecutionId) {
|
||||||
|
|
|
@ -9,6 +9,8 @@ module.exports = {
|
||||||
...sharedOptions(__dirname),
|
...sharedOptions(__dirname),
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
complexity: 'error',
|
||||||
|
|
||||||
// TODO: remove these
|
// TODO: remove these
|
||||||
'import/order': 'off',
|
'import/order': 'off',
|
||||||
'@typescript-eslint/no-base-to-string': 'warn',
|
'@typescript-eslint/no-base-to-string': 'warn',
|
||||||
|
|
|
@ -104,6 +104,7 @@ export class Expression {
|
||||||
* @param {boolean} [returnObjectAsString=false]
|
* @param {boolean} [returnObjectAsString=false]
|
||||||
*/
|
*/
|
||||||
// TODO: Clean that up at some point and move all the options into an options object
|
// TODO: Clean that up at some point and move all the options into an options object
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
resolveSimpleParameterValue(
|
resolveSimpleParameterValue(
|
||||||
parameterValue: NodeParameterValue,
|
parameterValue: NodeParameterValue,
|
||||||
siblingParameters: INodeParameters,
|
siblingParameters: INodeParameters,
|
||||||
|
|
|
@ -127,6 +127,7 @@ export const extendTransform = (expression: string): { code: string } | undefine
|
||||||
|
|
||||||
// Polyfill optional chaining
|
// Polyfill optional chaining
|
||||||
visit(ast, {
|
visit(ast, {
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
visitChainExpression(path) {
|
visitChainExpression(path) {
|
||||||
this.traverse(path);
|
this.traverse(path);
|
||||||
const chainNumber = currentChain;
|
const chainNumber = currentChain;
|
||||||
|
|
|
@ -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 {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
|
* @param {INodeParameters} [nodeValuesRoot] The root node-parameter-data
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export function getNodeParameters(
|
export function getNodeParameters(
|
||||||
nodePropertiesArray: INodeProperties[],
|
nodePropertiesArray: INodeProperties[],
|
||||||
nodeValues: INodeParameters | null,
|
nodeValues: INodeParameters | null,
|
||||||
|
@ -1388,6 +1389,7 @@ function isINodeParameterResourceLocator(value: unknown): value is INodeParamete
|
||||||
* @param {INodeParameters} nodeValues The values of the node
|
* @param {INodeParameters} nodeValues The values of the node
|
||||||
* @param {string} path The path to the properties
|
* @param {string} path The path to the properties
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export function getParameterIssues(
|
export function getParameterIssues(
|
||||||
nodeProperties: INodeProperties,
|
nodeProperties: INodeProperties,
|
||||||
nodeValues: INodeParameters,
|
nodeValues: INodeParameters,
|
||||||
|
|
|
@ -121,6 +121,7 @@ function parseRegexPattern(pattern: string): RegExp {
|
||||||
return regex;
|
return regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export function executeFilterCondition(
|
export function executeFilterCondition(
|
||||||
condition: FilterConditionValue,
|
condition: FilterConditionValue,
|
||||||
filterOptions: FilterOptionsValue,
|
filterOptions: FilterOptionsValue,
|
||||||
|
|
|
@ -743,6 +743,7 @@ export class RoutingNode {
|
||||||
return parameterValue;
|
return parameterValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
getRequestOptionsFromParameters(
|
getRequestOptionsFromParameters(
|
||||||
executeSingleFunctions: IExecuteSingleFunctions,
|
executeSingleFunctions: IExecuteSingleFunctions,
|
||||||
nodeProperties: INodeProperties | INodePropertyOptions,
|
nodeProperties: INodeProperties | INodePropertyOptions,
|
||||||
|
|
|
@ -151,6 +151,7 @@ export function generateNodesGraph(
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
otherNodes.forEach((node: INode, index: number) => {
|
otherNodes.forEach((node: INode, index: number) => {
|
||||||
nodeGraph.node_types.push(node.type);
|
nodeGraph.node_types.push(node.type);
|
||||||
const nodeItem: INodeGraphItem = {
|
const nodeItem: INodeGraphItem = {
|
||||||
|
|
|
@ -178,6 +178,7 @@ type ValidateFieldTypeOptions = Partial<{
|
||||||
parseStrings: boolean;
|
parseStrings: boolean;
|
||||||
}>;
|
}>;
|
||||||
// Validates field against the schema and tries to parse it to the correct type
|
// Validates field against the schema and tries to parse it to the correct type
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export const validateFieldType = (
|
export const validateFieldType = (
|
||||||
fieldName: string,
|
fieldName: string,
|
||||||
value: unknown,
|
value: unknown,
|
||||||
|
|
|
@ -1264,6 +1264,7 @@ export class Workflow {
|
||||||
* Executes the given node.
|
* Executes the given node.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
async runNode(
|
async runNode(
|
||||||
executionData: IExecuteData,
|
executionData: IExecuteData,
|
||||||
runExecutionData: IRunExecutionData,
|
runExecutionData: IRunExecutionData,
|
||||||
|
|
|
@ -738,6 +738,7 @@ export class WorkflowDataProxy {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
const getPairedItem = (
|
const getPairedItem = (
|
||||||
destinationNodeName: string,
|
destinationNodeName: string,
|
||||||
incomingSourceData: ISourceData | null,
|
incomingSourceData: ISourceData | null,
|
||||||
|
|
|
@ -115,6 +115,7 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = {
|
||||||
export class NodeApiError extends NodeError {
|
export class NodeApiError extends NodeError {
|
||||||
httpCode: string | null;
|
httpCode: string | null;
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
constructor(
|
constructor(
|
||||||
node: INode,
|
node: INode,
|
||||||
errorResponse: JsonObject,
|
errorResponse: JsonObject,
|
||||||
|
|
Loading…
Reference in a new issue