Repository navigation
docs(develop): Add frontend linting and lint incubator guides - #20919
natemoo-re wants to merge 5 commits into
Conversation
Document how getsentry/sentry rolls out new Oxlint rules incrementally using per-workspace oxlint-suppressions.json budgets, local lint:suppressions maintenance commands, and CI ratchet workflows. Fixes DE-1723
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…uide Add a parent Linting page under Frontend covering mechanical enforcement in the agentic era, rule design principles, and the frontend linting stack, and condense the Lint Incubator guide around its operational model. Refs DE-1723
Document Knip checks for unused files/exports, production dead code, and circular module imports on the frontend linting page. Refs DE-1723
|
Getting ready to monitor this change · Rollout details
|
coolguyzone
left a comment
There was a problem hiding this comment.
Looks good, thanks for adding!
|
|
||
| When adding or updating a lint rule, optimize for fast comprehension and low false positives: | ||
|
|
||
| - **Enforce as errors, never permanent warnings**: Warnings get ignored by both humans and agents. Every active rule fails the build. When pre-existing violations prevent turning a rule on all at once, enroll it in the [Lint Incubator](/frontend/linting/lint-incubator/) instead of leaving it at `warn`. |
There was a problem hiding this comment.
[Bug] I don't think "Every active rule fails the build" is true today: oxlint.base.ts still has four 'warn' rules (jest/no-commented-out-tests, testing-library/no-debugging-utils, regexp/confusing-quantifier, regexp/no-empty-alternative), and nothing passes --deny-warnings/--max-warnings. prek even runs oxlint with --quiet, which hides warnings entirely.
You might consider rephrasing this as guidance for new rules ("New rules should be errors…"), or flipping those four in a follow-up. My preference would be to make the four warn rules error though, so this becomes fully correct. 🧹
|
|
||
| ## Frontend Linting Stack | ||
|
|
||
| Frontend checks in `getsentry/sentry` split responsibility across five tools: |
There was a problem hiding this comment.
[Docs] Small mismatch: the overview in frontend/index.mdx lists four tools (Oxlint, Oxfmt, Stylelint, Knip), while this says five. The fifth (dependency linting) also doesn't name sherif, which might help folks who see it in CI output.
| - **`New incubator violations`**: Your change added a violation in a clean file or pushed a file above its `master` budget. Because budgets track counts per file rather than line numbers, the error output lists every current violation of that rule in the file. Fix one or more of them to bring the count back within budget. Do not manually raise `count` in `oxlint-suppressions.json`; CI compares against `master` and rejects budget increases. If a specific line genuinely requires an exception, add an inline disable comment (`// oxlint-disable-next-line <rule>`) explaining why, then prune if the file also had a recorded budget. | ||
| - **`Suppression budgets are stale`**: Your changes lowered the violation count in one or more files (either directly, or indirectly by updating a shared TypeScript type), leaving the committed budget higher than live debt. `pnpm run fix:oxlint` lowers budgets automatically when autofixing root files; otherwise run `pnpm run lint:suppressions --prune` and commit the updated `oxlint-suppressions.json` files. |
There was a problem hiding this comment.
[Question] These headings are messages from lint:suppressions: New incubator violations comes from --ci/--check/--enroll/--prune, and Suppression budgets are stale only from --ci. A local pnpm run lint:js or prek failure just shows plain oxlint diagnostics, e.g.:
static/app/example.tsx:2:22: error @sentry/scraps(prefer-primitives): Use Flex from '@sentry/scraps/layout'. ...
Would it help to note where each message comes from, so readers don't look for these headings in local output?
|
|
||
| ### Enrolling, Updating, and Graduating Rules | ||
|
|
||
| - **Enroll a new rule (or broaden an existing rule)**: Add the rule with `'error'` severity to `incubator` in `oxlint.config.ts` (use `incubator.overrides` for file exclusions or test-only rules, and also enable the rule in `oxlint.base.ts` if standalone workspace packages with their own `oxlint.config.ts` should run it). Then generate baseline budgets against `master`: |
There was a problem hiding this comment.
[Question] For the "also enable the rule in oxlint.base.ts" path: createPackageConfig spreads base.rules without the incubator's warn-in-editor switch (that only lives in oxlint.config.ts). So I think in scraps/icons/search-syntax, editors would show the rule as an error rather than the warning "How Budgets Work" describes. Might be worth a caveat?
|
|
||
| Three GitHub Actions workflows enforce the ratchet and keep `oxlint-suppressions.json` files up to date: | ||
|
|
||
| - **Ratchet verification (`frontend.yml`)**: Checks that no `(file, rule)` count exceeds `master` and that committed `oxlint-suppressions.json` budgets match live violations. If concurrent merges on `master` leave behind stale budgets that your pull request did not touch or cause, CI logs a warning instead of failing your pull request. |
There was a problem hiding this comment.
[Docs] It might help to name the command here: this step runs pnpm run lint:suppressions --ci --base HEAD^1 on PRs, and --ci isn't in the Command Reference table either. That'd make it easier to map CI logs back to these docs.
| "count": 2 | ||
| }, | ||
| "@sentry/scraps/prefer-primitives": { | ||
| "count": 1 |
There was a problem hiding this comment.
[Nit] Totally optional since it's illustrative: the real static/app/oxlint-suppressions.json uses compact {"count": 2} entries, and featureDisabled.tsx currently has prefer-primitives: 2.
Frontend linting conventions and the
getsentry/sentrylint incubator lacked contributor documentation ondevelop.sentry.dev.Adds a new Linting section under Frontend (
develop-docs/frontend/linting/):develop-docs/frontend/linting/index.mdx: Covers our mechanical-enforcement philosophy (especially why deterministic lint feedback matters for coding agents), principles for writing actionable rules, and the frontend linting stack (oxlint,oxfmt,stylelint,knip, and workspace dependency linting).develop-docs/frontend/linting/lint-incubator.mdx: Explains how per-workspaceoxlint-suppressions.jsonbudgets work, how contributors and rule authors resolve failures or enroll/prune/graduate rules, and how CI enforces and maintains the ratchet.Fixes DE-1723
IS YOUR CHANGE URGENT?