Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(template-parser): visit receiver of Call expression #1887

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

Merged
merged 3 commits into from
Aug 25, 2024

Conversation

P4
Copy link
Contributor

@P4 P4 commented Jun 14, 2024

When traversing a Call AST node, ESLint would never visit its receiver/callee. Since Call didn't have visitor keys listed explicitly, the parser would use getFallbackKeys, which seems to be buggy as it only returns args and not receiver.

Update test cases for no-call-expression to deal with new call expressions being reported.

Since convertAnnotatedSourceToFailureCase doesn't deal well with overlapping errors at the moment, instances of ()() were removed from existing tests and added as separate cases for nested calls.

Closes #1885

Copy link

nx-cloud bot commented Jun 30, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d26bbcb. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@P4 P4 force-pushed the fix/call-receiver branch from 376100f to 5d55eed Compare July 4, 2024 15:52
@P4
Copy link
Contributor Author

P4 commented Jul 23, 2024

Hi, any info on this? I've updated the PR after nx run eslint-plugin-template:check-rule-docs failed to include the updated docs by running yarn update-rule-docs as instructed, and it's been sitting like this since

@JamesHenry
Copy link
Member

@P4 rule tests are now more strictly typed after a large scale refactoring was needed to bring us up to the lates typescript-eslint v8 stable in #1956

The latest CI run fails on this one and it looks to be related to the stricter types, please could you take a look?

@P4 P4 force-pushed the fix/call-receiver branch from 415c31d to 65088f8 Compare August 1, 2024 08:07
@P4
Copy link
Contributor Author

P4 commented Aug 1, 2024

I've rebased the changes on top of the most recent main and slightly changed my workaround for overlapping errors to make it pass typechecking

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.73%. Comparing base (7b98fc9) to head (d26bbcb).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1887   +/-   ##
=======================================
  Coverage   91.73%   91.73%           
=======================================
  Files         181      181           
  Lines        3401     3401           
  Branches      552      552           
=======================================
  Hits         3120     3120           
  Misses        144      144           
  Partials      137      137           
Flag Coverage Δ
unittest 91.73% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...n-template/tests/rules/no-call-expression/cases.ts 100.00% <ø> (ø)
packages/template-parser/src/index.ts 85.10% <ø> (ø)

];

// convertAnnotatedSourceToFailureCase unfortunately cannot handle multiple errors starting/ending at the same position;
Copy link
Member

Choose a reason for hiding this comment

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

It's our own utility, so feels a little weird to add a comment saying "unfortunately cannot handle". Can we make it handle it? 🤔

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 looked at the implementation, but only briefly, I didn't really want this PR to turn into a side-quest of re-writing a test utility to handle just these few cases.

If you feel that it's worthwhile, I can try and implement the necessary changes.

Copy link
Member

Choose a reason for hiding this comment

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

It's a unit test utility right, so a super fast feedback loop - if the existing tests and the new tests pass then the patch is "correct" :)

If it bogs you down for a long time then let me know, but it's definitely worth giving it a go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I think I've managed to finally figure it out - this hack is no longer necessary and the other tests didn't break.

The code for processing annotated cases assumed the code would always be at line-1, but this is not true if we have multiple lines of annotations, I changed it to instead keep track of the last non-annotation line and use that for setting start and end line positions

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Once we address the point around the error utility this is good to go, thanks so much!

@P4 P4 force-pushed the fix/call-receiver branch from 70d0f78 to e2a9278 Compare August 22, 2024 10:36
Paweł Maniecki added 3 commits August 22, 2024 13:36
When traversing a Call AST node, ESLint would never visit its receiver/callee.
Since Call didn't have visitor keys listed explicitly, the parser would use `getFallbackKeys`,
which seems to be buggy as it only returns `args` and not `receiver`.

Update test cases for no-call-expression to deal with new call expressions being reported.

Since convertAnnotatedSourceToFailureCase doesn't deal well with overlapping errors at the moment,
instances of `()()` were removed from existing tests and added as separate cases for nested calls.

Closes angular-eslint#1885
follow-up to 4292d10, fixes an identical problem with calls like
`foo?.()` which are represented as a separate node type.
…line

rewrite the parseInvalidSource to keep track of last non-annotation line instead of assuming it's
always the previous line.

enables writing test cases with multiple errors starting/ending at the same position in code
@P4 P4 force-pushed the fix/call-receiver branch from e2a9278 to d26bbcb Compare August 22, 2024 11:36
Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Thanks a lot, @P4!

@JamesHenry JamesHenry merged commit 709a2c4 into angular-eslint:main Aug 25, 2024
7 checks passed
JamesHenry added a commit that referenced this pull request Aug 25, 2024
@JamesHenry
Copy link
Member

JamesHenry commented Aug 25, 2024

@P4 I'm afraid I'm not sure what happened with this one, but the tests are not passing, so I have reverted it on main. Please can you recreate the PR and we can take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

receiver of Call expression is skipped during AST traversal
2 participants