You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Incremental Migration for TypeScript
Seamlessly migrate your codebase to leverage the latest TypeScript compiler features while maintaining clarity, control, and CI stability.
π Audit: The audit slugs depending on the implementation could be a small set that is easy to maintain, or a TS-Code to slug manually maintained list.
π Group: The groups are similar to audits easy depending approach. A convention aligning with compiler options might be hard. Some of the group slugs overlap with compiler options like strict which is a short hand option to enable all strict type checks. All those cases need to be maintained manually.
π Category: The categories could be the same as for EsLint plus one for the configuration linting.
Details maintenance
π Issues: The details contain only issues, but those are a bit cumbersome to set up initially. The TypeScript's compiler diagnostics return diagnostic codes, and a subset of those codes are relevant for this plugin. The irrelevant ones are easy to filter out. The relevant ones need to manually be mapped to an audit in the maintained map.
π Table: N/A
Runner maintenance
The runner is simple to maintain, consisting of only a few fully typed lines.
Acceptance criteria
The target tsconfig.json serves as the primary source for report creation and determines the applied audits.
Parsed using helpers from the typescript package.
Default configuration is loaded based on the current typescript version.
Audits are derived from programmatically derived or a small set of static data.
Audits are filtered by onlyAudits if specified.
Issues are grouped by an audit slug.
docsUrl points to the official documentation page.
Unsupported diagnostic codes are logged.
Audits are organized into logically linked groups.
Implementation details
π Key Note: Thereβs no way to automatically link Diagnostic results to compiler options.
There is no known way to link the Diagnostic results to compiler options or audits.
Diagnostic results depend on both the active tsconfig.json configuration and TypeScript internal defaults.
TypeScript defaults are not exported. They are derived over internal logic that depends on the current package version.
Ambiguity exists between disabled and missing compiler options.
Ambiguity exists between configures and internally derived compiler options.
A draft implementation of the plugin can be found here: #902.
Setup
The plugin needs the following options:
typePluginOptions={tsConfigPath?: string,onlyAudits?: AuditSlug[]}|undefined;constpluginOptions: PluginOptions={tsConfigPath: `tsconfig.next.json`,// default is `tsconfig.json`onlyAudits: ['no-implicite-any']};
Generating TypeScript Diagnostics
The typescript package exports a method to create a program. The required parameters are derived from a given tscinfig.json file:
This objects need to get linked to audits. Due to key note [1] we would have to maintain a manual map to link diagnostic errors to audits and groups. So far the only maintainable way to group diagnostics is to rely on the undocumented ranges.
NOTE: This section is here to reflect learnings from the research
The existing compiler options configured in tsconfig.next.json are different from the ones used in the program. This internal logic is not accessible and parts of that logic has to be duplicated in the plugin source, see key notes [2].
Case 1: Internally applied defaults options - key notes [5]
The npx tsc --init command creates a tsconfig.json file with all defaults listed as comments.
A suggested implementation could be npx -y tsc -p=typescript@{version} --init.
generated tsconfig.json file
{"compilerOptions": {/* Visit https://aka.ms/tsconfig to read more about this file *//* Type Checking */"strict": true,/* Enable all strict type-checking options. */// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */}}
This file gets parsed and stores as tsconfig.<version>.json under node_modules/.code-pushup/typescript-plugin/ts-defaults.
This data can get generated and loaded at runtime of the plugin and merge with the config retrieved form tsconfig.next.json.
Solution 2 (favoured)
The generate login from above can install the current TypeScript version on the postinstall hook fired on every npm install.
At runtime of the plugin can load this data and merge this defaults into the config retrieved form the given tsconfig.next.json.
Typescript Plugin
Incremental Migration for TypeScript
Seamlessly migrate your codebase to leverage the latest TypeScript compiler features while maintaining clarity, control, and CI stability.
π§ͺ Reference PR
π #902 β TypeScript Plugin PoC Implementation
Metric
TypeScript code quality based on compiler diagnostics.
Derived from diagnostic objects of category
error
andwarning
.48
48 errors
0
1
) or failed (0
).User story
As a developer, I want to incrementally migrate my codebase to the latest TypeScript features while avoiding large-scale refactoring and CI failures.
The plugin should:
Diagnostic
data.Integration Requirements
Setup and Requirements
π¦ Package Dependencies
π Configuration Files
tsconfig.json
β Standard configuration file.tsconfig.next.json
β Migration-specific configuration.Audit, groups and category maintenance
strict
which is a short hand option to enable all strict type checks. All those cases need to be maintained manually.Details maintenance
Runner maintenance
The runner is simple to maintain, consisting of only a few fully typed lines.
Acceptance criteria
tsconfig.json
serves as the primary source for report creation and determines the applied audits.typescript
package.typescript
version.onlyAudits
if specified.docsUrl
points to the official documentation page.Implementation details
tsconfig.json
configuration and TypeScript internal defaults.A draft implementation of the plugin can be found here: #902.
Setup
The plugin needs the following options:
Generating TypeScript Diagnostics
The
typescript
package exports a method to create a program. The required parameters are derived from a giventscinfig.json
file:The
typescript
package exports a method to get theDiagnostic
results of a given program:All objects are identified by a unique code:
TypeScript diagnostic codes are grouped into ranges based on their source and purpose. Unfortunately this is not documented anywhere.
Here's how they are categorized:
The diagnostic messages are exposed over a undocumented and undiscoverable const names
Diagnostics
.This objects need to get linked to audits. Due to key note [1] we would have to maintain a manual map to link diagnostic errors to audits and groups. So far the only maintainable way to group diagnostics is to rely on the undocumented ranges.
TypeScript Compiler Options
The existing compiler options configured in
tsconfig.next.json
are different from the ones used in the program. This internal logic is not accessible and parts of that logic has to be duplicated in the plugin source, see key notes [2].Case 1: Internally applied defaults options - key notes [5]
tsconfig.next.json
calculated compiler options inside the TS program
Solution 1
The
npx tsc --init
command creates atsconfig.json
file with all defaults listed as comments.A suggested implementation could be
npx -y tsc -p=typescript@{version} --init
.generated
tsconfig.json
fileThis file gets parsed and stores as
tsconfig.<version>.json
undernode_modules/.code-pushup/typescript-plugin/ts-defaults
.tsconfig.5.5.4.json
This data can get generated and loaded at runtime of the plugin and merge with the config retrieved form
tsconfig.next.json
.Solution 2 (favoured)
The generate login from above can install the current TypeScript version on the postinstall hook fired on every
npm install
.At runtime of the plugin can load this data and merge this defaults into the config retrieved form the given
tsconfig.next.json
.Case 2: : Internally expanding defaults/short-hand options - key notes [5]
tsconfig.next.json
calculated compiler options inside the TS program
Is TypeScript
strict
acts as a short-hand and expands internally into multiple other options.Solution 1
We can re-implement the internal logic to handle cases like
strict
etc in the plugin source.Resources
The text was updated successfully, but these errors were encountered: