Add lint:tsc package script#9652
Conversation
| @@ -0,0 +1,12 @@ | |||
| { | |||
| "extends": ["./tsconfig.json", "../../tsconfig.packages.lint.json"], | |||
There was a problem hiding this comment.
These per-package config files work a bit differently than the per-package tsconfig.build.json files, because they extend two files rather than one. I chose to do this because these files are very similar to tsconfig.json in concept but they just need to be tweaked a little bit (whereas tsconfig.build.json is almost entirely different from tsconfig.json, so it only makes sense to extend tsconfig.packages.build.json).
| @@ -44,7 +44,7 @@ describe('create-package/cli', () => { | |||
| beforeEach(() => { | |||
| // yargs calls process.exit() with 1 on failure and sometimes 0 on success. | |||
| // We have to intercept it. | |||
| jest.spyOn(process, 'exit').mockImplementation((code?: number) => { | |||
There was a problem hiding this comment.
Fixing existing type error in this file, which only showed up in my editor.
There was a problem hiding this comment.
In typechecking this file tsc told me that it interpreted knip as an ESM-only module but it interpreted this file as CommonJS. Renaming this file cleared the type error (although it did mean I had to update how we call knip in package.json, because knip won't look for knip.config.mts by default).
| */ | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "skipLibCheck": true, |
There was a problem hiding this comment.
We don't enable this setting in tsconfig.json or tsconfig.packages.json, however, I found it to be necessary in this case. We are getting a large number of errors from @types/node and I wasn't quite sure how to resolve them. I figured we could investigate that problem in a different PR.
Adding skipLibCheck isn't entirely without precedent: we enable this in tsconfig.build.json.
Currently, the monorepo is not being fully typechecked in CI. This is a problem because type errors have sneaked into test files, and the only way to see them is in an editor context. To fix this, this commit adds another category of tsconfig files (`tsconfig.lint.json`) which are like the development-only versions, except they emit type declarations to a temporary directory. This allows packages which have dependencies on other packages to resolve types correctly. These tsconfigs are linted by the `lint:tsconfigs` scripts. This commit also adds a `lint:tsc` package script which makes use of `tsconfig.lint.json`. Note that if we were to run this across the monorepo we would have to address many type errors. To allow us to address these incrementally, this commit only enables linting for a subset of packages.
Explanation
Currently, the monorepo is not being fully typechecked in CI. This is a problem because type errors have sneaked into test files, and the only way to see them is in an editor context (they are not always caught by Jest).
To fix this, this commit adds another category of tsconfig files (
tsconfig.lint.json) which are like the development-only versions, except they emit type declarations to a temporary directory. This allows packages which have dependencies on other packages to resolve types correctly. These tsconfigs are linted by thelint:tsconfigsscripts. This commit also adds alint:tscpackage script which makes use oftsconfig.lint.json.Note that if we were to run this across the monorepo we would have to address many type errors. To allow us to address these incrementally, this commit only enables linting for a subset of packages. We will increase this set in future PRs.
References
Checklist
Note
Low Risk
Changes are limited to tooling, CI, and TypeScript config; no runtime product code.
Overview
Adds repository-wide TypeScript typechecking in CI via a new
lint:tscscript (tsc --build tsconfig.lint.json), wired into the rootlintcommand and the lint workflow matrix.Introduces a
tsconfig.lint.jsonlayer (root + sharedtsconfig.packages.lint.json) that mirrors dev configs but emits declarations into.tsc-lint-cache/so project references resolve across workspace packages. Only four packages are enabled initially (base-controller,messenger,messenger-cli,platform-api-docs) so the rest of the monorepo can opt in later.Extends
lint:tsconfigsto validate and fix references ontsconfig.lint.jsonseparately fromtsconfig.json/tsconfig.build.json, using workspaces that actually have a lint config.lint:dependenciesnow points knip atknip.config.mtsexplicitly; roottsconfig.jsonincludes that file instead ofknip.config.ts.Reviewed by Cursor Bugbot for commit a50e40f. Bugbot is set up for automated code reviews on this repo. Configure here.