gitKrystan / prettier-plugin-ember-template-tag

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

plugin is parsing JS comments and throws errors #84

Open hmajoros opened 1 year ago

hmajoros commented 1 year ago

JS comments are being parsed by the plugin, and if the plugin finds invalid syntax, it throws errors. This is common in our codebase when people write example usages of a component invocation, and it even catches on some JSDoc comments. really, any JS comment with {{ will attempt to be parsed by the plugin.

example: this JSDoc comment with a type annotation containing an object, which looks like a double-curly template invocation:

  /**
   * Error message from loading the suggestions and whether the user can retry.
   * @type {{ errorMessage: string, canRetry: boolean} | undefined }}
   */

this breaks the prettier plugin

✖ yarn prettier:
[error] packages/addons/profile-shared/addon/components/generated-suggestions/generated-suggestion-edit-view.gjs: SyntaxError: Unexpected token (544:9)
[error]   542 |
[error]   543 |
[error] > 544 |  export default [__GLIMMER_TEMPLATE(`{{!voyager-i18n-resource}}
[error]       |         ^
[error]   545 | {{t-def "Original" key="i18n_original"}}
[error]   546 | {{t-def "Dismiss" key="i18n_dismiss"}}
[error]   547 | {{t-def "Something went wrong. Please try again." key="failure_toast"}}

something about the double-curly in the comment block is throwing off prettier, because when i delete that line it works fine

recommendation: just don't parse the contents of JS comment blocks

Originally posted by @hmajoros in https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/42#issuecomment-1611418303

gitKrystan commented 1 year ago

Thanks @hmajoros .

I won't be able to look into this for a few weeks, but if someone has time to investigate, I'd look into...

...to see what the root cause is.

gitKrystan commented 4 months ago

Can you confirm this is still an issue with the latest version?