Skip to content

ref(lint): Enable no-unnecessary-condition in cli - #2187

Closed
JoshuaKGoldberg wants to merge 7 commits into
mainfrom
josh/lint-no-unnecessary-condition-cli
Closed

JoshuaKGoldberg wants to merge 7 commits into
mainfrom
josh/lint-no-unnecessary-condition-cli

Conversation

@JoshuaKGoldberg

@JoshuaKGoldberg JoshuaKGoldberg commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Turns on typescript/no-unnecessary-condition for packages/cli, following #2123, and builds on #2186 so tests are checked with the CLI's compiler options.

Any checks that the types already guarantee are dropped. Where a guard is needed at runtime (API fields older servers omit, parsed files, terminal sizes), the types are fixed so the guard stays.

JoshuaKGoldberg and others added 2 commits November 11, 2026 10:55
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 13, 2026 5:01pm 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 278cda9. Configure here.

@JoshuaKGoldberg
JoshuaKGoldberg marked this pull request as ready for review November 11, 2026 16:14
Comment thread packages/cli/src/lib/db/auth.ts Resolved
Base automatically changed from josh/cli-test-tsconfig to main November 13, 2026 16:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 13, 2026
const tableRows: Row[] = rows.map(({ rule: r, orgSlug }) => ({
id: r.id,
name: tableCell(r.name ?? "(untitled)"),
name: tableCell(r.name),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Null metric alert name crashes human list output

When the detectors API returns a null name, human-formatted alert metrics list passes it to tableCell() and throws a TypeError instead of displaying the rule.

Evidence
  • listMetricAlertsPaginated treats the detector response as MetricDetector[] without runtime validation, and mapDetectorToMetricAlertRule copies detector.name; test/commands/alert/metrics/list.test.ts supplies a detector with name: null.
  • Human output maps display rows through tableCell(r.name) with no null fallback. tableCell calls toSingleLine, which calls value.replace, so a null name throws.
  • The existing null-name test filters in JSON mode; it does not cover the unfiltered human-output path.

Identified by Warden · code-review · SX4-WJ2

@joshuarli

Copy link
Copy Markdown
Member

Superseded by #2266. All of this branch's changes are carried there, rebased onto the base branch.

@joshuarli joshuarli closed this Nov 18, 2026
joshuarli added a commit that referenced this pull request Nov 18, 2026
Toolkit was on TypeScript 5.9 and pnpm 11, each project had its own
type-check settings, and many tests, scripts, Worker and build configs
were never type-checked in CI. This moves the workspace to TypeScript
7.0.2 and pnpm 12.18.0, applies one strict tsconfig policy to every
maintained TypeScript file, and adds stronger type-aware Oxlint rules.
Published package contracts are unchanged.

This single PR supersedes the stacked #2240,
#2187, #2238, and
#2239: everything those branches carried is here,
rebased onto current `main` (which also carries #2186). #2187's metric
alert query filter fix is included as a cherry-pick. It follows that
stack's layout: one root `tsconfig.base.json` that every project
extends, no `@sentry/mcp-server-tsconfig` package, and one root
`.oxlintrc.json`.

Intermediate commits are not individually green; squash-merge.

## Changes

- The root `tsconfig.base.json` keeps the stack's runtime defaults and
adds the rest of the checking policy. Projects set only runtime options
such as target, module, lib, types, JSX and emit. The policy enables:
- `strict`, `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`,
`noPropertyAccessFromIndexSignature`
  - `verbatimModuleSyntax`, `erasableSyntaxOnly`
  - the `noUnused*` checks
  - `skipLibCheck: false`
- Every package's sources, tests, scripts and build configs belong to a
program that its `typecheck` script runs.
- `scripts/tsconfig-policy.test.mjs` reads the policy from the root base
and guards against:
  - files left uncovered
  - weakened options
  - library-check exceptions without a stated reason
- Tooling upgrades:
- Oxlint 1.93 with tsrs-lint (tsrs 7.1.0-beta.tsrs3) for type-aware
rules, Oxfmt 0.78, tsdown 0.23
- Code generators that need the old compiler API now use
`@typescript/typescript6`.
- New lint rules for the whole repo: promise misuse, exhaustive
switches, `only-throw-error` and related safety rules.
- Non-test code outside the CLI, including apps/local, now also bans
`any`, `!`, unnecessary conditions and unsafe `any` flows.
- Bugs that stricter types exposed:
- mcp-cloudflare now rejects incomplete OAuth approval states and empty
HMAC signatures.
- mcp-cloudflare's `/api/chat` now returns a 500 for a non-`Error`
throw.
- apps/local's Web Vitals view no longer crashes when a page has no
metrics.
- The CLI's `command-api.json` regained the fixed query notes it had
lost.

## Impact

- pnpm 11 switches itself to 12.18.0 because of the `packageManager`
pin. The first switch adds `@pnpm/exe` entries to `pnpm-lock.yaml`;
discard them.
- `typecheck` is the canonical script. `tsc` remains as an alias.
- The quality job in CI builds `@sentry/mcp-core` and `@sentry/logger`
before lint, because type-aware rules read workspace packages through
their built declarations.

## Exceptions

- `packages/codemod-cli3to4/tsconfig.json` repeats the checking options
instead of extending the root, because `jssg` cannot resolve an
`extends` outside the package. The policy test fails if the copy drifts.
- 11 programs keep `skipLibCheck: true`, each with a comment naming the
dependency, the diagnostic and when to remove it:
- `ai` declarations (under `exactOptionalPropertyTypes`, and DOM or Node
names they reference)
- `@cloudflare/workers-types` conflicting with `@types/node` globals,
and `urlpattern-polyfill` against the workers-types `URLPattern` global
- `wrangler` and `miniflare` declarations referencing packages they
bundle but do not ship
- `unplugin` and `vite` declarations referencing packages they don't
ship
  - `hono` declarations using DOM names in the Node program
- `apps/cli-docs` keeps `astro check` on TypeScript 6 until
`@astrojs/check` supports TypeScript 7.
- Vitest is pinned to `~5.0.5`. Vitest 5.1 needs
`AsyncLocalStorage.disable()`, which workerd lacks. Remove the pin once
`@cloudflare/vitest-plugin` ≥ 1.7.0 is adopted.
- Type-aware lint runs on `tsrs-lint`, which tracks the TypeScript 7.1
beta. `pnpm run typecheck` stays on TypeScript 7.0 and is the type gate.
`.pnpmfile.cjs` drops oxlint's optional `oxlint-tsgolint` peer, which
pnpm 12 would otherwise install unused. tsrs3 is newer than the
release-age window, so its packages are in `minimumReleaseAgeExclude`.

## Open questions

- In mcp-cloudflare's `chat-message.tsx`, the tool-part state mapping
never sees `"result"` under AI SDK v6. That bug predates this PR and is
left as is.

Refs getsentry/junior#2171

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

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3Af90a6d1952c6435371ab2bce -->

--

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

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

---------

Co-authored-by: Josh Goldberg ✨ <joshua.goldberg@sentry.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Co-authored-by: Joshua Li <joshuarli98@gmail.com>
Co-authored-by: Inkling 2 Small Free <inkling-2-small-free@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Preview — 5f7cf1b4 Deployed Nov 13, 2026 by vercel[bot]
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.

3 participants