gitKrystan / prettier-plugin-ember-template-tag

A prettier plugin for formatting Ember template tags
MIT License
22 stars 12 forks source link

[Bug] Prettier v3 Support #61

Closed evoactivity closed 1 year ago

evoactivity commented 1 year ago

🐞 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 https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/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

πŸ˜• Actual Behavior

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

πŸ€” Expected Behavior

Prettier is run.

🌍 Environment

βž• 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 commented 1 year ago

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

ef4 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I've opened a draft PR here https://github.com/gitKrystan/prettier-plugin-ember-template-tag/pull/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 commented 1 year ago

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 commented 1 year ago

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

index_gts_β€”_Untitled__Workspace_
gitKrystan commented 1 year ago

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 commented 1 year ago

@gitKrystan that is working for me with prettier 3.0.0 πŸš€ πŸŽ‰ πŸš€ πŸŽ‰ πŸš€ πŸŽ‰

esbanarango commented 1 year ago

Same here!!! That fix solved the issue.

(Now I'm blocked by https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/81#issuecomment-1650560485 πŸ˜‚ )

evoactivity commented 1 year ago

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

gitKrystan commented 1 year ago

Fixed as of v1.0.0 πŸŽ‰

Techn1x commented 1 year ago

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