Skip to content

Commit

Permalink
refactor(editor): Stricter linting for promises and async functions (…
Browse files Browse the repository at this point in the history
…no-changelog) (#4642)
  • Loading branch information
michael-radency authored May 10, 2023
1 parent 1b1dc0e commit ed3bc15
Show file tree
Hide file tree
Showing 114 changed files with 351 additions and 344 deletions.
3 changes: 0 additions & 3 deletions packages/editor-ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-duplicate-imports': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-for-in-array': 'off',
'@typescript-eslint/no-loop-func': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
Expand All @@ -45,10 +44,8 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/promise-function-async': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
},
Expand Down
14 changes: 7 additions & 7 deletions packages/editor-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
return;
}
this.$router.replace({ name: VIEWS.SETUP });
void this.$router.replace({ name: VIEWS.SETUP });
return;
}
Expand All @@ -149,7 +149,7 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
const redirect =
this.$route.query.redirect ||
encodeURIComponent(`${window.location.pathname}${window.location.search}`);
this.$router.replace({ name: VIEWS.SIGNIN, query: { redirect } });
void this.$router.replace({ name: VIEWS.SIGNIN, query: { redirect } });
return;
}
Expand All @@ -158,21 +158,21 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
const redirect = decodeURIComponent(this.$route.query.redirect);
if (redirect.startsWith('/')) {
// protect against phishing
this.$router.replace(redirect);
void this.$router.replace(redirect);
return;
}
}
// if cannot access page and is logged in
this.$router.replace({ name: VIEWS.HOMEPAGE });
void this.$router.replace({ name: VIEWS.HOMEPAGE });
},
redirectIfNecessary() {
const redirect =
this.$route.meta &&
typeof this.$route.meta.getRedirect === 'function' &&
this.$route.meta.getRedirect();
if (redirect) {
this.$router.replace(redirect);
void this.$router.replace(redirect);
}
},
setTheme() {
Expand Down Expand Up @@ -203,7 +203,7 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
this.versionControlStore.isEnterpriseVersionControlEnabled &&
this.usersStore.isInstanceOwner
) {
this.versionControlStore.getPreferences();
void this.versionControlStore.getPreferences();
}
},
watch: {
Expand All @@ -214,7 +214,7 @@ export default mixins(newVersions, showMessage, userHelpers).extend({
this.trackPage();
},
defaultLocale(newLocale) {
loadLanguage(newLocale);
void loadLanguage(newLocale);
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/__tests__/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function setupServer() {
server.logging = false;

// Handle undefined endpoints
server.post('/rest/:any', () => new Promise(() => {}));
server.post('/rest/:any', async () => new Promise(() => {}));

// Handle defined endpoints
for (const endpointsFn of endpoints) {
Expand Down
15 changes: 10 additions & 5 deletions packages/editor-ui/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UserManagementAuthenticationMethod } from '@/Interface';
import { render } from '@testing-library/vue';
import { PiniaVuePlugin } from 'pinia';

export const retry = (assertion: () => any, { interval = 20, timeout = 200 } = {}) => {
export const retry = async (assertion: () => any, { interval = 20, timeout = 200 } = {}) => {
return new Promise((resolve, reject) => {
const startTime = Date.now();

Expand All @@ -27,7 +27,7 @@ export const renderComponent = (Component: RenderParams[0], renderOptions: Rende
vue.use(PiniaVuePlugin);
});

export const waitAllPromises = () => new Promise((resolve) => setTimeout(resolve));
export const waitAllPromises = async () => new Promise((resolve) => setTimeout(resolve));

export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
settings: {
Expand All @@ -43,8 +43,10 @@ export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
ldap: false,
saml: false,
logStreaming: false,
variables: false,
versionControl: false,
},
executionMode: '',
executionMode: 'regular',
executionTimeout: 0,
hideUsagePage: false,
hiringBannerEnabled: false,
Expand All @@ -66,8 +68,8 @@ export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
},
publicApi: { enabled: false, latestVersion: 0, path: '', swaggerUi: { enabled: false } },
pushBackend: 'sse',
saveDataErrorExecution: '',
saveDataSuccessExecution: '',
saveDataErrorExecution: 'all',
saveDataSuccessExecution: 'all',
saveManualExecutions: false,
sso: {
ldap: { loginEnabled: false, loginLabel: '' },
Expand All @@ -94,6 +96,9 @@ export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
deployment: {
type: 'default',
},
variables: {
limit: 100,
},
},
promptsData: {
message: '',
Expand Down
8 changes: 4 additions & 4 deletions packages/editor-ui/src/api/api-keys.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { IRestApiContext } from '@/Interface';
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';

export function getApiKey(context: IRestApiContext): Promise<{ apiKey: string | null }> {
export async function getApiKey(context: IRestApiContext): Promise<{ apiKey: string | null }> {
return makeRestApiRequest(context, 'GET', '/me/api-key');
}

export function createApiKey(context: IRestApiContext): Promise<{ apiKey: string | null }> {
export async function createApiKey(context: IRestApiContext): Promise<{ apiKey: string | null }> {
return makeRestApiRequest(context, 'POST', '/me/api-key');
}

export function deleteApiKey(context: IRestApiContext): Promise<{ success: boolean }> {
export async function deleteApiKey(context: IRestApiContext): Promise<{ success: boolean }> {
return makeRestApiRequest(context, 'DELETE', '/me/api-key');
}
6 changes: 3 additions & 3 deletions packages/editor-ui/src/api/communityNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export async function installNewPackage(
context: IRestApiContext,
name: string,
): Promise<PublicInstalledPackage> {
return await post(context.baseUrl, '/nodes', { name });
return post(context.baseUrl, '/nodes', { name });
}

export async function uninstallPackage(context: IRestApiContext, name: string): Promise<void> {
return await makeRestApiRequest(context, 'DELETE', '/nodes', { name });
return makeRestApiRequest(context, 'DELETE', '/nodes', { name });
}

export async function updatePackage(
context: IRestApiContext,
name: string,
): Promise<PublicInstalledPackage> {
return await makeRestApiRequest(context, 'PATCH', '/nodes', { name });
return makeRestApiRequest(context, 'PATCH', '/nodes', { name });
}
2 changes: 1 addition & 1 deletion packages/editor-ui/src/api/credentials.ee.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ICredentialsResponse, IRestApiContext, IShareCredentialsPayload } from '@/Interface';
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';
import type { IDataObject } from 'n8n-workflow';

export async function setCredentialSharedWith(
Expand Down
6 changes: 3 additions & 3 deletions packages/editor-ui/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ICredentialsResponse,
IRestApiContext,
} from '@/Interface';
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';
import type {
ICredentialsDecrypted,
ICredentialType,
Expand All @@ -22,11 +22,11 @@ export async function getCredentialsNewName(
context: IRestApiContext,
name?: string,
): Promise<{ name: string }> {
return await makeRestApiRequest(context, 'GET', '/credentials/new', name ? { name } : {});
return makeRestApiRequest(context, 'GET', '/credentials/new', name ? { name } : {});
}

export async function getAllCredentials(context: IRestApiContext): Promise<ICredentialsResponse[]> {
return await makeRestApiRequest(context, 'GET', '/credentials');
return makeRestApiRequest(context, 'GET', '/credentials');
}

export async function createNewCredential(
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/api/curlHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CurlToJSONResponse, IRestApiContext } from '@/Interface';
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';

export function getCurlToJson(
export async function getCurlToJson(
context: IRestApiContext,
curlCommand: string,
): Promise<CurlToJSONResponse> {
Expand Down
15 changes: 5 additions & 10 deletions packages/editor-ui/src/api/environments.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,33 @@ import { makeRestApiRequest } from '@/utils';
import type { IDataObject } from 'n8n-workflow';

export async function getVariables(context: IRestApiContext): Promise<EnvironmentVariable[]> {
return await makeRestApiRequest(context, 'GET', '/variables');
return makeRestApiRequest(context, 'GET', '/variables');
}

export async function getVariable(
context: IRestApiContext,
{ id }: { id: EnvironmentVariable['id'] },
): Promise<EnvironmentVariable> {
return await makeRestApiRequest(context, 'GET', `/variables/${id}`);
return makeRestApiRequest(context, 'GET', `/variables/${id}`);
}

export async function createVariable(
context: IRestApiContext,
data: Omit<EnvironmentVariable, 'id'>,
) {
return await makeRestApiRequest(context, 'POST', '/variables', data as unknown as IDataObject);
return makeRestApiRequest(context, 'POST', '/variables', data as unknown as IDataObject);
}

export async function updateVariable(
context: IRestApiContext,
{ id, ...data }: EnvironmentVariable,
) {
return await makeRestApiRequest(
context,
'PATCH',
`/variables/${id}`,
data as unknown as IDataObject,
);
return makeRestApiRequest(context, 'PATCH', `/variables/${id}`, data as unknown as IDataObject);
}

export async function deleteVariable(
context: IRestApiContext,
{ id }: { id: EnvironmentVariable['id'] },
) {
return await makeRestApiRequest(context, 'DELETE', `/variables/${id}`);
return makeRestApiRequest(context, 'DELETE', `/variables/${id}`);
}
12 changes: 6 additions & 6 deletions packages/editor-ui/src/api/ldap.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import type { ILdapConfig, ILdapSyncData, IRestApiContext } from '@/Interface';
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';
import type { IDataObject } from 'n8n-workflow';

export function getLdapConfig(context: IRestApiContext): Promise<ILdapConfig> {
export async function getLdapConfig(context: IRestApiContext): Promise<ILdapConfig> {
return makeRestApiRequest(context, 'GET', '/ldap/config');
}

export function testLdapConnection(context: IRestApiContext): Promise<{}> {
export async function testLdapConnection(context: IRestApiContext): Promise<{}> {
return makeRestApiRequest(context, 'POST', '/ldap/test-connection');
}

export function updateLdapConfig(
export async function updateLdapConfig(
context: IRestApiContext,
adConfig: ILdapConfig,
): Promise<ILdapConfig> {
return makeRestApiRequest(context, 'PUT', '/ldap/config', adConfig as unknown as IDataObject);
}

export function runLdapSync(context: IRestApiContext, data: IDataObject): Promise<{}> {
export async function runLdapSync(context: IRestApiContext, data: IDataObject): Promise<{}> {
return makeRestApiRequest(context, 'POST', '/ldap/sync', data as unknown as IDataObject);
}

export function getLdapSynchronizations(
export async function getLdapSynchronizations(
context: IRestApiContext,
pagination: { page: number },
): Promise<ILdapSyncData[]> {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/api/nodeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';
import type {
INodeTranslationHeaders,
IResourceLocatorReqParams,
Expand Down
10 changes: 5 additions & 5 deletions packages/editor-ui/src/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import type {
IN8nValueSurveyData,
IN8nPromptResponse,
} from '../Interface';
import { makeRestApiRequest, get, post } from '@/utils';
import { makeRestApiRequest, get, post } from '@/utils/apiUtils';
import { N8N_IO_BASE_URL, NPM_COMMUNITY_NODE_SEARCH_API_URL } from '@/constants';
import type { IN8nUISettings } from 'n8n-workflow';

export function getSettings(context: IRestApiContext): Promise<IN8nUISettings> {
export async function getSettings(context: IRestApiContext): Promise<IN8nUISettings> {
return makeRestApiRequest(context, 'GET', '/settings');
}

export async function getPromptsData(instanceId: string, userId: string): Promise<IN8nPrompts> {
return await get(
return get(
N8N_IO_BASE_URL,
'/prompts',
{},
Expand All @@ -26,7 +26,7 @@ export async function submitContactInfo(
userId: string,
email: string,
): Promise<IN8nPromptResponse> {
return await post(
return post(
N8N_IO_BASE_URL,
'/prompt',
{ email },
Expand All @@ -39,7 +39,7 @@ export async function submitValueSurvey(
userId: string,
params: IN8nValueSurveyData,
): Promise<IN8nPromptResponse> {
return await post(N8N_IO_BASE_URL, '/value-survey', params, {
return post(N8N_IO_BASE_URL, '/value-survey', params, {
'n8n-instance-id': instanceId,
'n8n-user-id': userId,
});
Expand Down
12 changes: 6 additions & 6 deletions packages/editor-ui/src/api/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ import type {
SamlPreferencesExtractedData,
} from '@/Interface';

export const initSSO = (context: IRestApiContext): Promise<string> => {
export const initSSO = async (context: IRestApiContext): Promise<string> => {
return makeRestApiRequest(context, 'GET', '/sso/saml/initsso');
};

export const getSamlMetadata = (context: IRestApiContext): Promise<SamlPreferences> => {
export const getSamlMetadata = async (context: IRestApiContext): Promise<SamlPreferences> => {
return makeRestApiRequest(context, 'GET', '/sso/saml/metadata');
};

export const getSamlConfig = (
export const getSamlConfig = async (
context: IRestApiContext,
): Promise<SamlPreferences & SamlPreferencesExtractedData> => {
return makeRestApiRequest(context, 'GET', '/sso/saml/config');
};

export const saveSamlConfig = (
export const saveSamlConfig = async (
context: IRestApiContext,
data: SamlPreferences,
): Promise<SamlPreferences | undefined> => {
return makeRestApiRequest(context, 'POST', '/sso/saml/config', data);
};

export const toggleSamlConfig = (
export const toggleSamlConfig = async (
context: IRestApiContext,
data: SamlPreferencesLoginEnabled,
): Promise<void> => {
return makeRestApiRequest(context, 'POST', '/sso/saml/config/toggle', data);
};

export const testSamlConfig = (context: IRestApiContext): Promise<string> => {
export const testSamlConfig = async (context: IRestApiContext): Promise<string> => {
return makeRestApiRequest(context, 'GET', '/sso/saml/config/test');
};
Loading

0 comments on commit ed3bc15

Please sign in to comment.