Skip to content

feat(unicorn): add no-useless-error-capture-stack-trace rule - #2203

Merged
fansenze merged 2 commits into
web-infra-dev:mainfrom
HashemKhalifa:feat/unicorn-no-useless-error-capture-stack-trace
Sep 18, 2026
Merged

fansenze merged 2 commits into
web-infra-dev:mainfrom
HashemKhalifa:feat/unicorn-no-useless-error-capture-stack-trace

Conversation

@HashemKhalifa

Copy link
Copy Markdown
Contributor

Motivation

Refs #1309.

Port unicorn/no-useless-error-capture-stack-trace from eslint-plugin-unicorn v75.0.0. The rule was absent from main and exact-name, all-state PR searches returned no matches before implementation and on the final eligibility check.

Changes

Use a scoped ancestor walk instead of parallel class/this traversal stacks. Preserve arrow-function scope, reject shadowed or disabled error globals, and use the canonical class-symbol helper for TypeScript declaration merging. Restrict autofixes to standalone block statements.

Add documentation, catalogue registration, a JavaScript upstream mirror, and separate upstream/extras Go suites. This branch is independent of the other new rule PRs and does not modify shared utility implementations.

Validation

  • 54 upstream/documentation source cases and 42 additional scope, syntax and regression cases passed through the native Go RuleTester. Assertions cover diagnostic IDs/text, full ranges, autofix output, and absence of edits where the call cannot be safely removed as a standalone block statement.
  • Two representative scenarios cover all four edit-demand modes; diagnostic identity stays unchanged and edit artifacts are produced only when requested.
  • Direct Go-versus-ESLint comparison passed on copies of two real repository TypeScript files (packages/rslint/src/service/service.ts and packages/rslint/src/eslint-plugin/plugin/plugin-loader.ts), each with an appended positive control. Checked diagnostic IDs/text, full ranges, applied autofixes and suggestion IDs/outputs. Reference: Unicorn 75.0.0, ESLint 10.10.0, typescript-eslint parser 8.62.0. This exercises the native rule harness, not the IPC layer.
  • Focused Go 1.26.0 tests passed: go test ./internal/plugins/unicorn/rules/no_useless_error_capture_stack_trace.
  • golangci-lint 2.12.2 passed with --new-from-merge-base=origin/main on the new rule package and changed Unicorn catalogue package.
  • Changed-file spelling, pnpm run format:check, gofmt, and git diff --check passed. Normal repository pre-commit hooks remained enabled.

Local integration limitation

The full catalogue test, schema dump, complete native/core-JavaScript builds, and JavaScript integration run were not executed in this batch. The Mac previously exhausted disk and experienced sustained full-catalogue linker pressure, so this batch reused the unchanged pinned compiler with task-local workspace files and bounded, focused verification. No repository toolchain or dependency versions were changed.

The JavaScript mirror is included and registered but is not claimed as passing locally. CI must validate full registration/build and native-JavaScript integration before merge.

Use a scoped ancestor walk instead of parallel class/this traversal stacks. Preserve arrow-function scope, reject shadowed or disabled error globals, and use the canonical class-symbol helper for TypeScript declaration merging. Restrict autofixes to standalone block statements.

Cover 96 source cases plus edit-demand boundaries; compare two real-source copies against pinned Unicorn v75. Full native/JS integration remains for CI.
@elecmonkey

Copy link
Copy Markdown
Member

enable in preset plz

Enable unicorn/no-useless-error-capture-stack-trace at error severity in the recommended
preset and assert its public preset registration in the existing suite.

The source-backed preset regression failed before the registration change
and passes afterward. Only this rule is newly enabled; other preset
settings are unchanged. Formatting and changed-file spelling checks pass.
@fansenze
fansenze merged commit 8717398 into web-infra-dev:main Sep 18, 2026
26 of 28 checks passed
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