refactor(core): Forbid raw enums (no-changelog)

This commit is contained in:
Michael Kret 2023-04-21 14:23:15 +03:00 committed by GitHub
parent da31925083
commit 0e93fe064e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 119 additions and 115 deletions

View file

@ -397,6 +397,18 @@ const config = (module.exports = {
},
],
/**
* https://www.typescriptlang.org/docs/handbook/enums.html#const-enums
*/
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration:not([const=true])',
message:
'Do not declare raw enums as it leads to runtime overhead. Use const enum instead. See https://www.typescriptlang.org/docs/handbook/enums.html#const-enums',
},
],
// ----------------------------------
// import
// ----------------------------------

View file

@ -80,7 +80,7 @@ type HttpNodeHeaders = Pick<HttpNodeParameters, 'sendHeaders' | 'headerParameter
type HttpNodeQueries = Pick<HttpNodeParameters, 'sendQuery' | 'queryParameters'>;
enum ContentTypes {
const enum ContentTypes {
applicationJson = 'application/json',
applicationFormUrlEncoded = 'application/x-www-form-urlencoded',
applicationMultipart = 'multipart/form-data',

View file

@ -68,7 +68,7 @@ export const WORKFLOW_REACTIVATE_MAX_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
export const SETTINGS_LICENSE_CERT_KEY = 'license.cert';
export enum LICENSE_FEATURES {
export const enum LICENSE_FEATURES {
SHARING = 'feat:sharing',
LDAP = 'feat:ldap',
SAML = 'feat:saml',
@ -78,7 +78,7 @@ export enum LICENSE_FEATURES {
VERSION_CONTROL = 'feat:versionControl',
}
export enum LICENSE_QUOTAS {
export const enum LICENSE_QUOTAS {
TRIGGER_LIMIT = 'quota:activeWorkflows',
VARIABLES_LIMIT = 'quota:maxVariables',
}

View file

@ -3,7 +3,7 @@ import { idStringifier } from '../utils/transformers';
import { datetimeColumnType } from './AbstractEntity';
import { WorkflowEntity } from './WorkflowEntity';
export enum StatisticsNames {
export const enum StatisticsNames {
productionSuccess = 'production_success',
productionError = 'production_error',
manualSuccess = 'manual_success',

View file

@ -9,7 +9,7 @@ import { InternalHooks } from '@/InternalHooks';
import config from '@/config';
import { UserService } from '@/user/user.service';
enum StatisticsUpsertResult {
const enum StatisticsUpsertResult {
insert = 'insert',
update = 'update',
failed = 'failed',

View file

@ -635,7 +635,7 @@ export interface IN8nPromptResponse {
updated: boolean;
}
export enum UserManagementAuthenticationMethod {
export const enum UserManagementAuthenticationMethod {
Email = 'email',
Ldap = 'ldap',
Saml = 'saml',

View file

@ -362,7 +362,7 @@ export const NODE_TYPE_COUNT_MAPPER = {
};
export const TEMPLATES_NODES_FILTER = ['n8n-nodes-base.start', 'n8n-nodes-base.respondToWebhook'];
export enum VIEWS {
export const enum VIEWS {
HOMEPAGE = 'Homepage',
COLLECTION = 'TemplatesCollectionView',
EXECUTIONS = 'Executions',
@ -398,7 +398,7 @@ export enum VIEWS {
VERSION_CONTROL = 'VersionControl',
}
export enum FAKE_DOOR_FEATURES {
export const enum FAKE_DOOR_FEATURES {
ENVIRONMENTS = 'environments',
LOGGING = 'logging',
SSO = 'sso',
@ -443,7 +443,7 @@ export const MAPPING_PARAMS = [
export const DEFAULT_STICKY_HEIGHT = 160;
export const DEFAULT_STICKY_WIDTH = 240;
export enum WORKFLOW_MENU_ACTIONS {
export const enum WORKFLOW_MENU_ACTIONS {
DUPLICATE = 'duplicate',
DOWNLOAD = 'download',
IMPORT_FROM_URL = 'import-from-url',
@ -455,7 +455,7 @@ export enum WORKFLOW_MENU_ACTIONS {
/**
* Enterprise edition
*/
export enum EnterpriseEditionFeature {
export const enum EnterpriseEditionFeature {
AdvancedExecutionFilters = 'advancedExecutionFilters',
Sharing = 'sharing',
Ldap = 'ldap',
@ -466,7 +466,7 @@ export enum EnterpriseEditionFeature {
}
export const MAIN_NODE_PANEL_WIDTH = 360;
export enum MAIN_HEADER_TABS {
export const enum MAIN_HEADER_TABS {
WORKFLOW = 'workflow',
EXECUTIONS = 'executions',
SETTINGS = 'settings',
@ -504,7 +504,7 @@ export const CURL_IMPORT_NODES_PROTOCOLS: { [key: string]: string } = {
imaps: 'IMAP',
};
export enum STORES {
export const enum STORES {
COMMUNITY_NODES = 'communityNodes',
ROOT = 'root',
SETTINGS = 'settings',
@ -523,7 +523,7 @@ export enum STORES {
HISTORY = 'history',
}
export enum SignInType {
export const enum SignInType {
LDAP = 'ldap',
EMAIL = 'email',
}

View file

@ -6,7 +6,7 @@ import { createEventBus } from '@/event-bus';
// Command names don't serve any particular purpose in the app
// but they make it easier to identify each command on stack
// when debugging
export enum COMMANDS {
export const enum COMMANDS {
MOVE_NODE = 'moveNode',
ADD_NODE = 'addNode',
REMOVE_NODE = 'removeNode',

View file

@ -14,7 +14,7 @@ import {
import { EnterpriseEditionFeature, PLACEHOLDER_EMPTY_WORKFLOW_ID } from '@/constants';
import { useSettingsStore } from './stores/settings';
export enum UserRole {
export const enum UserRole {
InstanceOwner = 'isInstanceOwner',
ResourceOwner = 'isOwner',
ResourceEditor = 'isEditor',

View file

@ -24,7 +24,6 @@ module.exports = {
'@typescript-eslint/naming-convention': ['error', { selector: 'memberLike', format: null }],
'@typescript-eslint/no-explicit-any': 'off', //812 warnings, better to fix in separate PR
'@typescript-eslint/no-non-null-assertion': 'off', //665 errors, better to fix in separate PR
// '@typescript-eslint/no-unsafe-argument': 'off', //1538 errors, better to fix in separate PR
'@typescript-eslint/no-unsafe-assignment': 'off', //7084 problems, better to fix in separate PR
'@typescript-eslint/no-unsafe-call': 'off', //541 errors, better to fix in separate PR
'@typescript-eslint/no-unsafe-member-access': 'off', //4591 errors, better to fix in separate PR

View file

@ -51,7 +51,7 @@ export type PartitionKey = {
};
};
export enum EAttributeValueType {
export const enum EAttributeValueType {
S = 'S',
SS = 'SS',
M = 'M',

View file

@ -3,14 +3,14 @@ export interface IHourlyRateDto {
currency: string;
}
enum MembershipStatusEnum {
const enum MembershipStatusEnum {
PENDING = 'PENDING',
ACTIVE = 'ACTIVE',
DECLINED = 'DECLINED',
INACTIVE = 'INACTIVE',
}
enum TaskStatusEnum {
const enum TaskStatusEnum {
ACTIVE = 'ACTIVE',
DONE = 'DONE',
}

View file

@ -1,3 +1,3 @@
export enum EntryTypeEnum {
export const enum EntryTypeEnum {
NEW_TIME_ENTRY,
}

View file

@ -1,6 +1,6 @@
import type { IHourlyRateDto, IMembershipDto } from './CommonDtos';
enum EstimateEnum {
const enum EstimateEnum {
AUTO = 'AUTO',
MANUAL = 'MANUAL',
}
@ -40,7 +40,7 @@ export interface IProjectRequest {
tasks: ITaskDto;
}
enum TaskStatusEnum {
const enum TaskStatusEnum {
ACTIVE = 'ACTIVE',
DONE = 'DONE',
}

View file

@ -1,7 +1,7 @@
import type { IDataObject } from 'n8n-workflow';
import type { IMembershipDto } from './CommonDtos';
enum UserStatusEnum {
const enum UserStatusEnum {
ACTIVE,
PENDING_EMAIL_VERIFICATION,
DELETED,

View file

@ -1,12 +1,12 @@
import type { IHourlyRateDto, IMembershipDto } from './CommonDtos';
enum AdminOnlyPagesEnum {
const enum AdminOnlyPagesEnum {
PROJECT = 'PROJECT',
TEAM = 'TEAM',
REPORTS = 'REPORTS',
}
enum DaysOfWeekEnum {
const enum DaysOfWeekEnum {
MONDAY = 'MONDAY',
TUESDAY = 'TUESDAY',
WEDNESDAY = 'WEDNESDAY',
@ -16,13 +16,13 @@ enum DaysOfWeekEnum {
SUNDAY = 'SUNDAY',
}
enum DatePeriodEnum {
const enum DatePeriodEnum {
DAYS = 'DAYS',
WEEKS = 'WEEKS',
MONTHS = 'MONTHS',
}
enum AutomaticLockTypeEnum {
const enum AutomaticLockTypeEnum {
WEEKLY = 'WEEKLY',
MONTHLY = 'MONTHLY',
OLDER_THAN = 'OLDER_THAN',

View file

@ -1,6 +1,6 @@
import type { IDataObject } from 'n8n-workflow';
export enum JobStatus {
export const enum JobStatus {
WAITING = 'Waiting',
INPROGRESS = 'InProgress',
SUCCESS = 'Success',
@ -8,14 +8,14 @@ export enum JobStatus {
DELETED = 'Deleted',
}
export enum TLP {
export const enum TLP {
white,
green,
amber,
red,
}
export enum ObservableDataType {
export const enum ObservableDataType {
'domain' = 'domain',
'file' = 'file',
'filename' = 'filename',

View file

@ -39,7 +39,7 @@ export interface IFormstackSubmissionFieldContainer {
value: string;
}
export enum FormstackFieldFormat {
export const enum FormstackFieldFormat {
ID = 'id',
Label = 'label',
Name = 'name',

View file

@ -20,21 +20,21 @@ import type { ICreateContactBody } from './ContactInterface';
import { contactFields, contactOperations } from './ContactDescription';
enum Status {
const enum Status {
Open = 2,
Pending = 3,
Resolved = 4,
Closed = 5,
}
enum Priority {
const enum Priority {
Low = 1,
Medium = 2,
High = 3,
Urgent = 4,
}
enum Source {
const enum Source {
Email = 1,
Portal = 2,
Phone = 3,

View file

@ -31,7 +31,7 @@ export interface IUser {
type?: Type;
isAnonymous?: boolean;
}
enum Type {
const enum Type {
'TYPE_UNSPECIFIED',
'HUMAN',
'BOT',

View file

@ -64,11 +64,11 @@ export type SheetProperties = PropertiesOf<GoogleSheetsSheet>;
export type ResourceLocator = 'id' | 'url' | 'list';
export enum ResourceLocatorUiNames {
id = 'By ID',
url = 'By URL',
list = 'From List',
}
export const ResourceLocatorUiNames = {
id: 'By ID',
url: 'By URL',
list: 'From List',
};
export type SheetCellDecoded = {
cell?: string;

View file

@ -29,16 +29,16 @@ type Aggregation = {
type Aggregations = Aggregation[];
enum AggregationDisplayNames {
append = 'appended_',
average = 'average_',
concatenate = 'concatenated_',
count = 'count_',
countUnique = 'unique_count_',
max = 'max_',
min = 'min_',
sum = 'sum_',
}
const AggregationDisplayNames = {
append: 'appended_',
average: 'average_',
concatenate: 'concatenated_',
count: 'count_',
countUnique: 'unique_count_',
max: 'max_',
min: 'min_',
sum: 'sum_',
};
const NUMERICAL_AGGREGATIONS = ['average', 'max', 'min', 'sum'];

View file

@ -29,16 +29,17 @@ type Aggregation = {
type Aggregations = Aggregation[];
enum AggregationDisplayNames {
append = 'appended_',
average = 'average_',
concatenate = 'concatenated_',
count = 'count_',
countUnique = 'unique_count_',
max = 'max_',
min = 'min_',
sum = 'sum_',
}
// eslint-disable-next-line no-restricted-syntax
const AggregationDisplayNames = {
append: 'appended_',
average: 'average_',
concatenate: 'concatenated_',
count: 'count_',
countUnique: 'unique_count_',
max: 'max_',
min: 'min_',
sum: 'sum_',
};
const NUMERICAL_AGGREGATIONS = ['average', 'max', 'min', 'sum'];

View file

@ -17,7 +17,7 @@ import {
import moment from 'moment';
enum Status {
const enum Status {
subscribe = 'subscribe',
unsubscribed = 'unsubscribe',
cleaned = 'cleaned',

View file

@ -1,10 +1,10 @@
export enum RecipientType {
export const enum RecipientType {
email = 'EMAIL',
phone = 'PHONE',
paypalId = 'PAYPAL_ID',
}
export enum RecipientWallet {
export const enum RecipientWallet {
paypal = 'PAYPAL',
venmo = 'VENMO',
}

View file

@ -18,13 +18,13 @@ export namespace SendInBlueNode {
type BBCEmail = { bbc: Email[] };
type ValidatedEmail = ToEmail | SenderEmail | CCEmail | BBCEmail;
enum OVERRIDE_MAP_VALUES {
const enum OVERRIDE_MAP_VALUES {
'CATEGORY' = 'category',
'NORMAL' = 'boolean',
'TRANSACTIONAL' = 'id',
}
enum OVERRIDE_MAP_TYPE {
const enum OVERRIDE_MAP_TYPE {
'CATEGORY' = 'category',
'NORMAL' = 'normal',
'TRANSACTIONAL' = 'transactional',

View file

@ -1,11 +1,11 @@
import type { IDataObject } from 'n8n-workflow';
export enum AlertStatus {
export const enum AlertStatus {
NEW = 'New',
UPDATED = 'Updated',
IGNORED = 'Ignored',
IMPORTED = 'Imported',
}
export enum TLP {
export const enum TLP {
white,
green,
amber,

View file

@ -31,13 +31,13 @@ export interface ICase {
upadtedAt?: Date;
}
export enum CaseStatus {
export const enum CaseStatus {
OPEN = 'Open',
RESOLVED = 'Resolved',
DELETED = 'Deleted',
}
export enum CaseResolutionStatus {
export const enum CaseResolutionStatus {
INDETERMINATE = 'Indeterminate',
FALSEPOSITIVE = 'FalsePositive',
TRUEPOSITIVE = 'TruePositive',
@ -45,7 +45,7 @@ export enum CaseResolutionStatus {
DUPLICATED = 'Duplicated',
}
export enum CaseImpactStatus {
export const enum CaseImpactStatus {
NOIMPACT = 'NoImpact',
WITHIMPACT = 'WithImpact',
NOTAPPLICABLE = 'NotApplicable',

View file

@ -1,5 +1,5 @@
import type { IAttachment } from './ObservableInterface';
export enum LogStatus {
export const enum LogStatus {
OK = 'Ok',
DELETED = 'Deleted',
}

View file

@ -1,10 +1,10 @@
import type { TLP } from './AlertInterface';
export enum ObservableStatus {
export const enum ObservableStatus {
OK = 'Ok',
DELETED = 'Deleted',
}
export enum ObservableDataType {
export const enum ObservableDataType {
'domain' = 'domain',
'file' = 'file',
'filename' = 'filename',

View file

@ -17,7 +17,7 @@ export interface ITask {
upadtedAt?: Date;
}
export enum TaskStatus {
export const enum TaskStatus {
WAITING = 'Waiting',
INPROGRESS = 'InProgress',
COMPLETED = 'Completed',

View file

@ -42,7 +42,7 @@ export interface Command {
};
}
export enum CommandType {
export const enum CommandType {
ITEM_MOVE = 'item_move',
ITEM_ADD = 'item_add',
ITEM_UPDATE = 'item_update',

View file

@ -35,17 +35,16 @@ export class TodoistService implements Service {
};
}
export enum OperationType {
create = 'create',
close = 'close',
delete = 'delete',
get = 'get',
getAll = 'getAll',
reopen = 'reopen',
update = 'update',
move = 'move',
sync = 'sync',
}
export type OperationType =
| 'create'
| 'close'
| 'delete'
| 'get'
| 'getAll'
| 'reopen'
| 'update'
| 'move'
| 'sync';
export interface Section {
name: string;

View file

@ -13,7 +13,8 @@ import type {
import { todoistApiRequest } from '../GenericFunctions';
import { OperationType, TodoistService } from './Service';
import type { OperationType } from './Service';
import { TodoistService } from './Service';
// interface IBodyCreateTask {
// content?: string;
@ -702,15 +703,11 @@ export class TodoistV1 implements INodeType {
const service = new TodoistService();
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const operation = this.getNodeParameter('operation', 0) as OperationType;
for (let i = 0; i < length; i++) {
try {
if (resource === 'task') {
responseData = await service.execute(
this,
OperationType[operation as keyof typeof OperationType],
i,
);
responseData = await service.execute(this, operation, i);
}
if (Array.isArray(responseData?.data)) {
returnData.push.apply(returnData, responseData?.data as IDataObject[]);

View file

@ -42,7 +42,7 @@ export interface Command {
};
}
export enum CommandType {
export const enum CommandType {
ITEM_MOVE = 'item_move',
ITEM_ADD = 'item_add',
ITEM_UPDATE = 'item_update',

View file

@ -35,17 +35,16 @@ export class TodoistService implements Service {
};
}
export enum OperationType {
create = 'create',
close = 'close',
delete = 'delete',
get = 'get',
getAll = 'getAll',
reopen = 'reopen',
update = 'update',
move = 'move',
sync = 'sync',
}
export type OperationType =
| 'create'
| 'close'
| 'delete'
| 'get'
| 'getAll'
| 'reopen'
| 'update'
| 'move'
| 'sync';
export interface Section {
name: string;

View file

@ -13,7 +13,8 @@ import type {
import { todoistApiRequest } from '../GenericFunctions';
import { OperationType, TodoistService } from './Service';
import type { OperationType } from './Service';
import { TodoistService } from './Service';
// interface IBodyCreateTask {
// content?: string;
@ -701,15 +702,11 @@ export class TodoistV2 implements INodeType {
const service = new TodoistService();
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const operation = this.getNodeParameter('operation', 0) as OperationType;
for (let i = 0; i < length; i++) {
try {
if (resource === 'task') {
responseData = await service.execute(
this,
OperationType[operation as keyof typeof OperationType],
i,
);
responseData = await service.execute(this, operation, i);
}
if (responseData !== undefined && Array.isArray(responseData?.data)) {

View file

@ -1868,7 +1868,7 @@ export interface IConnectedNode {
depth: number;
}
export enum OAuth2GrantType {
export const enum OAuth2GrantType {
authorizationCode = 'authorizationCode',
clientCredentials = 'clientCredentials',
}

View file

@ -5,7 +5,7 @@ import type { INodeCredentials } from './Interfaces';
// General Enums And Interfaces
// ===============================
export enum EventMessageTypeNames {
export const enum EventMessageTypeNames {
generic = '$$EventMessage',
audit = '$$EventMessageAudit',
confirm = '$$EventMessageConfirm',
@ -13,7 +13,7 @@ export enum EventMessageTypeNames {
node = '$$EventMessageNode',
}
export enum MessageEventBusDestinationTypeNames {
export const enum MessageEventBusDestinationTypeNames {
abstract = '$$AbstractMessageEventBusDestination',
webhook = '$$MessageEventBusDestinationWebhook',
sentry = '$$MessageEventBusDestinationSentry',