The @nx/directive-checks lint rule checks the @nx- directives in the comment block that opens a file:
@nx-depends-onand@nx-ignore-server-inputsscope the task of a split end-to-end (e2e) test file to the code the test exercises. To learn how to use them, see skip unaffected split e2e tests.@nx-target-namenames the task of a script that the@nx/js/nodeor@nx/js/tsxplugin runs.
When Nx can't read a directive, it ignores it silently or with a warning that's easy to miss. An ignored @nx-depends-on or @nx-ignore-server-inputs leaves the test's task unscoped, so the test reruns on every change to the app.
Enable the rule
Section titled “Enable the rule”The rule isn't in the shared configs that @nx/eslint-plugin exports, and generators don't add it. Add it to the root lint config that project configs extend. For ESLint, that's eslint.base.config.mjs when the workspace has one, and eslint.config.mjs otherwise:
import nx from '@nx/eslint-plugin';
export default [ ...nx.configs['flat/base'], // ... other config { rules: { '@nx/directive-checks': 'error', }, },];{ "jsPlugins": ["@nx/oxlint/boundaries-plugin"], "rules": { "@nx/directive-checks": "error" }}On Oxlint, the rule comes from the same JavaScript plugin as @nx/enforce-module-boundaries. For how Nx runs Oxlint, see Nx with Oxlint.
The entry has no files pattern, so the rule runs on every file the config already lints, whatever its extension. A files pattern would make ESLint lint files that match it, even ones the config sets no parser for. The rule reads the project graph only for files whose opening comments contain @nx-depends-on or @nx-ignore-server-inputs.
When you update Nx with nx migrate, a migration in @nx/eslint adds the rule to the root ESLint config that project configs extend. It does so when a split test file already has @nx-depends-on or @nx-ignore-server-inputs and no ESLint config mentions the rule yet. The config must also register the @nx plugin for every file, as the configs Nx generates do. When the migration can't verify that, it prints a warning instead. Add the rule to a config that registers @nx for the files it checks.
Checks in every file
Section titled “Checks in every file”Nx reads directives only from the comment block that opens a file, before the first line of code. Blank lines, a #! line, and other comments can come first.
Unknown directive names
Section titled “Unknown directive names”The rule reports a comment line shaped like a directive, @nx-<name> alone or followed by a colon, when Nx doesn't read that name. If the name is close to a directive Nx reads, the message suggests it:
// @nx-depend-on: checkout// @nx-depends-on: checkoutThe rule reports "@nx-depend-on" is not a directive Nx reads, so Nx ignores it. Did you mean "@nx-depends-on"?
A line with more text after the name and no colon, such as // @nx-todo check the flaky step, isn't shaped like a directive, so the rule doesn't report it. After the first line of code, the rule reports an unknown name only when it can suggest a directive. A misspelled // @nx-depend-on: checkout after an import is reported, and // @nx-flaky isn't.
Directives Nx can't read
Section titled “Directives Nx can't read”The rule reports a known directive that Nx can't parse, such as @nx-depends-on without its colon or @nx-ignore-server-inputs followed by a note:
// @nx-depends-on checkout// @nx-ignore-server-inputs // runs against the staging API// @nx-depends-on: checkout// @nx-ignore-server-inputs// Runs against the staging API.The message names the form Nx reads, such as Write it as "@nx-depends-on: <project>, <project>".
The rule also reports a directive in a comment after code, such as after an import or a 'use strict' line. It also reports a directive on the line where a block comment ends and code follows the */. Move the directive above the first line of code:
// @nx-depends-on: checkoutimport { expect, test } from '@playwright/test';// @nx-depends-on: checkoutValues Nx ignores
Section titled “Values Nx ignores”The rule reports a directive whose value Nx ignores:
| Reported line | Why Nx ignores it | Fix |
|---|---|---|
// @nx-depends-on: | It lists no projects. | List the projects the test depends on, separated by commas. |
// @nx-ignore-server-inputs: true | The directive takes no value. | Write // @nx-ignore-server-inputs alone. |
// @nx-target-name: | The task name is empty. | Write the task name after the colon. |
A second // @nx-target-name: start after @nx-target-name: serve | Nx reads only the first @nx-target-name. | Remove the extra line. |
Nx merges every @nx-depends-on line, so the rule reports empty @nx-depends-on lines only when none of the lines in the file lists a project.
Checks in split test files
Section titled “Checks in split test files”These checks run on a test file that a split task runs. The checks read the cached project graph. A plugin can record on each split task the test file it runs and the directives it applies. The Playwright, Cypress e2e, Jest, and Vitest plugins record them with applyTestFileDirectives from @nx/devkit/internal, which other plugins can also call. When no split task records the file, the rule looks for a split task that records no file and whose name is <target>--<file path>, such as test-ci--src/checkout.spec.ts. Cypress component test split tasks record nothing, so the rule finds them this way. A name can also end with another file's path, so the rule can check a file that no split task runs.
Directives the test runner ignores
Section titled “Directives the test runner ignores”Nx applies both directives to Playwright and Cypress e2e split tasks, and only @nx-depends-on to Jest and Vitest split tasks. It applies neither to Cypress component test split tasks. The rule reports a directive that the file's split task doesn't record as applied.
For a Jest or Vitest test file, list the projects the test exercises instead:
// @nx-ignore-server-inputs// @nx-depends-on: checkoutThe rule reports No split task that runs this file applies "@nx-ignore-server-inputs", so Nx ignores it. For a Cypress component test file, remove the directive.
When several split tasks run the same file, the rule reports a directive only if none of them records it. It then doesn't report the directive's value, since Nx ignores the whole directive.
Project patterns that match no project
Section titled “Project patterns that match no project”The rule matches each @nx-depends-on pattern against the project graph the way Nx does when it hashes the task. A pattern can be an exact project name, a name with a name:, tag:, or directory: prefix, or a glob such as shop-*. A pattern that matches no project makes every Nx command that includes the task fail, unless it's an exclusion such as !shop-legacy. A target default or project.json entry that replaces the task's inputs without "..." drops the inputs that the plugin added for @nx-depends-on. Nx then doesn't check the patterns, so an unmatched pattern fails no command. The rule still reports it, because the pattern fails commands once the entry keeps "...".
When a project name is close, the message suggests it, such as the full name @acme/shop-ui for shop-ui:
// @nx-depends-on: shop-ui// @nx-depends-on: @acme/shop-uiThe rule reports "shop-ui" matches no project. Did you mean "@acme/shop-ui"?
Limits
Section titled “Limits”- Without a cached project graph, the rule prints a warning and runs only the checks in every file.
- The rule reads the project graph that Nx cached last. A pattern that names a project created after that reads as matching no project until Nx updates the cache.
- When the rule matches split tasks to the file and none of them records a directive as applied, it reports the directive as ignored, even when a plugin applies it.
- For a split task that records no test file, the rule goes by the task name, which can end with another file's path. For example, the Cypress component test task
component-test-ci--checkout--unit.cy.tsrunscheckout--unit.cy.ts, but its name also ends withunit.cy.ts. The rule then reports a test directive inunit.cy.tsas ignored. Nx does ignore it there, since no split task runs that file. - A lint task's hash covers the e2e project and the projects it depends on. The rule also reads other projects, such as an API that
@nx-depends-onnames but the e2e project doesn't depend on. After a rename of that project,nx lintcan replay a cached clean result.nx affected -t lintdoesn't run the e2e project's lint task at all. To check again, run the lint task with--skip-nx-cache. The e2e task still fails before it runs, with an error that names the pattern.