From 62751b5a0b804a718b877d88cf99293c2b4ca250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 31 Mar 2023 16:44:08 +0200 Subject: [PATCH] refactor: Add lint rule `no-unused-param-in-catch-clause` (#5868) :shirt: Add lint rule `no-unused-param-in-catch-clause` --- packages/@n8n_io/eslint-config/base.js | 2 ++ packages/@n8n_io/eslint-config/local-rules.js | 30 +++++++++++++++++++ packages/cli/src/CommunityNodes/helpers.ts | 2 +- .../nodes/Github/SearchFunctions.ts | 2 +- .../src/Extensions/StringExtensions.ts | 2 +- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/@n8n_io/eslint-config/base.js b/packages/@n8n_io/eslint-config/base.js index cadc748b5c..2f673ece0b 100644 --- a/packages/@n8n_io/eslint-config/base.js +++ b/packages/@n8n_io/eslint-config/base.js @@ -343,6 +343,8 @@ const config = (module.exports = { 'n8n-local-rules/no-interpolation-in-regular-string': 'error', + 'n8n-local-rules/no-unused-param-in-catch-clause': 'error', + // ****************************************************************** // overrides to base ruleset // ****************************************************************** diff --git a/packages/@n8n_io/eslint-config/local-rules.js b/packages/@n8n_io/eslint-config/local-rules.js index 9b4677c1c0..41af48f7f9 100644 --- a/packages/@n8n_io/eslint-config/local-rules.js +++ b/packages/@n8n_io/eslint-config/local-rules.js @@ -140,6 +140,36 @@ module.exports = { }, }, + 'no-unused-param-in-catch-clause': { + meta: { + type: 'problem', + docs: { + description: 'Unused param in catch clause must be omitted.', + recommended: 'error', + }, + messages: { + removeUnusedParam: 'Remove unused param in catch clause', + }, + fixable: 'code', + }, + create(context) { + return { + CatchClause(node) { + if (node.param?.name.startsWith('_')) { + const start = node.range[0] + 'catch '.length; + const end = node.param.range[1] + '()'.length; + + context.report({ + messageId: 'removeUnusedParam', + node, + fix: (fixer) => fixer.removeRange([start, end]), + }); + } + }, + }; + }, + }, + 'no-interpolation-in-regular-string': { meta: { type: 'problem', diff --git a/packages/cli/src/CommunityNodes/helpers.ts b/packages/cli/src/CommunityNodes/helpers.ts index 6cbe4134c4..328a3f6a32 100644 --- a/packages/cli/src/CommunityNodes/helpers.ts +++ b/packages/cli/src/CommunityNodes/helpers.ts @@ -216,7 +216,7 @@ export function removePackageFromMissingList(packageName: string): void { ); config.set('nodes.packagesMissing', packageFailedToLoad.join(' ')); - } catch (_error) { + } catch { // Do nothing } } diff --git a/packages/nodes-base/nodes/Github/SearchFunctions.ts b/packages/nodes-base/nodes/Github/SearchFunctions.ts index 79da3bd05b..4d2b34a154 100644 --- a/packages/nodes-base/nodes/Github/SearchFunctions.ts +++ b/packages/nodes-base/nodes/Github/SearchFunctions.ts @@ -72,7 +72,7 @@ export async function getRepositories( {}, { q, page, per_page }, ); - } catch (_error) { + } catch { // will fail if the owner does not have any repositories } diff --git a/packages/workflow/src/Extensions/StringExtensions.ts b/packages/workflow/src/Extensions/StringExtensions.ts index ea0acea8da..fb79704094 100644 --- a/packages/workflow/src/Extensions/StringExtensions.ts +++ b/packages/workflow/src/Extensions/StringExtensions.ts @@ -185,7 +185,7 @@ function isUrl(value: string) { let url: URL; try { url = new URL(value); - } catch (_error) { + } catch { return false; }