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: Lint for no unneeded backticks #5057

Merged
merged 9 commits into from
Dec 29, 2022
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
2 changes: 2 additions & 0 deletions packages/@n8n_io/eslint-config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ const config = (module.exports = {

'n8n-local-rules/no-json-parse-json-stringify': 'error',

'n8n-local-rules/no-unneeded-backticks': 'error',

// ******************************************************************
// overrides to base ruleset
// ******************************************************************
Expand Down
33 changes: 33 additions & 0 deletions packages/@n8n_io/eslint-config/local-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,39 @@ module.exports = {
};
},
},

'no-unneeded-backticks': {
meta: {
type: 'problem',
docs: {
description:
'Template literal backticks may only be used for string interpolation or multiline strings.',
recommended: 'error',
},
messages: {
noUneededBackticks: 'Use single or double quotes, not backticks',
},
fixable: 'code',
},
create(context) {
return {
TemplateLiteral(node) {
if (node.expressions.length > 0) return;
if (node.quasis.every((q) => q.loc.start.line !== q.loc.end.line)) return;

node.quasis.forEach((q) => {
const escaped = q.value.raw.replace(/(?<!\\)'/g, "\\'");

context.report({
messageId: 'noUneededBackticks',
node,
fix: (fixer) => fixer.replaceText(q, `'${escaped}'`),
});
});
},
};
},
},
};

const isJsonParseCall = (node) =>
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/ActiveWorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ import { WorkflowRunner } from '@/WorkflowRunner';
import { ExternalHooks } from '@/ExternalHooks';
import { whereClause } from './UserManagement/UserManagementHelper';

const WEBHOOK_PROD_UNREGISTERED_HINT = `The workflow must be active for a production URL to run successfully. You can activate the workflow using the toggle in the top-right of the editor. Note that unlike test URL calls, production URL calls aren't shown on the canvas (only in the executions list)`;
const WEBHOOK_PROD_UNREGISTERED_HINT =
"The workflow must be active for a production URL to run successfully. You can activate the workflow using the toggle in the top-right of the editor. Note that unlike test URL calls, production URL calls aren't shown on the canvas (only in the executions list)";

export class ActiveWorkflowRunner {
private activeWorkflows: ActiveWorkflows | null = null;
Expand Down Expand Up @@ -118,11 +119,11 @@ export class ActiveWorkflowRunner {
workflowName: workflowData.name,
workflowId: workflowData.id,
});
console.log(` => Started`);
console.log(' => Started');
} catch (error) {
ErrorReporter.error(error);
console.log(
` => ERROR: Workflow could not be activated on first try, keep on trying`,
' => ERROR: Workflow could not be activated on first try, keep on trying',
);
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.log(` ${error.message}`);
Expand Down Expand Up @@ -773,7 +774,7 @@ export class ActiveWorkflowRunner {
workflowData?: IWorkflowDb,
): Promise<void> {
if (this.activeWorkflows === null) {
throw new Error(`The "activeWorkflows" instance did not get initialized yet.`);
throw new Error('The "activeWorkflows" instance did not get initialized yet.');
}

let workflowInstance: Workflow;
Expand Down Expand Up @@ -806,7 +807,7 @@ export class ActiveWorkflowRunner {
if (!canBeActivated) {
Logger.error(`Unable to activate workflow "${workflowData.name}"`);
throw new Error(
`The workflow can not be activated because it does not contain any nodes which could start the workflow. Only workflows which have trigger or webhook nodes can be activated.`,
'The workflow can not be activated because it does not contain any nodes which could start the workflow. Only workflows which have trigger or webhook nodes can be activated.',
);
}

Expand Down Expand Up @@ -1001,7 +1002,7 @@ export class ActiveWorkflowRunner {
return;
}

throw new Error(`The "activeWorkflows" instance did not get initialized yet.`);
throw new Error('The "activeWorkflows" instance did not get initialized yet.');
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/Push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Push {
this.channel.on('disconnect', (channel: string, res: Response) => {
if (res.req !== undefined) {
const { sessionId } = res.req.query;
Logger.debug(`Remove editor-UI session`, { sessionId });
Logger.debug('Remove editor-UI session', { sessionId });
delete this.connections[sessionId as string];
}
});
Expand All @@ -27,7 +27,7 @@ export class Push {
* @param {Response} res The response
*/
add(sessionId: string, req: Request, res: Response) {
Logger.debug(`Add editor-UI session`, { sessionId });
Logger.debug('Add editor-UI session', { sessionId });

if (this.connections[sessionId] !== undefined) {
// Make sure to remove existing connection with the same session
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ class App {
const parameters = toHttpNodeParameters(curlCommand);
return ResponseHelper.flattenObject(parameters, 'parameters');
} catch (e) {
throw new ResponseHelper.BadRequestError(`Invalid cURL command`);
throw new ResponseHelper.BadRequestError('Invalid cURL command');
}
},
),
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/TestWebhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import * as Push from '@/Push';
import * as ResponseHelper from '@/ResponseHelper';
import * as WebhookHelpers from '@/WebhookHelpers';

const WEBHOOK_TEST_UNREGISTERED_HINT = `Click the 'Execute workflow' button on the canvas, then try again. (In test mode, the webhook only works for one call after you click this button)`;
const WEBHOOK_TEST_UNREGISTERED_HINT =
"Click the 'Execute workflow' button on the canvas, then try again. (In test mode, the webhook only works for one call after you click this button)";

export class TestWebhooks {
private testWebhookData: {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/UserManagement/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function usersNamespace(this: N8nApp): void {
const usersToSetUp = Object.keys(createUsers).filter((email) => createUsers[email] === null);
const total = usersToSetUp.length;

Logger.debug(total > 1 ? `Creating ${total} user shells...` : `Creating 1 user shell...`);
Logger.debug(total > 1 ? `Creating ${total} user shells...` : 'Creating 1 user shell...');

try {
await Db.transaction(async (transactionManager) => {
Expand Down Expand Up @@ -156,7 +156,7 @@ export function usersNamespace(this: N8nApp): void {
}

Logger.info('Created user shell(s) successfully', { userId: req.user.id });
Logger.verbose(total > 1 ? `${total} user shells created` : `1 user shell created`, {
Logger.verbose(total > 1 ? `${total} user shells created` : '1 user shell created', {
userShells: createUsers,
});

Expand Down Expand Up @@ -200,7 +200,7 @@ export function usersNamespace(this: N8nApp): void {
domain: baseUrl,
email,
});
resp.error = `Email could not be sent`;
resp.error = 'Email could not be sent';
}
return resp;
}),
Expand All @@ -211,7 +211,7 @@ export function usersNamespace(this: N8nApp): void {
Logger.debug(
usersPendingSetup.length > 1
? `Sent ${usersPendingSetup.length} invite emails successfully`
: `Sent 1 invite email successfully`,
: 'Sent 1 invite email successfully',
{ userShells: createUsers },
);

Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function executeErrorWorkflow(
workflowData.settings.errorWorkflow.toString() === workflowData.id.toString()
)
) {
Logger.verbose(`Start external error workflow`, {
Logger.verbose('Start external error workflow', {
executionId,
errorWorkflowId: workflowData.settings.errorWorkflow.toString(),
workflowId: workflowData.id,
Expand Down Expand Up @@ -177,7 +177,7 @@ export function executeErrorWorkflow(
workflowData.id !== undefined &&
workflowData.nodes.some((node) => node.type === ERROR_TRIGGER_TYPE)
) {
Logger.verbose(`Start internal error workflow`, { executionId, workflowId: workflowData.id });
Logger.verbose('Start internal error workflow', { executionId, workflowId: workflowData.id });
void getWorkflowOwner(workflowData.id).then((user) => {
void WorkflowHelpers.executeErrorWorkflow(
workflowData.id!.toString(),
Expand Down Expand Up @@ -293,7 +293,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
],
workflowExecuteBefore: [
async function (this: WorkflowHooks): Promise<void> {
Logger.debug(`Executing hook (hookFunctionsPush)`, {
Logger.debug('Executing hook (hookFunctionsPush)', {
executionId: this.executionId,
sessionId: this.sessionId,
workflowId: this.workflowData.id,
Expand Down Expand Up @@ -324,7 +324,7 @@ function hookFunctionsPush(): IWorkflowExecuteHooks {
fullRunData: IRun,
newStaticData: IDataObject,
): Promise<void> {
Logger.debug(`Executing hook (hookFunctionsPush)`, {
Logger.debug('Executing hook (hookFunctionsPush)', {
executionId: this.executionId,
sessionId: this.sessionId,
workflowId: this.workflowData.id,
Expand Down Expand Up @@ -490,7 +490,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
fullRunData: IRun,
newStaticData: IDataObject,
): Promise<void> {
Logger.debug(`Executing hook (hookFunctionsSave)`, {
Logger.debug('Executing hook (hookFunctionsSave)', {
executionId: this.executionId,
workflowId: this.workflowData.id,
});
Expand Down Expand Up @@ -830,7 +830,7 @@ export async function getWorkflowData(
): Promise<IWorkflowBase> {
if (workflowInfo.id === undefined && workflowInfo.code === undefined) {
throw new Error(
`No information about the workflow to execute found. Please provide either the "id" or "code"!`,
'No information about the workflow to execute found. Please provide either the "id" or "code"!',
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/e2e.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const setupUserManagement = async () => {
`INSERT INTO user (id, globalRoleId) values ("${uuid()}", ${instanceOwnerRole[0].insertId})`,
);
await connection.query(
`INSERT INTO "settings" (key, value, loadOnStartup) values ('userManagement.isInstanceOwnerSetUp', 'false', true), ('userManagement.skipInstanceOwnerSetup', 'false', true)`,
"INSERT INTO \"settings\" (key, value, loadOnStartup) values ('userManagement.isInstanceOwnerSetUp', 'false', true), ('userManagement.skipInstanceOwnerSetup', 'false', true)",
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/db/revert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DbRevertMigrationCommand extends Command {
connection = Db.collections.Credentials.manager.connection;

if (!connection) {
throw new Error(`No database connection available.`);
throw new Error('No database connection available.');
}

const connectionOptions: ConnectionOptions = Object.assign(connection.options, {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { findCliWorkflowStart } from '@/utils';
export class Execute extends Command {
static description = '\nExecutes a given workflow';

static examples = [`$ n8n execute --id=5`, `$ n8n execute --file=workflow.json`];
static examples = ['$ n8n execute --id=5', '$ n8n execute --file=workflow.json'];

static flags = {
help: flags.help({ char: 'h' }),
Expand Down Expand Up @@ -59,12 +59,12 @@ export class Execute extends Command {
const loadNodesAndCredentialsPromise = loadNodesAndCredentials.init();

if (!flags.id && !flags.file) {
console.info(`Either option "--id" or "--file" have to be set!`);
console.info('Either option "--id" or "--file" have to be set!');
return;
}

if (flags.id && flags.file) {
console.info(`Either "id" or "file" can be set never both!`);
console.info('Either "id" or "file" can be set never both!');
return;
}

Expand Down
28 changes: 14 additions & 14 deletions packages/cli/src/commands/executeBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export class ExecuteBatch extends Command {
static instanceOwner: User;

static examples = [
`$ n8n executeBatch`,
`$ n8n executeBatch --concurrency=10 --skipList=/data/skipList.txt`,
`$ n8n executeBatch --debug --output=/data/output.json`,
`$ n8n executeBatch --ids=10,13,15 --shortOutput`,
`$ n8n executeBatch --snapshot=/data/snapshots --shallow`,
`$ n8n executeBatch --compare=/data/previousExecutionData --retries=2`,
'$ n8n executeBatch',
'$ n8n executeBatch --concurrency=10 --skipList=/data/skipList.txt',
'$ n8n executeBatch --debug --output=/data/output.json',
'$ n8n executeBatch --ids=10,13,15 --shortOutput',
'$ n8n executeBatch --snapshot=/data/snapshots --shallow',
'$ n8n executeBatch --compare=/data/previousExecutionData --retries=2',
];

static flags = {
Expand Down Expand Up @@ -205,11 +205,11 @@ export class ExecuteBatch extends Command {
if (flags.snapshot !== undefined) {
if (fs.existsSync(flags.snapshot)) {
if (!fs.lstatSync(flags.snapshot).isDirectory()) {
console.log(`The parameter --snapshot must be an existing directory`);
console.log('The parameter --snapshot must be an existing directory');
return;
}
} else {
console.log(`The parameter --snapshot must be an existing directory`);
console.log('The parameter --snapshot must be an existing directory');
return;
}

Expand All @@ -218,11 +218,11 @@ export class ExecuteBatch extends Command {
if (flags.compare !== undefined) {
if (fs.existsSync(flags.compare)) {
if (!fs.lstatSync(flags.compare).isDirectory()) {
console.log(`The parameter --compare must be an existing directory`);
console.log('The parameter --compare must be an existing directory');
return;
}
} else {
console.log(`The parameter --compare must be an existing directory`);
console.log('The parameter --compare must be an existing directory');
return;
}

Expand All @@ -232,7 +232,7 @@ export class ExecuteBatch extends Command {
if (flags.output !== undefined) {
if (fs.existsSync(flags.output)) {
if (fs.lstatSync(flags.output).isDirectory()) {
console.log(`The parameter --output must be a writable file`);
console.log('The parameter --output must be a writable file');
return;
}
}
Expand All @@ -251,7 +251,7 @@ export class ExecuteBatch extends Command {

if (matchedIds.length === 0) {
console.log(
`The parameter --ids must be a list of numeric IDs separated by a comma or a file with this content.`,
'The parameter --ids must be a list of numeric IDs separated by a comma or a file with this content.',
);
return;
}
Expand Down Expand Up @@ -294,11 +294,11 @@ export class ExecuteBatch extends Command {
const query = Db.collections.Workflow.createQueryBuilder('workflows');

if (ids.length > 0) {
query.andWhere(`workflows.id in (:...ids)`, { ids });
query.andWhere('workflows.id in (:...ids)', { ids });
}

if (skipIds.length > 0) {
query.andWhere(`workflows.id not in (:...skipIds)`, { skipIds });
query.andWhere('workflows.id not in (:...skipIds)', { skipIds });
}

// eslint-disable-next-line prefer-const
Expand Down
Loading