Title: `rs lint -c
Open Graph Title: `rs lint -c
X Title: `rs lint -c
Description: When rs lint -c
Open Graph Description: When rs lint -c
X Description: When rs lint -c <path> points to a file other than the rstack.config.* that would be found in the cwd (a config in another directory, or one with another name such as -c lint.config.mjs), rul...
Opengraph URL: https://github.com/rstackjs/rstack-cli/issues/591
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`rs lint -c \u003cpath>`: JS plugin rules load the config from cwd in Rslint workers","articleBody":"When `rs lint -c \u003cpath>` points to a file other than the `rstack.config.*` that would be found in the cwd (a config in another directory, or one with another name such as `-c lint.config.mjs`), rules from object-form JS plugins (`plugins: { kw: { rules: { ... } } }`) are not loaded from the `-c` file. Rslint's plugin worker threads re-import Rstack's internal Rslint config module, and that module does not know the `-c` path inside a worker, so it looks for `rstack.config.*` in the current working directory instead. Depending on what the cwd contains, the run fails during worker init, silently runs a rule implementation from another config, or reports `rule not found in any loaded plugin`. Configs that only use built-in rules are not affected.\n\n## Environment\n\n- rstack 0.8.5 with @rslint/core 0.9.5, Node 22.23.3 and 24.21.0, Linux x64\n- Same output on rstack 0.8.3 (Node 22.23.3) and on a build of `main` at 5fe9881 (Node 22.23.3 and 24.21.0)\n- Using a build of current Rslint `main` in place of @rslint/core 0.9.5 does not change the result\n\n## Reproduction\n\n```\n.\n├── package.json\n└── proj\n ├── rstack.config.mjs\n └── src\n └── index.js\n```\n\n`package.json`\n\n```json\n{\n \"private\": true,\n \"type\": \"module\",\n \"devDependencies\": {\n \"rstack\": \"0.8.5\"\n }\n}\n```\n\n`proj/rstack.config.mjs`\n\n```js\nimport { define } from 'rstack';\n\nconst noFoo = {\n meta: { type: 'problem', schema: [], messages: { foo: 'foo is not allowed' } },\n create(context) {\n return {\n Identifier(node) {\n if (node.name === 'foo') context.report({ node, messageId: 'foo' });\n },\n };\n },\n};\n\ndefine.lint([\n {\n files: ['**/*.js'],\n plugins: { kw: { rules: { 'no-foo': noFoo } } },\n rules: { 'kw/no-foo': 'error' },\n },\n]);\n```\n\n`proj/src/index.js`\n\n```js\nexport const foo = 1;\n```\n\n```sh\nnpm install\n(cd proj && npx rs lint) # kw/no-foo at src/index.js:1:14, exit 1 (correct)\nnpx rs lint -c proj/rstack.config.mjs proj/src # run from the root\n```\n\nActual output of the last command (exit 1):\n\n```\nstart Linting...\n[rslint:plugin] error No lint configuration found. Add define.lint(...) to your Rstack config file.\n\n[rslint:plugin] error No lint configuration found. Add define.lint(...) to your Rstack config file.\n\nerror Linting failed in 108ms: worker exited during init (code=1) before sending ready\n```\n\nExpected (exit 1):\n\n```\nstart Linting...\n\n kw/no-foo — [error] foo is not allowed\n ╭─┴──────────( proj/src/index.js:1:14 )─────\n │ 1 │ export const foo = 1;\n │ 2 │ \n ╰────────────────────────────────\n\nerror Lint failed with 1 error in 195ms (1 file, 1 rule, 32 threads)\n```\n\nThe same failure occurs without changing directory when the config has another name: rename `proj/rstack.config.mjs` to `proj/lint.config.mjs` and run `npx rs lint -c lint.config.mjs src` in `proj/`.\n\n`--type-check` and `--type-check-only` fail the same way. So does the lint phase of `rs check -c proj/rstack.config.mjs proj/src`; its format check then passes, and the command exits 1. The error is printed twice because Rslint starts up to two warm-up workers ([worker-pool.ts#L268-L269][rl-warmup]).\n\nPlain `rslint -c proj/rslint.config.mjs proj/src`, using the same plugin in an `rslint.config.mjs`, reports the expected finding from the root, even when the root has a conflicting `rslint.config.mjs` of its own.\n\n### When the cwd has a different `rstack.config.mjs`\n\nAdd `rstack.config.mjs` in the root:\n\n```js\nimport { define } from 'rstack';\n\nconst other = {\n meta: { type: 'problem', schema: [], messages: { other: 'reported by ./rstack.config.mjs' } },\n create(context) {\n return {\n Program(node) {\n context.report({ node, messageId: 'other' });\n },\n };\n },\n};\n\ndefine.lint([\n {\n files: ['**/*.js'],\n plugins: { kw: { rules: { 'no-foo': other } } },\n rules: { 'kw/no-foo': 'warn' },\n },\n]);\n```\n\n`npx rs lint -c proj/rstack.config.mjs proj/src` now gets past worker init but runs the root config's implementation (exit 1):\n\n```\nstart Linting...\n\n kw/no-foo — [error] reported by ./rstack.config.mjs\n ╭─┴──────────( proj/src/index.js:1:1 )─────\n │ 1 │ export const foo = 1;\n │ 2 │ \n ╰────────────────────────────────\n\nerror Lint failed with 1 error in 107ms (1 file, 1 rule, 32 threads)\n```\n\nThe severity (`error`) comes from the `-c` file, while the rule implementation comes from the cwd config (which sets `warn`). If the cwd config does not define `kw/no-foo`, for example `define.lint([{ rules: { 'no-debugger': 'error' } }])`, each file reports `kw/no-foo — [error] rule error: rule not found in any loaded plugin` instead.\n\n## Cause\n\n1. `setupCommands` removes `-c` (via `parseCliArgs`) and stores the resolved path in `globalThis.__rstackCliState` ([commands.ts#L216-L225][rc-setup], [config.ts#L133-L141][rc-state]).\n2. `runRslintCLI` passes the internal `dist/rslintConfig.js` to Rslint as `--config`, not the user's file ([commands.ts#L149-L160][rc-argv]). `rs check` goes through the same function ([#L185-L189][rc-check]).\n3. `rslintConfig.ts` calls `loadRstackConfig()` with no arguments at module top level and calls `process.exit(1)` when no lint config is found ([rslintConfig.ts#L10-L19][rc-shim-load]). `loadRstackConfig()` uses `configFilePath ?? state.configPath` and otherwise searches the cwd for `rstack.config.*` ([config.ts#L264-L287][rc-loader]).\n4. For object-form plugins, Rslint sends the `--config` path to each plugin worker in `workerData`, and the worker re-imports that file to get the live plugin objects ([worker-pool.ts#L717-L738][rl-spawn], [plugin-loader.ts#L335][rl-load], [define-config.ts#L247-L251][rl-doc]). A `worker_threads` worker has its own `globalThis`, so `__rstackCliState` is empty there, and the module falls back to the cwd. The main thread still loads the `-c` file, which is why the rule list and severities are correct while the implementations are not.\n\nIn a worker, this does not match the documented behavior of `loadRstackConfig()`: \"If omitted, the loader uses the path specified by the CLI's `--config` option\" ([api-reference.mdx#L123][rc-docs-api]).\n\n## Fix\n\nI will open a PR for this part only. Before starting Rslint, `rs lint` and `rs check` write the resolved `-c` path to a `RSTACK_CLI_CONFIG_PATH` environment variable, and the internal lint config passes it to `loadRstackConfig()`. Rslint creates its workers without an `env` option ([worker-pool.ts#L717-L738][rl-spawn]), so they inherit the variable. Without `-c`, the variable is removed, so an inherited value is ignored.\n\n## Related: paths in a `-c` config resolve from the cwd\n\nThis is a separate point, and the current behavior may be intended, so it is a question rather than part of the bug above. The PR does not change it.\n\n`rslintConfig.ts` uses `process.cwd()` as the default `basePath` of every entry. The code comment there says this preserves \"the historical behavior of resolving user-authored paths from the invocation directory\" (#431, [rslintConfig.ts#L21-L30][rc-shim-base]). The implicit tsconfig lookup uses the same base ([#L39-L50][rc-shim-tsconfig]). When `-c` points into another directory, `files`, `ignores` and the tsconfig lookup therefore resolve from the cwd. Plain `rslint -c` resolves relative paths from the config file's directory when an entry has no `basePath` ([base-path.md#L33-L36][rl-basepath]), and `rs fmt -c` uses the config file's directory as its root ([fmt/config.ts#L161][rc-fmt]).\n\nWith type checking, this gives a silent pass. Fixture in the same root (built-in rules only, so the worker bug is not involved):\n\n`typed/rstack.config.mjs`\n\n```js\nimport { define } from 'rstack';\n\ndefine.lint([{ rules: { 'no-debugger': 'error' } }]);\n```\n\n`typed/tsconfig.json`\n\n```json\n{\n \"compilerOptions\": { \"strict\": true, \"noEmit\": true },\n \"include\": [\"src\"]\n}\n```\n\n`typed/src/index.ts`\n\n```ts\nexport const n: number = 'a';\n```\n\n```sh\n(cd typed && npx rs lint --type-check-only) # TS2322 at src/index.ts:1:14, exit 1\nnpx rs lint -c typed/rstack.config.mjs --type-check-only typed/src # run from the root\n```\n\nOutput of the last command (exit 0):\n\n```\nstart Type checking...\nsuccess No files to type check in 37ms\n```\n\n`files` and `ignores` behave the same way. With `app/rstack.config.mjs` set to `define.lint([{ files: ['src/**/*.js'], rules: { 'no-debugger': 'error' } }])` and `debugger;` in `app/src/a.js`, `npx rs lint -c app/rstack.config.mjs app/src` from the root prints `Lint passed ... (1 file, 0 rules, ...)` and exits 0. With `{ ignores: ['src/ignored/**'] }` instead, files in `app/src/ignored/` are still linted.\n\nWorkaround: set `basePath: import.meta.dirname` on each entry. That fixes `files` and `ignores`, but not the type-check case, because the implicit tsconfig lookup always uses the cwd. For type checking, also set `languageOptions: { parserOptions: { project: ['./tsconfig.json'] } }` on an entry that has that `basePath`.\n\nShould these paths resolve from the `-c` file's directory instead? When the config is discovered rather than passed with `-c`, that directory is the cwd, so only `-c` runs would change. On the other hand, resolving from the cwd fits a config kept in `./configs/` and run from the project root, as in the [`-c` docs example][rc-docs-c]. If the cwd is the intended base, a note in those docs would help.\n\n[rc-setup]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/cli/commands.ts#L216-L225\n[rc-state]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/config.ts#L133-L141\n[rc-argv]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/cli/commands.ts#L149-L160\n[rc-check]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/cli/commands.ts#L185-L189\n[rc-shim-load]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/rslintConfig.ts#L10-L19\n[rc-loader]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/config.ts#L264-L287\n[rc-shim-base]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/rslintConfig.ts#L21-L30\n[rc-shim-tsconfig]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/rslintConfig.ts#L39-L50\n[rc-fmt]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/packages/rstack/src/fmt/config.ts#L161\n[rc-docs-api]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/website/docs/en/guide/api-reference.mdx?plain=1#L123\n[rc-docs-c]: https://github.com/rstackjs/rstack-cli/blob/5fe988168bd0dbf4de19eb86fd3eafcc8a0607df/website/docs/en/guide/configuration.mdx?plain=1#L45-L49\n[rl-warmup]: https://github.com/web-infra-dev/rslint/blob/8ef7d5ad24566a0f7fa87f4bc395fd9ec6f5fe4a/packages/rslint/src/eslint-plugin/worker-pool.ts#L268-L269\n[rl-spawn]: https://github.com/web-infra-dev/rslint/blob/8ef7d5ad24566a0f7fa87f4bc395fd9ec6f5fe4a/packages/rslint/src/eslint-plugin/worker-pool.ts#L717-L738\n[rl-load]: https://github.com/web-infra-dev/rslint/blob/8ef7d5ad24566a0f7fa87f4bc395fd9ec6f5fe4a/packages/rslint/src/eslint-plugin/plugin/plugin-loader.ts#L335\n[rl-doc]: https://github.com/web-infra-dev/rslint/blob/8ef7d5ad24566a0f7fa87f4bc395fd9ec6f5fe4a/packages/rslint/src/config/define-config.ts#L247-L251\n[rl-basepath]: https://github.com/web-infra-dev/rslint/blob/8ef7d5ad24566a0f7fa87f4bc395fd9ec6f5fe4a/website/docs/en/config/base-path.md?plain=1#L33-L36\n","author":{"url":"https://github.com/LucasIcarus","@type":"Person","name":"LucasIcarus"},"datePublished":"2026-10-23T07:16:54Z","url":"https://github.com/rstackjs/rstack-cli/issues/591"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:637c547f-8224-3e62-5b83-400d07b1c2fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B58C:31F0B2:1FB335:2AFCC1:6AEC1B84 |
| html-safe-nonce | 0cba238670c5e1e28f2501e00a60c9f0dba0907900e8e1d97219afdce20b84e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNThDOjMxRjBCMjoxRkIzMzU6MkFGQ0MxOjZBRUMxQjg0IiwidmlzaXRvcl9pZCI6IjkxMTE5NjE2ODY1MDIwMjIwMjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1e10c1252438f080d7b26ef8835b690051f1489ab7078534cef10c3563620c93 |
| hovercard-subject-tag | issue:5993634582 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/rstackjs/rstack-cli/591/issue_layout |
| twitter:image | https://opengraph.githubassets.com/33e3fe4b853e14beadefc3ff5ae641c261b9612e031788bb6dec5019954ceeb4/rstackjs/rstack-cli/issues/591 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/33e3fe4b853e14beadefc3ff5ae641c261b9612e031788bb6dec5019954ceeb4/rstackjs/rstack-cli/issues/591 |
| og:image:alt | When rs lint -c |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LucasIcarus |
| hostname | github.com |
| expected-hostname | github.com |
| None | d063d52022f5f270ef55a70761d126c8085d492d3c251084b07781784c02dad4 |
| turbo-cache-control | no-preview |
| go-import | github.com/rstackjs/rstack-cli git https://github.com/rstackjs/rstack-cli.git |
| octolytics-dimension-user_id | 129049372 |
| octolytics-dimension-user_login | rstackjs |
| octolytics-dimension-repository_id | 1138027854 |
| octolytics-dimension-repository_nwo | rstackjs/rstack-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1138027854 |
| octolytics-dimension-repository_network_root_nwo | rstackjs/rstack-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56e59340194011ba3cb6809acfa979ccbd174288 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width