Make WordPress Core

Opened 16 hours ago

Last modified 16 hours ago

#65997 new task (blessed)

TypeScript code quality improvements for 7.2

Reported by: westonruter Owned by:
Priority: normal Milestone: 7.2
Component: General Version:
Severity: normal Keywords:
Cc: Focuses: javascript, docs

Description (last modified by westonruter)

This is the JavaScript analog to the PHP in #65817, but using TypeScript instead of PHPStan. Adding TypeScript checking will likely identify bugs that need to be fixed along the way and it will greatly improve the resilience of the codebase against defects being introduced in the future, either by humans or by agents.

This follows the introduction of the TypeScript in the core codebase in #64662. The initial files being checked with TypeScript are those used by the Code Editor, the tooltip logic, and some build tooling, as is listed in tsconfig.json:

"src/js/_enqueues/lib/codemirror/htmlhint-kses.js",
"src/js/_enqueues/lib/codemirror/javascript-lint.js",
"src/js/_enqueues/wp/code-editor.js",
"src/js/_enqueues/wp/wp-tooltip.js",
"tools/gutenberg/copy.js",
"tools/gutenberg/download.js",
"tools/gutenberg/utils.js"

This list needs to expand so that TypeScript checking can eventually cover the entire JS codebase.

TypeScript can be invoked via npm run typecheck:js. Note also the related command do check JSDoc: npm run lint:jsdoc.

Note that while PHPStan has the concept of the baseline which allows adopting static analysis for an existing codebase with errors, this is not available for TypeScript. So this means we'll need to either go file-by-file adding TypeScript checking with the existing config, or make the existing config (or separate configs) much looser and then stricter over time.

This will naturally be closely related to improvements to JS documentation across the codebase:

  • #65951 (Fix all the JSDocs)
  • #65860 (General docblock improvements for 7.2)
  • #40831 (Customize: Further improve JS inline documentation)

Change History (1)

#1 @westonruter
16 hours ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.