@noctcore/eslint-plugin-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.
What it solves
Section titled “What it solves”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.
What it will yell at you about
Section titled “What it will yell at you about”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 and configure
Section titled “Install and configure”npm install --save-dev @noctcore/eslint-plugin-nestjs @typescript-eslint/parser# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-nestjs @typescript-eslint/parserThe 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.
--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.
@Processor(...), @InjectQueue(...) and <queue>.add(...) to be shared constants, not inline string literals..add / .addBulk job to state attempts, and a backoff when it retries, in its options or its queue's defaultJobOptions..add / .addBulk job to carry a jobId or deduplication in literal options, so a producer retry cannot enqueue the same work twice..add job to state removeOnComplete and removeOnFail in its options or its queue's defaultJobOptions, so finished jobs do not pile up in Redis.connection to take its options from a configured factory function, not from literal host, port or URL values.@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.concurrency, on new Worker(...) or @Processor(queue, options), to be a positive integer, and with requireExplicit require it to be stated.Worker in a field to call .close() on it in a shutdown method such as onModuleDestroy, so in-flight jobs are not abandoned.new Worker(...) to have a .on('failed', ...) listener in the same file, so a failing job is not silent.