Skip to content
Esc

@noctcore/eslint-plugin-nestjs

v0.2.09 rules3 recommended6 opt-innamespace noctcore-nestjs

A bad fit for a codebase without BullMQ or @nestjs/schedule, and the queue rules need queuePattern tuned if your queues are not named like queues.

NestJS and BullMQ background work: queue jobs keyed against retries, shared queue and job names, schedules with a stated time zone.

The work a NestJS app hands to a queue or a schedule fails quietly. A producer that runs twice (a double submit, a replayed request, a sweep that restarts) enqueues the same job twice unless the job carries a key. A queue name typed differently in the producer and the worker routes jobs nowhere. A @Cron without a time zone runs at 03:00 in whatever zone the host has, which is not the zone you meant once the code leaves your laptop. A BullMQ worker that nobody listens to fails without a trace, and one that is never closed abandons its running jobs on every deploy.

It will yell at you about three things, all on in recommended: a @Cron or a BullMQ cron schedule that does not state its time zone, a BullMQ worker with no failed listener, and a class that creates a worker and never closes it on shutdown. The worker rules recognise Worker by its bullmq import, renamed or not. Four queue rules are opt-in: every queue.add carrying a jobId or deduplication, queue and job names coming from shared constants, every queued job stating attempts (and a backoff when it retries), in its options or its queue’s defaultJobOptions in the same file, and every queued job stating removeOnComplete and removeOnFail, in its options or its queue’s defaultJobOptions in the same file. All four find queues by receiver name (this.queue, emailQueue), with no type information. One more opt-in rule reports a literal worker concurrency that is 0 or below or not a whole number, on a new Worker from bullmq or in @Processor(queue, options), and with requireExplicit it also asks every worker to state one. One more rule is opt-in and needs options, every Redis client and every inline BullMQ connection taking its options from your factory (redis-client-from-factory, set factoryFunctions). It is a bad fit for a codebase without BullMQ or @nestjs/schedule, and the queue rules need queuePattern tuned if your queues are not named like queues.

Install
npm install --save-dev @noctcore/eslint-plugin-nestjs @typescript-eslint/parser
# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-nestjs @typescript-eslint/parser

The recommended preset enables 3 of 9 rules. The rules board below builds the flat config: start from a preset, switch single rules between error and off, and copy the result.

Each rule links to its page, with the options it takes and Incorrect and Correct examples. A good first read is schedule-states-time-zone.

3 of 9 at error

--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.

job-name-must-be-constant
Require queue and job names passed to @Processor(...), @InjectQueue(...) and <queue>.add(...) to be shared constants, not inline string literals.
opt-in
job-options-must-set-attempts
Require every BullMQ .add / .addBulk job to state attempts, and a backoff when it retries, in its options or its queue's defaultJobOptions.
opt-in
queue-add-requires-dedup-key
Require every BullMQ .add / .addBulk job to carry a jobId or deduplication in literal options, so a producer retry cannot enqueue the same work twice.
opt-in
queue-options-must-set-retention
Require every BullMQ .add job to state removeOnComplete and removeOnFail in its options or its queue's defaultJobOptions, so finished jobs do not pile up in Redis.
opt-in
redis-client-from-factory
Require every Redis client and every inline BullMQ connection to take its options from a configured factory function, not from literal host, port or URL values.
Needs options
opt-in
schedule-states-time-zone
Require a @Cron to state timeZone (or utcOffset) and a BullMQ cron schedule to state tz, so it does not run in whatever zone the host has.
recommended
worker-concurrency
Require a literal BullMQ worker concurrency, on new Worker(...) or @Processor(queue, options), to be a positive integer, and with requireExplicit require it to be stated.
opt-in
worker-must-implement-close
Require a class that creates a BullMQ Worker in a field to call .close() on it in a shutdown method such as onModuleDestroy, so in-flight jobs are not abandoned.
recommended
worker-must-listen-failed
Require every BullMQ new Worker(...) to have a .on('failed', ...) listener in the same file, so a failing job is not silent.
recommended