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
lin-ll
merged 7 commits into
ember-cli:master
from
hmajoros:hank/duplicate-token-refactor
Mar 14, 2023
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Mar 13, 2023
<template>
tag
NullVoxPopuli
approved these changes
Mar 13, 2023
There was a problem hiding this 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
lin-ll
approved these changes
Mar 14, 2023
lin-ll
changed the title
for lint errors on template tokens in gjs/gts files, display eslint error on opening
Fix issue with token mapping for lint errors on template tokens in gjs/gts files by displaying eslint error on the opening Mar 14, 2023
<template>
tag<template>
tag
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
- token mapping never handled multiple tokens, eg:
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.