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

Add prettier user test and fix associated crash #23715

Merged
merged 2 commits into from
Apr 26, 2018
Merged

Conversation

sandersn
Copy link
Member

While adding prettier to the user tests, I uncovered another assert in getJSDocHost when looking up type references in a @property tag inside a @typedef tag. This PR contains the fix as well as adding prettier to the user tests.

Crash

  • getJSDocHost didn't work correctly when called on a @property tag.

Incorrect error

Annoying

  • Can't pass null to optional parameter with strictNullChecks.
  • Can't add instance properties to Error instances
  • [] is still often never[] with strictNullChecks (eg as a property of an object literal, or as the initial value of a reduce)
  • When a mutable variable is initialised with a specific member of a discriminated union, we need a type annotation in order to specify that the variable's type should actually be the entire union.
  • Browser detection code needs tweaks to be well-typed, even though nobody cares.
  • Auto types don't scale well to 1,000-line functions, and type declaration is blocked by the typedef reference feature.
  • Have to cast partial objects that are lazily initialised.

Improved hygiene

  • strictNullChecks forces some checks for undefined that are not obviously impossible.
  • strictNullChecks forces a few casts for undefineds that are obviously impossible (eg from queue.pop just after checking queue.length).
  • @param {number?} n doesn't make an optional parameter. @param {number} [n] and @param {number=} n do.
  • Too many arguments passed to a few different functions.
  • [].concat(x,y,z) has to be changed to [...x, y, ...z]

Found possible bug

  • Forgot to check result of String.match for null.
  • glimmer requires ASTPlugins to have a name property, but parser-postcss forgot to provide one.

Discussion

As you can see, there were lots of problems adding checkJs to prettier. None of them were particularly difficult to resolve, but there were a lot of small tasks that added up. Without strict null checks, there was only one bug and two hygiene items. Compare that to the whole pile of annoyances and incorrect errors.

Name resolution would crash when resolving a type name inside a
typedef's property tag.
@sandersn sandersn requested review from mhegazy and a user April 26, 2018 17:34
@mhegazy
Copy link
Contributor

mhegazy commented Apr 26, 2018

Auto types don't scale well to 1,000-line functions, and type declaration is blocked by the typedef reference feature.

what do you mean by not scaling?

@sandersn
Copy link
Member Author

The chance of doing something that confuses an auto type in a 1,000-line function approaches 1. In prettier, assignments plus each+lambda iteration confuse it.

If you had 100 10-line functions, each with an auto type, the number of constructs we don't handle would not be much higher, but you'd have many auto-typed variables with no problems.

@sandersn sandersn merged commit 1595f7f into master Apr 26, 2018
@sandersn sandersn deleted the add-prettier-user-test branch April 26, 2018 21:03
TheLarkInn added a commit to webpack/webpack that referenced this pull request May 3, 2018
TheLarkInn added a commit to webpack/webpack that referenced this pull request May 3, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
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.

2 participants