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

[Bug] Prettier v3 Support #61

Closed
evoactivity opened this issue Jul 9, 2023 · 12 comments
Closed

[Bug] Prettier v3 Support #61

evoactivity opened this issue Jul 9, 2023 · 12 comments

Comments

@evoactivity
Copy link

evoactivity commented Jul 9, 2023

🐞 Describe the Bug

Trying to get this working in vs code, also seeing this error when running pnpm lint.

Sidenote, to get to this point I had to follow the tips in #38

🔬 Minimal Reproduction

Not sure how reproducible this is I'm not sure of the cause. As it shows up outside of vscode I don't think it's an editor specific issue.

Some probably relevant info

  • Working in a pnpm monorepo setup by turbo.
  • Fresh ember project (5.1.2)

😕 Actual Behavior

Will not run. Failing with assertExists failed and a stack trace of minified code.

🤔 Expected Behavior

Prettier is run.

🌍 Environment

  • prettier-plugin-ember-template-tag version: 0.3.2
  • ember-template-imports version: 3.4.2
  • prettier version: 3.0.0

➕ Additional Context

Output from VS Code

["INFO" - 12:52:44 AM] Formatting file:///Users/liam/Work/project/monorepo/apps/web/app/components/test-thing.gts
["INFO" - 12:52:44 AM] Using config file at '/Users/liam/Work/project/monorepo/apps/web/.prettierrc.js'
["INFO" - 12:52:44 AM] PrettierInstance:
{
  "modulePath": "/Users/liam/Work/project/monorepo/apps/web/node_modules/prettier/index.cjs",
  "importResolver": {},
  "callMethodResolvers": {},
  "currentCallMethodId": 2,
  "version": "3.0.0"
}
["INFO" - 12:52:44 AM] Using ignore file (if present) at /Users/liam/Work/project/monorepo/.prettierignore
["INFO" - 12:52:44 AM] File Info:
{
  "ignored": false,
  "inferredParser": "ember-template-tag"
}
["INFO" - 12:52:44 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 12:52:44 AM] Prettier Options:
{
  "filepath": "/Users/liam/Work/project/monorepo/apps/web/app/components/test-thing.gts",
  "parser": "ember-template-tag",
  "useTabs": false,
  "tabWidth": 2,
  "endOfLine": "lf",
  "semi": true,
  "singleQuote": true,
  "quoteProps": "consistent",
  "bracketSpacing": true,
  "arrowParens": "always",
  "printWidth": 120,
  "plugins": [
    "/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js"
  ],
  "importOrder": [
    "web",
    "^node:(.*)$",
    "^@glimmer/(.*)$",
    "^@ember/(.*)$",
    "<THIRD_PARTY_MODULES>",
    "^[./]"
  ],
  "importOrderSeparation": false,
  "importOrderSortSpecifiers": true,
  "importOrderGroupNamespaceSpecifiers": true,
  "importOrderCaseInsensitive": true,
  "importOrderParserPlugins": [
    "typescript",
    "[\"decorators\", { \"decoratorsBeforeExport\": true }]"
  ]
}
["ERROR" - 12:52:44 AM] Error formatting document.
["ERROR" - 12:52:44 AM] assertExists failed
Error: assertExists failed
    at Bp (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:1933:57639)
    at TA (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:1933:57698)
    at FM (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:2048:8267)
    at Object.preprocess (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:2048:11036)
    at parse (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:17076:43)
    at async coreFormat (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:18401:7)
    at async formatWithCursor (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:18603:14)
    at async Module.format2 (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:21789:25)
["INFO" - 12:52:44 AM] Formatting completed in 13ms.

Output from pnpm lint:js

$ pnpm lint:js           

> project-web@0.0.0 lint:js /Users/liam/Work/project/monorepo/apps/web
> eslint . --cache


Oops! Something went wrong! :(

ESLint: 8.44.0

Error: assertExists failed
    at Bp (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:1933:57639)
    at TA (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:1933:57698)
    at FM (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:2048:8267)
    at Object.preprocess (/Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier-plugin-ember-template-tag@0.3.2/node_modules/prettier-plugin-ember-template-tag/dist/prettier-plugin-ember-template-tag.js:2048:11036)
    at parse (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:17076:43)
    at async coreFormat (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:18401:7)
    at async formatWithCursor (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:18603:14)
    at async Module.format2 (file:///Users/liam/Work/project/monorepo/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/index.mjs:21789:25)
@evoactivity
Copy link
Author

evoactivity commented Jul 10, 2023

Downgrading prettier to 2.8.7 and eslint-plugin-prettier to 4.2.1 got it running. So seems to be an issue with prettier 3

@evoactivity evoactivity changed the title [Bug] assertExists failed [Bug] Prettier v3 Support Jul 10, 2023
@ef4
Copy link
Contributor

ef4 commented Jul 13, 2023

I looked into this a little bit. It's non-trivial.

The proximate cause of the failure is that assertExists( estreePrinter.hasPrettierIgnore ) fails because estreePrinter is now an async function that returns the printer, not the printer itself. There's not an obvious place to absorb the asynchrony right at that spot.

The call signature of embed has also changed so that:

printer.embed = (path, print, textToDoc, options) => {
  return stuff
}

becomes something like:

printer.embed = (path, options) => {
  return async (textToDoc, print) => {
    return stuff;
  }
}

@Techn1x
Copy link

Techn1x commented Jul 17, 2023

Hitting the same thing error on updating to prettier v3

There's not an obvious place to absorb the asynchrony right at that spot.

The code is within definePrinter function which is only consumed in the parser preprocess hook
https://github.com/gitKrystan/prettier-plugin-ember-template-tag/blob/c73e1d77aa8a34f102fae16bd1729dd8734b644e/src/parse.ts#L78C1-L79

prettier v3 says -> "Also, the preprocess method of a printer can return a promise now."
https://prettier.io/blog/2023/07/05/3.0.0.html#api

So I think that'll be the place.

@Techn1x
Copy link

Techn1x commented Jul 17, 2023

I've opened a draft PR here
#63

I am stuck on 2 types issues, if anyone could lend a hand. Else, feel free to use it as a guide for your own prettier v3 update

@gitKrystan
Copy link
Owner

I've been watching the status updates for Prettier v3 like 🙈 . Looks like it's here now. I'll try to look into this ASAP

@esbanarango
Copy link

Facing this same issue trying out ember-template-imports. This project already uses prettierV3.

index_gts_—_Untitled__Workspace_

@gitKrystan
Copy link
Owner

Just released prettier-plugin-ember-template-tag@1.0.0-0 with a fix for this issue. Can one of you try it out and LMK if everything is working properly with your set-up? After that I will release 1.0.0 for real.

@HeroicEric
Copy link

@gitKrystan that is working for me with prettier 3.0.0 🚀 🎉 🚀 🎉 🚀 🎉

@esbanarango
Copy link

Same here!!! That fix solved the issue.

(Now I'm blocked by #81 (comment) 😂 )

@evoactivity
Copy link
Author

Working for me. @gitKrystan Thanks for fixing this so quickly 😊

@gitKrystan
Copy link
Owner

Fixed as of v1.0.0 🎉

@Techn1x
Copy link

Techn1x commented Jul 26, 2023

works great for me as well. thanks for putting in the effort here to get it across the line! happily on prettier 3 now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants