Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Lint for cyclomatic complexity in BE packages (no-changelog) #9111

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {

rules: {
'n8n-local-rules/no-dynamic-import-template': 'error',
complexity: 'error',

// TODO: Remove this
'import/no-cycle': 'warn',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/CurlConverterHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/InternalHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export class InternalHooks {
]);
}

// eslint-disable-next-line complexity
async onWorkflowPostExecute(
executionId: string,
workflow: IWorkflowBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const normalizeFormData = <T>(values: Record<string, T | T[]>) => {
/**
* Executes a webhook
*/
// eslint-disable-next-line complexity
export async function executeWebhook(
workflow: Workflow,
webhookData: IWebhookData,
Expand Down Expand Up @@ -625,6 +626,7 @@ export async function executeWebhook(
executionId,
) as Promise<IExecutionDb | undefined>;
executePromise
// eslint-disable-next-line complexity
.then(async (data) => {
if (data === undefined) {
if (!didSendResponse) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/executeBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/export/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ExportCredentialsCommand extends BaseCommand {
}),
};

// eslint-disable-next-line complexity
async run() {
const { flags } = await this.parse(ExportCredentialsCommand);

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/export/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class ExportWorkflowsCommand extends BaseCommand {
}),
};

// eslint-disable-next-line complexity
async run() {
const { flags } = await this.parse(ExportWorkflowsCommand);

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/databases/dsl/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (this.isInitialized) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class MessageEventBusDestinationWebhook
return null;
}

// eslint-disable-next-line complexity
async receiveFromEventBus(emitterPayload: MessageWithCallback): Promise<boolean> {
const { msg, confirmCallback } = emitterPayload;
let sendResult = false;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/eventbus/executionDataRecovery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ExecutionDataRecoveryService {
private readonly executionRepository: ExecutionRepository,
) {}

// eslint-disable-next-line complexity
async recoverExecutionData(
executionId: string,
messages: EventMessageTypes[],
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/services/credentials-tester.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export class CredentialsTester {
return undefined;
}

// eslint-disable-next-line complexity
async testCredentials(
user: User,
credentialType: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/workflows/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class WorkflowService {
: { workflows, count };
}

// eslint-disable-next-line complexity
async update(
user: User,
workflow: WorkflowEntity,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/integration/shared/utils/testServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const setupTestServer = ({
license: new LicenseMocker(),
};

// eslint-disable-next-line complexity
beforeAll(async () => {
await testDb.init();

Expand Down
2 changes: 2 additions & 0 deletions packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2894,6 +2897,7 @@ const getRequestHelperFunctions = (

return {
httpRequest,
// eslint-disable-next-line complexity
async requestWithAuthenticationPaginated(
this: IExecuteFunctions,
requestOptions: IRequestOptions,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/WorkflowExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -371,6 +371,7 @@ export class WorkflowExecute {
}
}

// eslint-disable-next-line complexity
addNodeToBeExecuted(
workflow: Workflow,
connectionData: IConnection,
Expand Down Expand Up @@ -836,6 +837,7 @@ export class WorkflowExecute {
setTimeout(() => resolve(fullRunData), 10);
});

// eslint-disable-next-line complexity
const returnPromise = (async () => {
try {
if (!this.additionalData.restartExecutionId) {
Expand Down
2 changes: 2 additions & 0 deletions packages/workflow/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = {
...sharedOptions(__dirname),

rules: {
complexity: 'error',

// TODO: remove these
'import/order': 'off',
'@typescript-eslint/no-base-to-string': 'warn',
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/Extensions/ExpressionExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/workflow/src/NodeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/NodeParameters/FilterParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function parseRegexPattern(pattern: string): RegExp {
return regex;
}

// eslint-disable-next-line complexity
export function executeFilterCondition(
condition: FilterConditionValue,
filterOptions: FilterOptionsValue,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/RoutingNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ export class RoutingNode {
return parameterValue;
}

// eslint-disable-next-line complexity
getRequestOptionsFromParameters(
executeSingleFunctions: IExecuteSingleFunctions,
nodeProperties: INodeProperties | INodePropertyOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/TelemetryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/TypeValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ export class Workflow {
* Executes the given node.
*
*/
// eslint-disable-next-line complexity
async runNode(
executionData: IExecuteData,
runExecutionData: IRunExecutionData,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/WorkflowDataProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ export class WorkflowDataProxy {
});
};

// eslint-disable-next-line complexity
const getPairedItem = (
destinationNodeName: string,
incomingSourceData: ISourceData | null,
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/errors/node-api.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading