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

Fix issue with token mapping for lint errors on template tokens in gjs/gts files by displaying eslint error on the opening <template> tag #1801

Merged
merged 7 commits into from Mar 14, 2023

Conversation

hmajoros
Copy link
Contributor

@hmajoros hmajoros commented Mar 9, 2023

Background
when using ESLint with gts/gjs files and encountering a lint error specifically on a template token, the error maps to the private __GLIMMER_TEMPLATE scope syntax, and we need to re-map that back into the template. In previous iterations of trying to map these tokens back to the original source, there were a few issues encountered:

- token mapping was too eager, and would match the first instance of a token (even if it was part of a comment block)

// comment Foo <-- this gets caught
<template> <Foo /> </template> // <-- this doesn't

- token mapping never handled multiple tokens, eg:

<template>
  <Foo />
  <Foo /> {{! this one never gets reported by eslint }}
</template>

What does this PR do?
We decided it would be easier (and less bug-prone) to instead just map any eslint errors on scope tokens back to the opening template tag. These error messages are modified to be prefixed with Error in template: , and will still give the user a signal that something is wrong in their template. This code will also be more efficient than searching the code for specific instances of tokens and filtering out any instances determined to be contained inside of a comment block.

This PR updates the logic to handle reporting on scope tokens. If we get a diagnostic message from eslint which is on a scope token, we search backwards until we find the first <template> tag, then we re-print the error message on this line.

@hmajoros hmajoros changed the title fix issue with token detection eagerly matching the wrong instance of token for lint errors on template tokens in gjs/gts files, display eslint error on opening <template> tag Mar 13, 2023
lib/preprocessors/glimmer.js Fixed Show resolved Hide resolved
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. let's shippit

lib/preprocessors/glimmer.js Fixed Show resolved Hide resolved
@bmish bmish added the Bug label Mar 14, 2023
@lin-ll lin-ll changed the title for lint errors on template tokens in gjs/gts files, display eslint error on opening <template> tag Fix issue with token mapping for lint errors on template tokens in gjs/gts files by displaying eslint error on the opening <template> tag Mar 14, 2023
@lin-ll lin-ll merged commit db6cd55 into ember-cli:master Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants