Only show no-undef errors for templates in gts files#1852
Only show no-undef errors for templates in gts files#1852bmish merged 4 commits intoember-cli:masterfrom
no-undef errors for templates in gts files#1852Conversation
c889e14 to
32b1910
Compare
|
Can tests be added? Thanks! Also, is no-undef really the only lint we care about? 😅 |
|
Yes, according to this comment: |
|
hmm I wrote that. 🙃 Sounds good then -- ping when you push up some tests or if you have any questions -- will be good to get this merged! |
|
@NullVoxPopuli @bmish its now ready, the tests would now fail without the change in glimmer.js |
|
Nice, lgtm then. @bmish , can you approve the workflow run? |
lib/preprocessors/glimmer.js
Outdated
| return flattened.map((message) => { | ||
| const filtered = flattened.filter( | ||
| (it) => | ||
| it.ruleId === 'no-undef' || |
There was a problem hiding this comment.
Can you comment to explain why no-undef is the only rule included here?
There was a problem hiding this comment.
Is the logic here "ember-template-lint should give us errors from inside a template context"?
are we certain there will not be other eslint rules written in the future that may require us to update this logic?
There was a problem hiding this comment.
I think it's the only rule that makes sense on a transformed code. The only thing i can think of is when template-lint would become a eslint plugin
There was a problem hiding this comment.
@hmajoros exactly -- the only thing template-lint can't know about is what is in scope -- so the template-lint equiv of no-undef is disabled for gjs/gts
There was a problem hiding this comment.
Waiting for a comment to be added about this.
There was a problem hiding this comment.
There is a comment here already:
There was a problem hiding this comment.
Should i move it down to this code?
There was a problem hiding this comment.
I think two improvements would help:
- Update the comment to explain why we need to "allow-list the rules that check for undefined identifiers".
- Move the rule name into an array with a descriptive name like:
const RULES_THAT_FOO = ['no-undef'];This name is self-documenting and an array would be reusable and easily expandable. Something to this effect.
lib/preprocessors/glimmer.js
Outdated
|
|
||
| const TRANSFORM_CACHE = new Map(); | ||
| const TEXT_CACHE = new Map(); | ||
| const RULE_CACHE = new Map(); |
There was a problem hiding this comment.
Can you add some high-level comment(s) explaining what's going on and why?
There was a problem hiding this comment.
maybe the naming is not ideal. how about TEMPLATE_RANGE_CACHE. it saves the template range so we can know which eslint messages are inside the template ranges in the postprocessing step
There was a problem hiding this comment.
i moved the whole thing to postprocessing, as the cache is not really needed
7939052 to
909d1bc
Compare
|
@bmish i pushed a fix, tests are passing. |
|
mmm, i will rework this to use the DocumentLines utils from my other PR, which makes the check more easier. |
lib/preprocessors/glimmer.js
Outdated
| // eslint rules that check for undefined identifiers | ||
| // this are the only rules we want to check within a template |
There was a problem hiding this comment.
I still would like to see an explanation for why this is the only rule we care about.
There was a problem hiding this comment.
there is here:
.. Should i add an explanation here too? Like
"Because otherwise eslint would show errors unrelated to the original code and apply autofixes like spacing, comna etc into the template"
There was a problem hiding this comment.
Any where we could clarify comments is appreciated. I will leave it to your and @NullVoxPopuli's judgment.
There was a problem hiding this comment.
things look good from over here
|
@bmish fixed, tests pass, full coverage |
| * @typedef {{ line: number; character: number }} Position | ||
| */ | ||
|
|
||
| class DocumentLines { |
There was a problem hiding this comment.
Can you add a high-level comment to this class/file explaining what it's for and where this comes from? Does it need tests? Need to make sure the "what" and "why" is clear for all this new code for someone unfamiliar with the feature.
There was a problem hiding this comment.
It comes from here: https://github.com/typed-ember/glint/blob/main/packages/core/src/language-server/util/position.ts
And will also be used for
#1853
lib/preprocessors/glimmer.js
Outdated
| // this are the only rules we want to check within a template | ||
| // Because otherwise eslint would show errors unrelated to the original code and | ||
| // apply auto fixes like spacing, comma etc. into the original template | ||
| const RULES_THAT_CHECK_FOR_UNDEFINED_IDENTIFIERS = new Set(['no-undef']); |
There was a problem hiding this comment.
I know I suggested RULES_THAT_CHECK_FOR_UNDEFINED_IDENTIFIERS but then I realized it's a bad name since it could only ever apply to this one rule. Can we use a better name for this array that explains what kind of rules would qualify or what the array is used for?
no-undef errors for templates in gts files
|
Coverage was not enough. I think because of the document utility class. |
* master: (88 commits) Release 11.7.0 build(deps-dev): Bump @typescript-eslint/parser from 5.59.5 to 5.59.6 (ember-cli#1863) Account for only having template tag in `no-empty-glimmer-component-classes` rule (ember-cli#1866) Support autofix of numerical property access and ternary expressions in `no-get` rule (ember-cli#1865) Release 11.6.0 build(deps-dev): Bump prettier from 2.8.7 to 2.8.8 (ember-cli#1842) build(deps-dev): Bump @typescript-eslint/parser from 5.58.0 to 5.59.5 (ember-cli#1860) build(deps-dev): Bump @babel/eslint-parser from 7.21.3 to 7.21.8 (ember-cli#1856) build(deps-dev): Bump markdownlint-cli from 0.33.0 to 0.34.0 (ember-cli#1848) build(deps-dev): Bump jquery from 3.6.4 to 3.7.0 (ember-cli#1861) build(deps-dev): Bump release-it from 15.10.1 to 15.10.3 (ember-cli#1859) build(deps): Bump vm2 from 3.9.17 to 3.9.18 (ember-cli#1862) Support autofix in gts files (ember-cli#1853) Only show `no-undef` errors for templates in gts files (ember-cli#1852) Release 11.5.2 Fix a bug in autofixer and autofix additional cases with `firstObject and `lastObject` in `no-get` rule (ember-cli#1841) build(deps-dev): Bump eslint from 8.37.0 to 8.38.0 (ember-cli#1830) build(deps-dev): Bump @typescript-eslint/parser from 5.57.0 to 5.58.0 (ember-cli#1837) build(deps-dev): Bump typescript from 5.0.3 to 5.0.4 (ember-cli#1832) build(deps): Bump vm2 from 3.9.11 to 3.9.17 (ember-cli#1839) ...
this filters out any linting message that is within the template, except for the no-undef rule.
there are also errors like
Expected blank line between class members, which wrap the whole template block, which will be included