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

feat: fix false negatives in no-this-before-super #17762

Merged
merged 9 commits into from Jan 26, 2024

Conversation

ota-meshi
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Fixes #17605

This PR fixes some false negatives in the no-this-before-super rule.

Is there anything you'd like reviewers to focus on?

@ota-meshi ota-meshi requested a review from a team as a code owner November 15, 2023 04:42
@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Nov 15, 2023
Copy link

netlify bot commented Nov 15, 2023

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit bf26f82
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/65aef47d82085f0008bb0dde
😎 Deploy Preview https://deploy-preview-17762--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Tanujkanti4441 Tanujkanti4441 added rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 15, 2023
Comment on lines 218 to 222
/*
* Traverse the segments in order starting from the first segment
* and check for `this` used before `super()`.
*/
while (segmentStack.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we maybe try to fix CodePath#traverseSegments() instead of reimplementing it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this PR to fix traverseSegments 👍

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 15, 2023
Comment on lines +261 to +268
class A extends B {
constructor() {
while (foo) {
this.a();
super();
}
}
}`,
Copy link
Member

Choose a reason for hiding this comment

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

This was another, unrelated false negative, caused by how onCodePathSegmentLoop was implemented in this rule?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems you're right. This false negative does not seem to be related to the traverseSegments bug. Should I do a different PR?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can include it in this PR, just wanted to make sure I understood the problem correctly.

@mdjermanovic mdjermanovic changed the title fix: false negatives in no-this-before-super feat: fix false negatives in no-this-before-super Nov 20, 2023
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Nov 20, 2023
visited.add(segment);


// Skips the segment if itself or all previous segments have been skipped.
const skip = skipped.has(segment) ||
Copy link
Member

Choose a reason for hiding this comment

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

Can skipped.has(segment) ever be true at this point?

@@ -59,6 +60,7 @@ function getOrderOfTraversing(codePath, options, callback) {
callback(segment, controller); // eslint-disable-line n/callback-return -- At end of inner function
}
});
debug.dumpDot(codePath);
Copy link
Member

Choose a reason for hiding this comment

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

Was this intentionally committed or maybe left over from debugging?

Comment on lines 277 to 279
skipped.size > 0 &&
segment.prevSegments.length > 0 &&
segment.prevSegments.every(prevSegment => skipped.has(prevSegment))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this logic works well when there are loops afterwards. For example:

const codePath = parseCodePaths("a; while (b) { c; }")[0];
const order = getOrderOfTraversing(codePath, null, (segment, controller) => {
    if (segment.id === "s1_1") {
        controller.skip();
    }
});

assert.deepStrictEqual(order, ["s1_1"]); // actual result is ["s1_1", "s1_2", "s1_3", "s1_4"] but it should be just ["s1_1"]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the review and finding the bug!
I fixed the issues.

Copy link

github-actions bot commented Dec 1, 2023

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Dec 1, 2023
@ota-meshi ota-meshi removed the Stale label Dec 1, 2023
@nzakas
Copy link
Member

nzakas commented Dec 8, 2023

@ota-meshi are you still working on this?

@ota-meshi
Copy link
Member Author

I would like to work on this PR. But right now, I'm prioritizing other PR.

Copy link

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Would like @mdjermanovic to review before merging.

visited.add(segment);


// Skips the segment if all previous segments have been skipped.
const skip = (
Copy link
Member

Choose a reason for hiding this comment

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

Maybe shouldSkip would be clearer for this variable name?

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit 26093c7 into eslint:main Jan 26, 2024
17 checks passed
@ota-meshi ota-meshi deleted the fix-no-this-before-super branch January 26, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Bug: no-this-before-super false negative
4 participants