Skip to content

Commit

Permalink
refactor(core): Enable import/order eslint rule (#10794)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Sep 12, 2024
1 parent 6530620 commit 5156313
Show file tree
Hide file tree
Showing 569 changed files with 2,889 additions and 2,393 deletions.
12 changes: 11 additions & 1 deletion packages/cli/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ module.exports = {

// TODO: Remove this
'import/no-cycle': 'warn',
'import/order': 'off',
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
groups: [['builtin', 'external'], 'internal', ['parent', 'index', 'sibling'], 'object'],
'newlines-between': 'always',
},
],
'import/extensions': 'warn',
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
'@typescript-eslint/no-explicit-any': 'warn',
Expand Down
11 changes: 6 additions & 5 deletions packages/cli/src/__tests__/active-executions.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ActiveExecutions } from '@/active-executions';
import PCancelable from 'p-cancelable';
import { v4 as uuid } from 'uuid';
import { mock } from 'jest-mock-extended';
import type {
IExecuteResponsePromiseData,
IRun,
IWorkflowExecutionDataProcess,
} from 'n8n-workflow';
import { createDeferredPromise } from 'n8n-workflow';
import type { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { mock } from 'jest-mock-extended';
import PCancelable from 'p-cancelable';
import { v4 as uuid } from 'uuid';

import { ActiveExecutions } from '@/active-executions';
import { ConcurrencyControlService } from '@/concurrency/concurrency-control.service';
import type { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { mockInstance } from '@test/mocking';

const FAKE_EXECUTION_ID = '15';
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/__tests__/credential-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CredentialTypes } from '@/credential-types';
import { Container } from 'typedi';

import { CredentialTypes } from '@/credential-types';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { mockInstance } from '@test/mocking';

Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/__tests__/credentials-helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Container from 'typedi';
import type {
IAuthenticateGeneric,
ICredentialDataDecryptedObject,
Expand All @@ -9,11 +8,13 @@ import type {
} from 'n8n-workflow';
import { NodeConnectionType, deepCopy } from 'n8n-workflow';
import { Workflow } from 'n8n-workflow';
import Container from 'typedi';

import { CredentialsHelper } from '@/credentials-helper';
import { NodeTypes } from '@/node-types';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { CredentialsRepository } from '@/databases/repositories/credentials.repository';
import { SharedCredentialsRepository } from '@/databases/repositories/shared-credentials.repository';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { NodeTypes } from '@/node-types';
import { mockInstance } from '@test/mocking';

describe('CredentialsHelper', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/__tests__/license.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { LicenseManager } from '@n8n_io/license-sdk';
import { InstanceSettings } from 'n8n-core';
import { mock } from 'jest-mock-extended';
import { InstanceSettings } from 'n8n-core';

import config from '@/config';
import { N8N_VERSION } from '@/constants';
import { License } from '@/license';
import { Logger } from '@/logger';
import { N8N_VERSION } from '@/constants';
import { mockInstance } from '@test/mocking';
import { OrchestrationService } from '@/services/orchestration.service';
import { mockInstance } from '@test/mocking';

jest.mock('@n8n_io/license-sdk');

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/__tests__/wait-tracker.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { WaitTracker } from '@/wait-tracker';
import { mock } from 'jest-mock-extended';

import type { ExecutionRepository } from '@/databases/repositories/execution.repository';
import type { IExecutionResponse } from '@/interfaces';
import { OrchestrationService } from '@/services/orchestration.service';
import type { MultiMainSetup } from '@/services/orchestration/main/multi-main-setup.ee';
import { OrchestrationService } from '@/services/orchestration.service';
import { WaitTracker } from '@/wait-tracker';

jest.useFakeTimers();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { VariablesService } from '@/environments/variables/variables.service.ee';
import { mockInstance } from '@test/mocking';
import { getBase } from '@/workflow-execute-additional-data';
import Container from 'typedi';

import { CredentialsHelper } from '@/credentials-helper';
import { SecretsHelper } from '@/secrets-helpers';
import { VariablesService } from '@/environments/variables/variables.service.ee';
import { EventService } from '@/events/event.service';
import { SecretsHelper } from '@/secrets-helpers';
import { getBase } from '@/workflow-execute-additional-data';
import { mockInstance } from '@test/mocking';

describe('WorkflowExecuteAdditionalData', () => {
const variablesService = mockInstance(VariablesService);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/workflow-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Workflow, IWorkflowExecutionDataProcess } from 'n8n-workflow';

import { getExecutionStartNode } from '@/workflow-helpers';

describe('WorkflowHelpers', () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/__tests__/workflow-runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Container from 'typedi';
import { WorkflowHooks, type ExecutionError, type IWorkflowExecuteHooks } from 'n8n-workflow';
import Container from 'typedi';

import config from '@/config';
import type { User } from '@/databases/entities/user';
import { Telemetry } from '@/telemetry';
import { WorkflowRunner } from '@/workflow-runner';
import config from '@/config';

import * as testDb from '@test-integration/test-db';
import { setupTestServer } from '@test-integration/utils';
import { mockInstance } from '@test/mocking';
import { createExecution } from '@test-integration/db/executions';
import { createUser } from '@test-integration/db/users';
import { createWorkflow } from '@test-integration/db/workflows';
import { createExecution } from '@test-integration/db/executions';
import { mockInstance } from '@test/mocking';
import { Telemetry } from '@/telemetry';
import * as testDb from '@test-integration/test-db';
import { setupTestServer } from '@test-integration/utils';

let owner: User;
let runner: WorkflowRunner;
Expand Down
21 changes: 11 additions & 10 deletions packages/cli/src/abstract-server.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { Container, Service } from 'typedi';
import { readFile } from 'fs/promises';
import type { Server } from 'http';
import { GlobalConfig } from '@n8n/config';
import compression from 'compression';
import express from 'express';
import { engine as expressHandlebars } from 'express-handlebars';
import compression from 'compression';
import { readFile } from 'fs/promises';
import type { Server } from 'http';
import isbot from 'isbot';
import { Container, Service } from 'typedi';

import config from '@/config';
import { N8N_VERSION, TEMPLATES_DIR, inDevelopment, inTest } from '@/constants';
import * as Db from '@/db';
import { N8nInstanceType } from '@/interfaces';
import { OnShutdown } from '@/decorators/on-shutdown';
import { ExternalHooks } from '@/external-hooks';
import { send, sendErrorResponse } from '@/response-helper';
import { N8nInstanceType } from '@/interfaces';
import { Logger } from '@/logger';
import { rawBodyReader, bodyParser, corsMiddleware } from '@/middlewares';
import { send, sendErrorResponse } from '@/response-helper';
import { WaitingForms } from '@/waiting-forms';
import { LiveWebhooks } from '@/webhooks/live-webhooks';
import { TestWebhooks } from '@/webhooks/test-webhooks';
import { WaitingWebhooks } from '@/webhooks/waiting-webhooks';
import { createWebhookHandlerFor } from '@/webhooks/webhook-request-handler';
import { LiveWebhooks } from '@/webhooks/live-webhooks';

import { generateHostInstanceId } from './databases/utils/generators';
import { Logger } from '@/logger';
import { ServiceUnavailableError } from './errors/response-errors/service-unavailable.error';
import { OnShutdown } from '@/decorators/on-shutdown';
import { GlobalConfig } from '@n8n/config';

@Service()
export abstract class AbstractServer {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/activation-errors.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Service } from 'typedi';

import { CacheService } from '@/services/cache/cache.service';

@Service()
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/active-executions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Service } from 'typedi';
import type PCancelable from 'p-cancelable';
import type {
IDeferredPromise,
IExecuteResponsePromiseData,
Expand All @@ -14,16 +12,19 @@ import {
sleep,
} from 'n8n-workflow';
import { strict as assert } from 'node:assert';
import type PCancelable from 'p-cancelable';
import { Service } from 'typedi';

import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import type {
ExecutionPayload,
IExecutingWorkflowData,
IExecutionDb,
IExecutionsCurrentSummary,
} from '@/interfaces';
import { isWorkflowIdValid } from '@/utils';
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { Logger } from '@/logger';
import { isWorkflowIdValid } from '@/utils';

import { ConcurrencyControlService } from './concurrency/concurrency-control.service';
import config from './config';

Expand Down
29 changes: 14 additions & 15 deletions packages/cli/src/active-workflow-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

import { Service } from 'typedi';
import { ActiveWorkflows, NodeExecuteFunctions } from 'n8n-core';

import type {
ExecutionError,
IDeferredPromise,
Expand All @@ -25,30 +23,31 @@ import {
WebhookPathTakenError,
ApplicationError,
} from 'n8n-workflow';
import { Service } from 'typedi';

import type { IWorkflowDb } from '@/interfaces';
import * as WebhookHelpers from '@/webhooks/webhook-helpers';
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';

import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import { ActivationErrorsService } from '@/activation-errors.service';
import { ActiveExecutions } from '@/active-executions';
import { ExecutionService } from './executions/execution.service';
import {
STARTING_NODES,
WORKFLOW_REACTIVATE_INITIAL_TIMEOUT,
WORKFLOW_REACTIVATE_MAX_TIMEOUT,
} from '@/constants';
import { NodeTypes } from '@/node-types';
import { ExternalHooks } from '@/external-hooks';
import { WebhookService } from '@/webhooks/webhook.service';
import { Logger } from './logger';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
import { OrchestrationService } from '@/services/orchestration.service';
import { ActivationErrorsService } from '@/activation-errors.service';
import { OnShutdown } from '@/decorators/on-shutdown';
import { ExternalHooks } from '@/external-hooks';
import type { IWorkflowDb } from '@/interfaces';
import { NodeTypes } from '@/node-types';
import { ActiveWorkflowsService } from '@/services/active-workflows.service';
import { OrchestrationService } from '@/services/orchestration.service';
import * as WebhookHelpers from '@/webhooks/webhook-helpers';
import { WebhookService } from '@/webhooks/webhook.service';
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';
import { WorkflowExecutionService } from '@/workflows/workflow-execution.service';
import { WorkflowStaticDataService } from '@/workflows/workflow-static-data.service';
import { OnShutdown } from '@/decorators/on-shutdown';

import { ExecutionService } from './executions/execution.service';
import { Logger } from './logger';

interface QueuedActivation {
activationMode: WorkflowActivateMode;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/auth/__tests__/auth.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import jwt from 'jsonwebtoken';
import { mock } from 'jest-mock-extended';
import type { NextFunction, Response } from 'express';
import { mock } from 'jest-mock-extended';
import jwt from 'jsonwebtoken';

import { AuthService } from '@/auth/auth.service';
import config from '@/config';
import { AUTH_COOKIE_NAME, Time } from '@/constants';
import type { User } from '@/databases/entities/user';
import type { InvalidAuthTokenRepository } from '@/databases/repositories/invalid-auth-token.repository';
import type { UserRepository } from '@/databases/repositories/user.repository';
import type { AuthenticatedRequest } from '@/requests';
import { JwtService } from '@/services/jwt.service';
import type { UrlService } from '@/services/url.service';
import type { AuthenticatedRequest } from '@/requests';

describe('AuthService', () => {
config.set('userManagement.jwtSecret', 'random-secret');
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Container, { Service } from 'typedi';
import type { NextFunction, Response } from 'express';
import { GlobalConfig } from '@n8n/config';
import { createHash } from 'crypto';
import type { NextFunction, Response } from 'express';
import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken';
import Container, { Service } from 'typedi';

import config from '@/config';
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES, Time } from '@/constants';
Expand All @@ -15,7 +16,6 @@ import { Logger } from '@/logger';
import type { AuthenticatedRequest } from '@/requests';
import { JwtService } from '@/services/jwt.service';
import { UrlService } from '@/services/url.service';
import { GlobalConfig } from '@n8n/config';

interface AuthJwtPayload {
/** User Id */
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/auth/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Container } from 'typedi';
import type { Response } from 'express';
import { Container } from 'typedi';

import type { User } from '@/databases/entities/user';

import { AuthService } from './auth.service';

// This method is still used by cloud hooks.
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/auth/methods/email.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { User } from '@/databases/entities/user';
import { PasswordUtility } from '@/services/password.utility';
import { Container } from 'typedi';
import { isLdapLoginEnabled } from '@/ldap/helpers.ee';

import type { User } from '@/databases/entities/user';
import { UserRepository } from '@/databases/repositories/user.repository';
import { AuthError } from '@/errors/response-errors/auth.error';
import { EventService } from '@/events/event.service';
import { isLdapLoginEnabled } from '@/ldap/helpers.ee';
import { PasswordUtility } from '@/services/password.utility';

export const handleEmailLogin = async (
email: string,
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/auth/methods/ldap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container } from 'typedi';

import { LdapService } from '@/ldap/ldap.service.ee';
import type { User } from '@/databases/entities/user';
import { EventService } from '@/events/event.service';
import {
createLdapUserOnLocalDb,
getUserByEmail,
Expand All @@ -10,8 +11,7 @@ import {
createLdapAuthIdentity,
updateLdapUserOnLocalDb,
} from '@/ldap/helpers.ee';
import type { User } from '@/databases/entities/user';
import { EventService } from '@/events/event.service';
import { LdapService } from '@/ldap/ldap.service.ee';

export const handleLdapLogin = async (
loginId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { CollaborationState } from '../collaboration.state';
import type { CacheService } from '@/services/cache/cache.service';
import { mock } from 'jest-mock-extended';

import type { CacheService } from '@/services/cache/cache.service';

import { CollaborationState } from '../collaboration.state';

const origDate = global.Date;

const mockDateFactory = (currentDate: string) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/collaboration/collaboration.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Service } from 'typedi';
import type { Workflow } from 'n8n-workflow';
import { ApplicationError, ErrorReporterProxy } from 'n8n-workflow';
import { Service } from 'typedi';

import { Push } from '@/push';
import { CollaborationState } from '@/collaboration/collaboration.state';
import type { User } from '@/databases/entities/user';
import { UserRepository } from '@/databases/repositories/user.repository';
import type { ICollaboratorsChanged } from '@/interfaces';
import { Push } from '@/push';
import type { OnPushMessage } from '@/push/types';
import { UserRepository } from '@/databases/repositories/user.repository';
import type { User } from '@/databases/entities/user';
import { CollaborationState } from '@/collaboration/collaboration.state';
import { AccessService } from '@/services/access.service';

import type { WorkflowClosedMessage, WorkflowOpenedMessage } from './collaboration.message';
Expand Down
Loading

0 comments on commit 5156313

Please sign in to comment.