mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
build: Update ESLint to v9 (#16639)
This commit is contained in:
49
packages/@n8n/eslint-config/src/rules/no-plain-errors.ts
Normal file
49
packages/@n8n/eslint-config/src/rules/no-plain-errors.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
||||
|
||||
export const NoPlainErrorsRule = ESLintUtils.RuleCreator.withoutDocs({
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description:
|
||||
'Only `ApplicationError` (from the `workflow` package) or its child classes must be thrown. This ensures the error will be normalized when reported to Sentry, if applicable.',
|
||||
},
|
||||
messages: {
|
||||
useApplicationError:
|
||||
'Throw an `ApplicationError` (from the `workflow` package) or its child classes.',
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
return {
|
||||
ThrowStatement(node) {
|
||||
if (!node.argument) return;
|
||||
|
||||
const isNewError =
|
||||
node.argument.type === TSESTree.AST_NODE_TYPES.NewExpression &&
|
||||
node.argument.callee.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
||||
node.argument.callee.name === 'Error';
|
||||
|
||||
const isNewlessError =
|
||||
node.argument.type === TSESTree.AST_NODE_TYPES.CallExpression &&
|
||||
node.argument.callee.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
||||
node.argument.callee.name === 'Error';
|
||||
|
||||
if (isNewError || isNewlessError) {
|
||||
return context.report({
|
||||
messageId: 'useApplicationError',
|
||||
node,
|
||||
fix: (fixer) =>
|
||||
fixer.replaceText(
|
||||
node,
|
||||
`throw new ApplicationError(${(node.argument as TSESTree.CallExpression).arguments
|
||||
.map((arg) => context.sourceCode.getText(arg))
|
||||
.join(', ')})`,
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user