refactor(linter/plugins): enable TS strict option#19675
refactor(linter/plugins): enable TS strict option#19675graphite-app[bot] merged 1 commit intomainfrom
Conversation
36ca452 to
cf873b9
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR fixes TypeScript type errors in the linter's JS plugin system by enabling strict mode and implementing a bivariance hack for visitor objects. The bivariance hack allows visitor functions with specific node types (e.g., CallExpression) to be assigned to properties expecting more generic node types, which is necessary for the plugin system to work correctly with TypeScript's strict type checking.
Changes:
- Enabled TypeScript strict mode in
apps/oxlint/tsconfig.jsonto catch type issues - Implemented bivariance hack pattern for
VisitorObjecttype to fix variance issues with visitor function parameters - Added type assertions and nullish coalescing operators to satisfy strict null checks
- Added type definition tests to verify visitor object compatibility
Reviewed changes
Copilot reviewed 13 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/ast_tools/src/generators/raw_transfer.rs | CRITICAL BUGS: Added incorrect import and type for NodeOrToken in generated deserialize type definitions |
| tasks/ast_tools/src/generators/estree_visit.rs | Implemented bivariance hack pattern for visitor types to allow contravariant parameter types |
| apps/oxlint/src-js/generated/visitor.d.ts | Generated visitor types with bivariance hack implementation |
| apps/oxlint/src-js/generated/deserialize.d.ts | Generated with incorrect NodeOrToken type usage (from raw_transfer.rs bugs) |
| apps/oxlint/src-js/visitor.test-d.ts | Added type-level tests to validate visitor object type compatibility |
| apps/oxlint/src-js/plugins/visitor.ts | Added type assertions for strict mode compatibility |
| apps/oxlint/src-js/plugins/cfg.ts | Added type assertions for strict mode compatibility |
| apps/oxlint/src-js/cli.ts | Added undefined handling with nullish coalescing for strict null checks |
| apps/oxlint/src-js/package/rule_tester.ts | Improved function signatures with proper this parameter typing and disabled unbound-method warnings |
| apps/oxlint/conformance/src/rule_tester.ts | Added oxlint-disable comment for intentional unbound method usage |
| apps/oxlint/tsconfig.json | Enabled strict mode and added node types |
| napi/parser/tsconfig.json | Added node types configuration |
| napi/transform/tsconfig.json | Added node types configuration |
| apps/oxfmt/tsconfig.json | Added node types configuration |
| apps/oxlint/package.json | Added @type-challenges/utils dependency for type tests |
| pnpm-lock.yaml | Updated lock file with new dependency |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
d15b14a to
40621dc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
apps/oxlint/conformance/src/rule_tester.ts:112
test.before = function (this) { ... }relies on athisparameter without a type annotation. With TSstrict(enablesnoImplicitThis), this form typically fails type-checking. Add an explicitthistype (e.g.function (this: T) { ... }/unknown) and keeporiginalBeforetyped with the samethisso hooks that depend on theirthiscontext remain correctly typed.
const originalBefore = test.before as () => void;
test.before = function (this) {
setCurrentTest(clonedTest);
originalBefore!.call(this);
};
Fixes #18154, #14745. Use the bivariance hack to fix the type def for `VisitorObject`. The bivariance hack is taken from DefinitelyTyped/DefinitelyTyped#20219. This was originally written by @sapphi-red in #19675. I've split it out into a separate PR. I can't claim to understand this witchcraft!
ecef907 to
602daaa
Compare
9904a4a to
9100c63
Compare
9100c63 to
cce88d5
Compare
cce88d5 to
a7ff967
Compare
Merge activity
|
Enable TypeScript strict option in `apps/oxlint`.
a7ff967 to
e255fcd
Compare
…e not `undefined` (#20070) Follow-on after #19675. The type for `lint` function that NAPI-RS produces is incorrect. `Option::None` on Rust side is translated to `null`, never `undefined`. Check this with a debug assertion, instead of handling `undefined` at runtime (which is pointless, because it never is `undefined`).

Enable TypeScript strict option in
apps/oxlint.