Skip to content

feat: add Node.js recommended presets - #2241

Merged
fansenze merged 7 commits into
mainfrom
feat/node-presets
Sep 22, 2026
Merged

fansenze merged 7 commits into
mainfrom
feat/node-presets

Conversation

@fansenze

@fansenze fansenze commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The native node/* rules currently require manual configuration. Add the three recommended Node.js presets to @rslint/core, including the language settings needed for their rules to work in ES modules and CommonJS.

Changes

  • Export nodePlugin.configs.recommended, nodePlugin.configs.recommendedModule, and nodePlugin.configs.recommendedScript, using camelCase keys for the corresponding presets in eslint-plugin-n@18.3.0.
  • Enable all 13 available recommended rules under the native node/* prefix. Preserve upstream globals access levels, sourceType, and the syntax rule's ignores options. The unimplemented process-exit-as-throw rule is explicitly documented and omitted.
  • Make recommended select the nearest valid working-directory package's type and apply .cjs/.mjs overrides, including dotfiles. Keep package lookup and globals loading lazy so importing the core root does not load environment assets.
  • Add integration coverage that triggers every enabled native rule and checks package lookup, globals, scopes, and option merging. Test that built presets lazily load only their two bundled globals assets. Correct the existing imported-globals test so config-load failures cannot pass as an empty diagnostic result.
  • Register the presets in the shared website preset table and import snippet. Add the preset API reference and source comments with links mapping recommended, recommendedModule, and recommendedScript to upstream recommended, recommended-module, and recommended-script. Fix three broken links in the Node publication-rule documentation exposed by the docs build.

The presets use core's bundled globals catalog: all 134 globals supplied by upstream retain their access levels, with seven additional globals from core's newer catalog. Auto selection uses process.cwd(), as upstream does, but runs when recommended is accessed instead of at import time. API cwd does not affect it; callers whose process directory differs from the lint project, or nested packages with different types, should use explicit presets. sourceType affects lint scopes, not TypeScript parsing.

Usage

import { defineConfig, nodePlugin } from '@rslint/core';

export default defineConfig([
  nodePlugin.configs.recommended,
  // Use one of these instead to select a module system explicitly:
  // nodePlugin.configs.recommendedModule,
  // nodePlugin.configs.recommendedScript,
]);

Validation

On macOS arm64 with Node.js 22.18.0:

  • pnpm --filter @rslint/core build:bin — passed.
  • pnpm --filter @rslint/core build:js — passed, including declarations.
  • CI=true pnpm --dir packages/rslint exec rs test run tests/define-config.test.ts tests/config-loader.test.ts tests/globals.test.ts — 99 passed.
  • CI=true pnpm --dir packages/rslint-test-tools exec rs test run tests/cli/js-config/presets.test.ts tests/cli/js-config/language-options-globals.test.ts — 50 passed.
  • With TMPDIR beneath an ESM package, reproduced the missing-package fixture failure before the fix. TMPDIR=<isolated-dir> CI=true pnpm --dir packages/rslint-test-tools exec rs test run tests/cli/js-config/presets.test.ts — all 37 passed after adding the CommonJS fixture boundary.
  • Packed core and the host native package with pnpm pack, installed the tarballs into an isolated temporary project without globals, and ran the packaged CLI: all three presets passed in both module and CommonJS packages across .js, .mjs, and .cjs (6 runs, 18 files). Verified root import loads no globals assets and preset normalization loads only node.json and es2021.json.
  • Reproduced the API/process-directory mismatch against both rslint and the published upstream preset to confirm the auto-selection limitation described above.
  • Compared the built presets against the published eslint-plugin-n@18.3.0 package: all 13 rule configurations and 134 upstream globals match after prefix mapping; confirmed the upstream duplicate Object.fromEntries diagnostics from the syntax and builtins rules.
  • pnpm --filter @rslint/website build — passed; verified the rendered preset names, API mapping links, and the repaired anchor.
  • pnpm run format:check, pnpm run check-spell with all changed text paths explicitly supplied, and git diff --check — passed.

No Go implementation changed. Full-repository tests and other platforms were not run.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Deploying rslint with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5157459
Status: ✅  Deploy successful!
Preview URL: https://fe86a0c8.rslint.pages.dev
Branch Preview URL: https://feat-node-presets.rslint.pages.dev

View logs

@fansenze
fansenze marked this pull request as draft September 21, 2026 13:33
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦀📦 Binary size

Commit 4579ff9 merged into base 3be2547 — feat(unicorn): add prefer-type-error rule (#2242).

Binary Base This PR Change
rslint (linux-x64-gnu) 39.97 MiB 39.97 MiB 0.00 KiB (0.00%)

Stripped go build -ldflags="-s -w" ./cmd/rslint, Go 1.26.0, linux/amd64 · run · 2026-09-22 04:21 UTC

@fansenze
fansenze marked this pull request as ready for review September 21, 2026 14:06
Comment thread website/docs/en/api/presets/node-plugin.md Outdated
Comment thread packages/rslint-test-tools/tests/cli/js-config/presets.test.ts Outdated
Comment thread packages/rslint/src/config/presets/index.ts

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@fansenze
fansenze merged commit 7a8e431 into main Sep 22, 2026
16 checks passed
@fansenze
fansenze deleted the feat/node-presets branch September 22, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants