Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typecheck updates & fixes in src/language-js #8759

Merged
merged 82 commits into from Aug 21, 2020

Conversation

brodybits
Copy link
Contributor

@brodybits brodybits commented Jul 15, 2020

updated:

  • add some type support packages to devDependencies
  • add & update JSDoc type comments
  • add src/language-js/types/estree.d.ts to facilitate clean parameter types in src/language-js/utils.js
  • apply some minor code updates to resolve some typecheck issues
  • add a single @ts-ignore comment, to work around a type issue remaining in src/language-js/utils.js
  • remove src/language-js & src/common/parser-create-error.js from exclude list in tsconfig.json
  • move & refactor typedefs in src/language-js/print/ternary.js, based on the changes I had originally proposed in PR refactor typedefs in src/language-js/print/ternary.js #8745
  • add some blank lines
  • minor extra cleanup of src/main/comments.js, as described below

(there used to be many more @ts-ignore comments, which are now resolved)

P.S. I suspect some of the minor code updates can make the code a little more robust. It would be interesting to see if we can think of any test cases to prove this or not.

Try the playground for this PR

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of TODO, can we remove them and adding types late in other PRs?

@brodybits brodybits marked this pull request as draft July 15, 2020 12:53
@brodybits
Copy link
Contributor Author

I just merged changes from master & replaced TODO with TBD (...) in the @ts-ignore comments. I would also like to rebase to improve the history message. My one issue is that I hope we can try to avoid using @ts-ignore comments to avoid resolving new JSDoc type issues in the future.

@brodybits brodybits marked this pull request as ready for review July 15, 2020 22:41
@brodybits
Copy link
Contributor Author

brodybits commented Jul 15, 2020

I just rebased this proposal with a hopefully cleaner commit history, with some updates:

At this point there are 2 TODO comments for issues that I think should be addressed in the near future:

  • error type issue in src/common/parser-create-error.js
  • Prettier options object typedef in src/language-js/print/ternary.js

Other @ts-ignore comments are simple TBD comments - see the updated list in the description.

It looks like the build cancelled itself, would appreciate it if someone could restart the build.

@alexander-akait
Copy link
Member

/cc @prettier/core

src/language-js/comments.js Outdated Show resolved Hide resolved
@brodybits brodybits changed the title JSDoc type fixes in src/language-js typecheck updates & fixes in src/language-js Jul 16, 2020
@brodybits brodybits marked this pull request as draft July 16, 2020 21:23
@@ -672,8 +683,9 @@ function printPathNoParens(path, options, print, args) {
options.locEnd
);
return (
nextCharacter &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nextCharacter &&
nextCharacter !== false &&

I wish we had a good way to test this kind of case.

@brodybits brodybits marked this pull request as ready for review August 12, 2020 04:09
@fisker
Copy link
Sponsor Member

fisker commented Aug 12, 2020

Saw this #8759 (comment)?

@brodybits
Copy link
Contributor Author

Saw this #8759 (comment)?

OK so Prettier basically uses its own "estree" format which can handle estree or estree-like AST structure that comes out of the Babel, Flow, or typescript-estree parser modules.

I am wondering about a couple things, though:

  • We had to add what look like some non-standard fields to some AST node types to get the function type checks to work properly. And we added these fields to all other exported "estree" AST node types.
  • The output of the Babel, Flow and typescript-estree parsers are processed by postprocess.js before returned by the parse function and are ready to be piped into the printer function.

I will probably take my rest pretty soon. Unfortunately I have some other priorities that I had put off for a while and may not be able to contribute much more over the next 1-2 weeks or so. I hope we can finish this PR without too much more work now and consider improving the type check in future PRs.

@brodybits
Copy link
Contributor Author

Latest estree.d.ts updates in 5414a62 look good to me, thanks.

@brodybits brodybits mentioned this pull request Aug 19, 2020
4 tasks
// MUST REMOVE to avoid errors with TypeScript 4.0.0:
import * as ts from "typescript";
declare module "typescript" {
type NamedTupleMember = Node;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work even with TypeScript 4.x:

Suggested change
type NamedTupleMember = Node;
export interface NamedTupleMember extends Node {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ExE-Boss. I would actually favor keeping this workaround as-is, errors can remind us to remove it with the TypeScript 4 update. Nice idea, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to remove this entire workaround if typescript-eslint/typescript-eslint#2405 is merged and released. I hope this will be possible.

@fisker fisker merged commit cdc250c into prettier:master Aug 21, 2020
@fisker
Copy link
Sponsor Member

fisker commented Aug 21, 2020

Good job

@brodybits brodybits deleted the language-js-jsdoc-types branch August 21, 2020 01:13
@brodybits
Copy link
Contributor Author

Teamwork yeah!

@brodybits brodybits mentioned this pull request Aug 21, 2020
4 tasks
@fisker fisker mentioned this pull request May 31, 2021
4 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants