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

Only show no-undef errors for templates in gts files #1852

Merged
merged 4 commits into from May 12, 2023

Conversation

patricklx
Copy link
Contributor

@patricklx patricklx commented May 4, 2023

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

@patricklx patricklx force-pushed the patch-1 branch 3 times, most recently from c889e14 to 32b1910 Compare May 4, 2023 13:53
@NullVoxPopuli
Copy link
Contributor

Can tests be added? Thanks!

Also, is no-undef really the only lint we care about? 😅

@patricklx
Copy link
Contributor Author

Yes, according to this comment:

// value and allow-list the rules that check for undefined identifiers

@NullVoxPopuli
Copy link
Contributor

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!

@patricklx
Copy link
Contributor Author

@NullVoxPopuli @bmish its now ready, the tests would now fail without the change in glimmer.js

@NullVoxPopuli
Copy link
Contributor

Nice, lgtm then. @bmish , can you approve the workflow run?

return flattened.map((message) => {
const filtered = flattened.filter(
(it) =>
it.ruleId === 'no-undef' ||
Copy link
Member

Choose a reason for hiding this comment

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

Can you comment to explain why no-undef is the only rule included here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think @NullVoxPopuli should answer :)

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@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

Copy link
Member

Choose a reason for hiding this comment

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

Waiting for a comment to be added about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a comment here already:

// value and allow-list the rules that check for undefined identifiers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should i move it down to this code?

Copy link
Member

@bmish bmish May 10, 2023

Choose a reason for hiding this comment

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

I think two improvements would help:

  1. Update the comment to explain why we need to "allow-list the rules that check for undefined identifiers".
  2. 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.

@@ -8,6 +8,7 @@ const util = require('ember-template-imports/src/util');

const TRANSFORM_CACHE = new Map();
const TEXT_CACHE = new Map();
const RULE_CACHE = new Map();
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some high-level comment(s) explaining what's going on and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i moved the whole thing to postprocessing, as the cache is not really needed

@patricklx patricklx force-pushed the patch-1 branch 2 times, most recently from 7939052 to 909d1bc Compare May 10, 2023 07:26
@patricklx
Copy link
Contributor Author

patricklx commented May 10, 2023

@bmish i pushed a fix, tests are passing.
Edit: ah... Lint is failing

@patricklx
Copy link
Contributor Author

mmm, i will rework this to use the DocumentLines utils from my other PR, which makes the check more easier.
just noticed the check is not completely correct, would be easier to test with offsets.

Comment on lines 31 to 32
// eslint rules that check for undefined identifiers
// this are the only rules we want to check within a template
Copy link
Member

Choose a reason for hiding this comment

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

I still would like to see an explanation for why this is the only rule we care about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is here:

// we could accidentally have this line formatted with
.
. 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"

Copy link
Member

Choose a reason for hiding this comment

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

Any where we could clarify comments is appreciated. I will leave it to your and @NullVoxPopuli's judgment.

Copy link
Contributor

Choose a reason for hiding this comment

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

things look good from over here

@patricklx
Copy link
Contributor Author

@bmish fixed, tests pass, full coverage

* @typedef {{ line: number; character: number }} Position
*/

class DocumentLines {
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// 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']);
Copy link
Member

Choose a reason for hiding this comment

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

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?

@bmish bmish changed the title only show no-undef errors for templates in gts files Only show no-undef errors for templates in gts files May 11, 2023
@patricklx
Copy link
Contributor Author

Coverage was not enough. I think because of the document utility class.
Can we disable the coverage for the document utility? It has a function which i do not use now. But i use it in the other pr.
I can try to enable it there again

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

Thanks, merging to unblock #1853.

@bmish bmish merged commit 558dab3 into ember-cli:master May 12, 2023
8 checks passed
@patricklx patricklx deleted the patch-1 branch May 12, 2023 17:18
bmish added a commit to bmish/eslint-plugin-ember that referenced this pull request May 21, 2023
* 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)
  ...
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