Files
n8n_Demo/n8n-n8n-1.109.2/packages/@n8n/eslint-config/src/rules/no-unused-param-catch-clause.ts
2025-09-08 04:48:28 +08:00

33 lines
786 B
TypeScript
Executable File

import { ESLintUtils } from '@typescript-eslint/utils';
export const NoUnusedParamInCatchClauseRule = ESLintUtils.RuleCreator.withoutDocs({
meta: {
type: 'problem',
docs: {
description: 'Unused param in catch clause must be omitted.',
},
messages: {
removeUnusedParam: 'Remove unused param in catch clause',
},
fixable: 'code',
schema: [],
},
defaultOptions: [],
create(context) {
return {
CatchClause(node) {
if (node.param?.type === 'Identifier' && 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]),
});
}
},
};
},
});