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

@typespec/prettier-plugin-typespec errors with Prettier 3.0.0 #2153

Closed
eddyashton opened this issue Jul 6, 2023 · 2 comments · Fixed by #2157
Closed

@typespec/prettier-plugin-typespec errors with Prettier 3.0.0 #2153

eddyashton opened this issue Jul 6, 2023 · 2 comments · Fixed by #2157
Assignees
Milestone

Comments

@eddyashton
Copy link
Member

Prettier 3.0.0 was released yesterday, and throws errors when attempting to format any TypeSpec files.

Looking at a minimised snippet from one of the samples:

// main.tsp
import "@typespec/versioning";
import "@typespec/rest";
import "./library.tsp";

using TypeSpec.Versioning;
using TypeSpec.Rest;

@service({
  title: "Pet Store Service",
})
@versioned(Versions)
namespace VersionedApi;
using TypeSpec.Http;

enum Versions {
  @useDependency(Library.Versions.`1.0`)
  v1,

  @useDependency(Library.Versions.`1.1`)
  v2,
}

And a simple Prettier config:

{
  "plugins": [
    "@typespec/prettier-plugin-typespec"
  ],
  "overrides": [
    {
      "files": "*.tsp",
      "options": {
        "parser": "typespec"
      }
    }
  ]
}

The plugin works with 2.8.7:

$ prettier --version
2.8.7

$ prettier --write main.tsp 
main.tsp 9ms

But throws errors with 3.0.0:

$ npx prettier --version
3.0.0

$ npx prettier --write main.tsp 
main.tsp
[error] main.tsp: InvalidDocError: Unexpected doc.type 'concat'.
[error] Expected it to be 'cursor', 'indent', 'align', 'trim', 'group', 'fill', 'if-break', 'indent-if-break', 'line-suffix', 'line-suffix-boundary', 'line', 'label', or 'break-parent'.
[error]     at traverseDoc (file:///data/src/2.CCF/node_modules/prettier/index.mjs:15105:13)
[error]     at propagateBreaks (file:///data/src/2.CCF/node_modules/prettier/index.mjs:15437:3)
[error]     at printDocToString (file:///data/src/2.CCF/node_modules/prettier/index.mjs:15842:3)
[error]     at coreFormat (file:///data/src/2.CCF/node_modules/prettier/index.mjs:18409:18)
[error]     at async formatWithCursor (file:///data/src/2.CCF/node_modules/prettier/index.mjs:18603:14)
[error]     at async formatFiles (file:///data/src/2.CCF/node_modules/prettier/internal/cli.mjs:6778:18)
[error]     at async main (file:///data/src/2.CCF/node_modules/prettier/internal/cli.mjs:6970:5)
[error]     at async Module.run (file:///data/src/2.CCF/node_modules/prettier/internal/cli.mjs:6924:5)
@timotheeguerin
Copy link
Member

I have a tentative PR #2157 adding support but I think there we also need to other plugins to update. In particular we are using sort-import plugin in our own repo and would need to be updated.

Updating to 3.0 is a decent breaking change and not sure we can keep back compat with prettier 2.0 which is also something to take into account.

@timotheeguerin
Copy link
Member

Ok so actually those concern above are not a problem, everything seems to work fine. Plugin is backward compatible with prettier 2.0(At least for now)

The main issue is the breaking change to the prettier api which cascade into our api of making format async. This ends up causing a breaking change in the emitter framework as well.

@timotheeguerin timotheeguerin self-assigned this Jul 10, 2023
@timotheeguerin timotheeguerin added this to the [2023] August milestone Jul 10, 2023
timotheeguerin added a commit that referenced this issue Aug 4, 2023
fix #2153

This include breaking change if using the typespec formatter
programatically. Some breaking changes to prettier carry over
https://prettier.io/blog/2023/07/05/3.0.0.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants