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
+157
−51
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.