Skip to content

ref(lint): Enable no-unnecessary-condition in mcp-core - #2123

Merged
JoshuaKGoldberg merged 1 commit into
mainfrom
josh/lint-no-unnecessary-condition-mcp-core
Nov 11, 2026
Merged

JoshuaKGoldberg merged 1 commit into
mainfrom
josh/lint-no-unnecessary-condition-mcp-core

Conversation

@JoshuaKGoldberg

@JoshuaKGoldberg JoshuaKGoldberg commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Turns on typescript/no-unnecessary-condition for just packages/mcp-core, since there are a lot of violations in the repo.

It drops checks the types already guarantee. Where a guard is needed at runtime but the types hid that, it fixes the types (checked against the Sentry source) so the guard stays. Just to be safe.

Turn on typescript/no-unnecessary-condition for packages/mcp-core as the
first step of a per-package rollout. Checks the types already guarantee are
removed. Where a guard was load-bearing but the type hid it (array and
record index access, Object.entries inference, event contexts), the type
is made accurate instead so the guard stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 9, 2026 9:43pm UTC

Request Review

@JoshuaKGoldberg

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0b5869e. Configure here.

@JoshuaKGoldberg
JoshuaKGoldberg marked this pull request as ready for review November 10, 2026 14:18
@@ -1,5 +1,5 @@
export const LIB_VERSION =
(typeof process !== "undefined" && process.env?.npm_package_version) ||
(typeof process !== "undefined" && process.env.npm_package_version) ||

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[Question] Do we know specifically of any customer/user environments where process exists but process.env doesn't? I've never seen such a thing.

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.

i don't think so. we also have this in place, so we're good:

env: {
SENTRY_ENVIRONMENT: "stdio",
SENTRY_RELEASE: packageVersion,
npm_package_version: packageVersion,
},

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 10, 2026
@JoshuaKGoldberg
JoshuaKGoldberg merged commit a1d68b1 into main Nov 11, 2026
43 checks passed
@JoshuaKGoldberg
JoshuaKGoldberg deleted the josh/lint-no-unnecessary-condition-mcp-core branch November 11, 2026 14:40
betegon added a commit that referenced this pull request Nov 13, 2026
## Summary

This continues #2123 (thanks @JoshuaKGoldberg). It turns on
`typescript/no-unnecessary-condition` for `packages/cli/test/**` and
fixes what the rule reports there. It uses the same approach as #2123:
drop checks the types already guarantee, and where a check matters at
runtime, fix the type so the check stays.

### Key Changes

- Builds on #2186, which added the test tsconfig
- **Fixed the 47 real reports**:
  - Dropped checks the types guarantee.
- Typed mocks that had no parameters (`vi.fn(() => true)` made
`calls[0]?.[0]` `never`).
- Removed casts like `(event.extra as Record<…>)?.environ` that hid
optional fields. Removing the cast with the `?.` crashed a test, so the
field now uses its real optional type.
- **Fixed one newly visible `require-array-sort-compare`** in
`response-cache-store.test.ts`.
- **Two reports in `completions.property.test.ts` show up only when
`src/generated/completion-targets.json` exists** (after
`script/generate.ts`). Lint is clean both with and without the generated
files.

No sites were deferred to the `src` batch, and there are no disable
comments.

<!-- junior-request-attribution:start -->
via @betegon.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A7d5cd1b81d3d817324abd3315e490aad -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A7d5cd1b81d3d817324abd3315e490aad)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A7d5cd1b81d3d817324abd3315e490aad/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: bete <28983162+betegon@users.noreply.github.com>
betegon added a commit that referenced this pull request Nov 13, 2026
Continues #2123 (thanks @JoshuaKGoldberg). This is the first of three
PRs that split #2196 so each part can be reviewed on its own. It turns
on `typescript/no-unnecessary-condition` for `packages/cli/script/**`
and fixes what the rule reports there.

### What's in it

- `.oxlintrc.json`: adds the rule to the existing
`packages/cli/script/**/*.ts` override.
- `packages/cli/script/tsconfig.json` (new): extends `../tsconfig.json`.
Without it, type-aware lint checked scripts against an inferred project
with `noUncheckedIndexedAccess` off, which reported false positives
(same fix as the test tsconfig in #2186).
- 8 scripts: regex groups and array lookups use `.at(i)` so their
`undefined` checks stay. It also drops checks the types already
guarantee: `command.parameters?.`, `args.with?.`, and a `kind ===
"tuple"` check after the narrowing that already rules out every other
kind.

### Please check

- `script/lib/output-schema-fields.ts`: `valibotTypeToString` now calls
`unwrapPipe(input)` without the `input ?` guard. Its parameter type
isn't nullable.
- `script/generate-sdk.ts`: `derivePositional` drops `params.kind ===
"tuple"` because the earlier branches already handled every other kind.

The other two PRs cover the CLI runtime code and the API-facing code.
The code is the same as in #2196.

<!-- junior-request-attribution:start -->
via @betegon.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A5958cecb5dcc235a4bb8f00d1688c52f -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A5958cecb5dcc235a4bb8f00d1688c52f)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A5958cecb5dcc235a4bb8f00d1688c52f/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: bete <28983162+betegon@users.noreply.github.com>

This branch was successfully deployed

2 active deployments
Preview — 0b5869ee Deployed Nov 9, 2026 by vercel[bot]
Actions — 0b5869ee Deployed Nov 9, 2026 by JoshuaKGoldberg via eval #1754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants