[Draft] plan of action for completing JS->TS #30813
Labels
process: contributing
Related to contributing to the Cypress codebase
type: chore
Work is required w/ no deliverable to end user
Success Criteria
.js
in the repository@typescript-eslint/recommended-type-checked
rule setprettier
to autoformat, rather than the deprecated eslint formatting rules@packages/foo
from a file whosepackage.json
does not declare@packages/foo
as a dependency)import
, because the package being imported was declared a dependency in either the rootpackage.json
or a sibling'spackage.json
Preparation
.prettierignore
files to each package with a*
directivenon-strict
rule set from the@typescript-eslint/recommended-type-checked
rule set and export as a config fromeslint-plugin-dev
. Rules thaterror
in the original rule set but which prove difficult to resolve in this repository are set towarn
instead.Execution
For shared language purposes, both packages and files can be categorized as "leaf," "shared," or "root" nodes.
./cli
Formatting
Beginning from leaf packages, recursively down to root packages: add
.prettierrc
files that enforces the formatting from the style guide, and open a PR that updates any nonconforming styling in that package.Ideally a package can be converted to prettier as a prerequisite for feature work to be done in that package.
Typescript
.eslintrc
for each package, that uses thenon-strict
rule set. Some packages may include additional rulesets or plugins for, e.g., graphql. Packages must not disable any rules from@typescript-eslint
unless those rules are replaced with more analogous rules from a different plugin that are more strict. If a rule needs to be changed towarn
, it must be set in thenon-strict
rule manifest, rather than at a package level. The following rules are likely to need to be set towarn
rather thanerror
in thenon-strict
rule set:ban-ts-comment
,no-require-imports
no-explicit-any
,no-unused-vars
await-thenable
,no-floating-promises
,prefer-promise-reject-errors
,require-await
no-require-imports
- this is a prerequisite to moving to ESM, unless we create our ownrequire
withModule.createRequire
.no-floating-promises
, because floating promises can introduce difficult-to-track-down errors in async codepathsno-explicit-any
-any
types are a useful escape hatch when first converting to TS, but prevent static type analysis. If the type of the identifier is indeterminate at declaration time, it is more accurate to type that identifier asunknown
, which forces you to determine what type it actually is via type narrowing before accessing that identifier. Resolving these can run the gamut from very easy to extraordinarily difficult, so prioritize based on the pain level of the specificany
triggering this warning.typedef
helps with implicitany
types, which have all of the pitfalls of explicitany
types. Once these warnings are resolved, we can enable Typescript'snoImplicitAny
compiler option.ban-ts-comment
-@ts-ignore
comments are usually used to bypass typescript when an alternative approach might be possible. Usually if it's difficult to resolve one of these, either a dependency must be updated or a structural refactor should be considered.no-unused-vars
- this is quality of life, and performance, rather than correctness. This is also the lowest hanging fruit.require-await
requires thatasync
functions actuallyawait
a promise. This avoids unnecessary promises, as the return value of anasync
function is always a promise. This is performance, rather than correctness.await-thenable
, because awaiting a non-promise still creates a new microtask. This is a performance rule, not a correctness rule.Constraints(TBD if they will be applied) 10.
prefer-promise-reject-errors
may end up being very difficult to resolve, if there are any instances of this warningHelpful Tips
The text was updated successfully, but these errors were encountered: