question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conflicts with prettier-plugin-ember-template-tag + eslint-plugin-prettier when linting gjs/gts files

See original GitHub issue

I 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:open
  • Created 10 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gitKrystancommented, Nov 16, 2022

@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.

1reaction
NullVoxPopulicommented, Nov 15, 2022

@gitKrystan sounds awesome! once you have that work released, I’ll get going on the fixes for eslint-plugin-ember

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · ember-cli/eslint-plugin-ember - GitHub
Conflicts with prettier-plugin-ember-template-tag + eslint-plugin-prettier when linting gjs/gts files. #1659 opened on Nov 7 by gitKrystan.
Read more >
How to make ESLint work with Prettier avoiding conflicts and ...
ESLint is a JavaScript linting utility which performs static analysis in order to find problematic patterns or code that doesn't adhere to ...
Read more >
ESLint rule conflicts with Prettier rule - Stack Overflow
I am copy-pasting those. In the .vscode/settings.json file : { // config related to code formatting "editor.defaultFormatter": ...
Read more >
Linting in TypeScript using ESLint and Prettier - LogRocket Blog
Integrate Prettier with ESLint to automate type-checking in your TypeScript code and ensure that the code has no bugs.
Read more >
eslint-plugin-prettier - npm
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found