Conflicts with prettier-plugin-ember-template-tag + eslint-plugin-prettier when linting gjs/gts files
See original GitHub issueI had a bug filed on my new project regarding an error being thrown when run via eslint + eslint-plugin-ember + eslint-plugin-prettier: https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/20
The further I delve into the issue, the more I think I might need help from this team to solve it, and that possibly the solution might involve changes to this repo rather than mine.
Repro: https://github.com/gitKrystan/simple-gjs-project/pull/2
This is the error thrown:
npm run lint:js
> gjs-project@0.0.0 lint:js
> eslint . --cache
Oops! Something went wrong! :(
ESLint: 7.32.0
SyntaxError: Invalid regular expression: /\b[__GLIMMER_\b/: Unterminated character class
at new RegExp (<anonymous>)
at /Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint-plugin-ember/lib/preprocessors/glimmer.js:121:34
at Array.map (<anonymous>)
at mapRange (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint-plugin-ember/lib/preprocessors/glimmer.js:106:20)
at Linter._verifyWithProcessor (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint/lib/linter/linter.js:1339:16)
at Linter._verifyWithConfigArray (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint/lib/linter/linter.js:1273:25)
at Linter.verify (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint/lib/linter/linter.js:1235:25)
at Linter.verifyAndFix (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint/lib/linter/linter.js:1428:29)
at verifyText (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint/lib/cli-engine/cli-engine.js:240:48)
at CLIEngine.executeOnFiles (/Users/krystanhuffmenne/Code/gjs-project/node_modules/eslint/lib/cli-engine/cli-engine.js:808:28)
First of all, it seems like there should be some escaping happening here: https://github.com/ember-cli/eslint-plugin-ember/blob/db745a3881686d50e486be67d6851d806ac770d6/lib/preprocessors/glimmer.js#L120
Because eslint-plugin-prettier runs Prettier as an ESLint rule, my plugin causes the Prettier ESLint rule to log the following violation message:
{
ruleId: "prettier/prettier",
severity: 2,
message: "Replace `[__GLIMMER_TEMPLATE(`⏎··<h1>···Hello·{{@who}}.·</h1>⏎`,·{·strictMode:·true·})];` with `<template><h1>·Hello·{{@who}}.·</h1></template>`",
line: 1,
column: 16,
nodeType: null,
messageId: "replace",
endLine: 3,
endColumn: 27,
}
Interestingly, the message has the preprocessed [__GLIMMER_TEMPLATE(
shenanigans when it probably should not. (Not sure yet if that because of something I am doing or because of something happening in this package).
As a result, the line linked above is generating new RegExp('\b[__GLIMMER_\b')
which indeed has an opening [
that the RegExp constructor interprets as the beginning of a character set.
I’ve noticed that this doesn’t always happen. For example, if I use the <template>
tag in the “top-level class” position, npm run lint:js
works properly (ish…it still has [__GLIMMER_TEMPLATE()]
in the message, and I think the line/column numbers might be off):
// works-ish.gjs
import Component from '@glimmer/component';
export default class MyComponent
extends Component {
<template>
<h1> Hello {{@who}}. </h1>
</template>
}
npm run lint:js
> gjs-project@0.0.0 lint:js
> eslint . --cache
Debugger attached.
/Users/krystanhuffmenne/Code/gjs-project/app/components/broken.gjs
2:1 error Delete `⏎` prettier/prettier
2:1 error Delete `⏎·` prettier/prettier
2:1 error Replace `⏎········[__GLIMMER_TEMPLATE(`⏎⏎⏎····<h1>···Hello·{{@who}}.·</h1>⏎··`,·{·strictMode:·true·})]` with `··<template><h1>·Hello·{{@who}}.·</h1></template>` prettier/prettier
✖ 3 problems (3 errors, 0 warnings)
Issue Analytics
- State:
- Created 10 months ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
@NullVoxPopuli I just released prettier-plugin-ember-template-tag 0.1.0 which should have all the fixes necessary. I also did a little spike to make sure the fix would actually be helpful for this library:
https://github.com/ember-cli/eslint-plugin-ember/compare/master...gitKrystan:gjs-prettier?expand=1
The tests are still failing, but things are way closer than they were before.
@gitKrystan sounds awesome! once you have that work released, I’ll get going on the fixes for eslint-plugin-ember