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

refactor glimmer post-process, better handle template tag #1795

Merged
merged 7 commits into from Mar 9, 2023

Conversation

hmajoros
Copy link
Contributor

@hmajoros hmajoros commented Mar 2, 2023

refactor postprocessing of template placeholders and re-map back to source more appropriately.

This PR makes many changes based on the assumption that the number of lines in the original code equals the number of lines in the transformed code. The code now throws an error if this assumption is not met. With this assumption in place, a lot of mapping from transformed -> original becomes a lot simpler: for a lint error on line X, when the original source content at line X matches the transformed source content at line X, we can return the original diagnostic message with no changes.

The remainder of the work in this PR is around mapping placeholder template values ([__GLIMMER_TEMPLATE back into its original form of <template>, and adjusting the column field in the diagnostic to match the changes. Same goes for the "closing tag" placeholder.

We still currently use the error prone "find token and loop through source" method when the diagnostic "token" is inside a template tag, but there is a failing test (commented out currently) which exhibits how this code is currently broken.

Other big change here is to generally add support for multiline lint errors, which never existed in the original implementation.

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.

Nice improvements!

lib/preprocessors/glimmer.js Outdated Show resolved Hide resolved
lib/preprocessors/glimmer.js Show resolved Hide resolved
// defined. the `token` should be the specific template API which the error is on,
// so we need to find the usage of the token in the template

// TODO: this is still bug-prone, and should be refactored to do something like:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we kinda have two options to making this less bug prone:

tests/lib/rules-preprocessor/gjs-gts-processor-test.js Outdated Show resolved Hide resolved
lib/preprocessors/glimmer.js Outdated Show resolved Hide resolved
Co-authored-by: Lucy Lin <lucy.ly.lin@gmail.com>
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

3 participants