Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ci: Introduce lint rule no-type-unsafe-event-emitter (no-changelog) #10254

Merged
merged 2 commits into from
Aug 2, 2024
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
30 changes: 30 additions & 0 deletions packages/@n8n_io/eslint-config/local-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,36 @@ module.exports = {
};
},
},

'no-type-unsafe-event-emitter': {
meta: {
type: 'problem',
docs: {
description: 'Disallow extending from `EventEmitter`, which is not type-safe.',
recommended: 'error',
},
messages: {
noExtendsEventEmitter: 'Extend from the type-safe `TypedEmitter` class instead.',
},
},
create(context) {
return {
ClassDeclaration(node) {
if (
node.superClass &&
node.superClass.type === 'Identifier' &&
node.superClass.name === 'EventEmitter' &&
node.id.name !== 'TypedEmitter'
) {
context.report({
node: node.superClass,
messageId: 'noExtendsEventEmitter',
});
}
},
};
},
},
};

const isJsonParseCall = (node) =>
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
rules: {
'n8n-local-rules/no-dynamic-import-template': 'error',
'n8n-local-rules/misplaced-n8n-typeorm-import': 'error',
'n8n-local-rules/no-type-unsafe-event-emitter': 'error',
complexity: 'error',

// TODO: Remove this
Expand All @@ -44,6 +45,12 @@ module.exports = {
'n8n-local-rules/misplaced-n8n-typeorm-import': 'off',
},
},
{
files: ['./test/**/*.ts'],
rules: {
'n8n-local-rules/no-type-unsafe-event-emitter': 'off',
},
},
{
files: ['./src/decorators/**/*.ts'],
rules: {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/eventbus/MessageEventBus/MessageEventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface MessageEventBusInitializeOptions {
}

@Service()
// TODO: Convert to TypedEventEmitter
// eslint-disable-next-line n8n-local-rules/no-type-unsafe-event-emitter
export class MessageEventBus extends EventEmitter {
private isInitialized = false;

Expand Down
Loading