mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -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: {
|
||||
'n8n-local-rules/no-dynamic-import-template': 'error',
|
||||
complexity: 'error',
|
||||
|
||||
// TODO: Remove this
|
||||
'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 => {
|
||||
const curlJson = curlToJson(curlCommand);
|
||||
|
||||
|
|
|
@ -339,6 +339,7 @@ export class InternalHooks {
|
|||
]);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async onWorkflowPostExecute(
|
||||
executionId: string,
|
||||
workflow: IWorkflowBase,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -48,6 +48,7 @@ export class ExportCredentialsCommand extends BaseCommand {
|
|||
}),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async run() {
|
||||
const { flags } = await this.parse(ExportCredentialsCommand);
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ export class ExportWorkflowsCommand extends BaseCommand {
|
|||
}),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async run() {
|
||||
const { flags } = await this.parse(ExportWorkflowsCommand);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,6 +16,7 @@ export class ExecutionDataRecoveryService {
|
|||
private readonly executionRepository: ExecutionRepository,
|
||||
) {}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async recoverExecutionData(
|
||||
executionId: string,
|
||||
messages: EventMessageTypes[],
|
||||
|
|
|
@ -166,6 +166,7 @@ export class CredentialsTester {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async testCredentials(
|
||||
user: User,
|
||||
credentialType: string,
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -55,6 +55,7 @@ export class WorkflowService {
|
|||
: { workflows, count };
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async update(
|
||||
user: User,
|
||||
workflow: WorkflowEntity,
|
||||
|
|
|
@ -95,6 +95,7 @@ export const setupTestServer = ({
|
|||
license: new LicenseMocker(),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
beforeAll(async () => {
|
||||
await testDb.init();
|
||||
|
||||
|
|
|
@ -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 }],
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -9,6 +9,8 @@ module.exports = {
|
|||
...sharedOptions(__dirname),
|
||||
|
||||
rules: {
|
||||
complexity: 'error',
|
||||
|
||||
// TODO: remove these
|
||||
'import/order': 'off',
|
||||
'@typescript-eslint/no-base-to-string': 'warn',
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -121,6 +121,7 @@ function parseRegexPattern(pattern: string): RegExp {
|
|||
return regex;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
export function executeFilterCondition(
|
||||
condition: FilterConditionValue,
|
||||
filterOptions: FilterOptionsValue,
|
||||
|
|
|
@ -743,6 +743,7 @@ export class RoutingNode {
|
|||
return parameterValue;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
getRequestOptionsFromParameters(
|
||||
executeSingleFunctions: IExecuteSingleFunctions,
|
||||
nodeProperties: INodeProperties | INodePropertyOptions,
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1264,6 +1264,7 @@ export class Workflow {
|
|||
* Executes the given node.
|
||||
*
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
async runNode(
|
||||
executionData: IExecuteData,
|
||||
runExecutionData: IRunExecutionData,
|
||||
|
|
|
@ -738,6 +738,7 @@ export class WorkflowDataProxy {
|
|||
});
|
||||
};
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
const getPairedItem = (
|
||||
destinationNodeName: string,
|
||||
incomingSourceData: ISourceData | null,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue