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

no-if rule doesn't work in many cases #1026

Closed
CreativeTechGuy opened this issue Jan 14, 2022 · 5 comments · Fixed by #1027
Closed

no-if rule doesn't work in many cases #1026

CreativeTechGuy opened this issue Jan 14, 2022 · 5 comments · Fixed by #1027

Comments

@CreativeTechGuy
Copy link

The jest/no-if rule has a bug which results in it failing to find conditions in many cases.

This pops from the stack whenever a call expression ends yet this only adds to the stack when specific call expression start.

This results in more items being popped off than pushed.

Example:

test("shows error", () => {
    if (1 === 2) {
        expect(true).toBe(false);
    }
});

test("does not show error", () => {
    setTimeout(() => console.log("noop"));
    if (1 === 2) {
        expect(true).toBe(false);
    }
});

The inner function in the second example causes the stack to be popped off one too many times and so by the time it arrives at the condition, the stack is empty when it shouldn't be.

I believe there are also other cases where this can occur as when debugging I often see it attempting to pop off the stack several times despite the stack being empty.

@G-Rath
Copy link
Collaborator

G-Rath commented Jan 14, 2022

Ironically I was looking at this code the other day when writing this new rule (iirc) and thinking "wait, isn't that check incorrect...?" 😅

@G-Rath
Copy link
Collaborator

G-Rath commented Jan 14, 2022

I've "fixed" this by creating a new rule to replace no-if, which just doesn't allow any conditionals in tests: #1027

@github-actions
Copy link

github-actions bot commented Feb 6, 2022

🎉 This issue has been resolved in version 26.1.0-next.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@G-Rath
Copy link
Collaborator

G-Rath commented Feb 7, 2022

This was closed in v26.1.0 but the bot didn't pick it up 😅

@G-Rath G-Rath closed this as completed Feb 7, 2022
@G-Rath G-Rath added the released label Feb 7, 2022
@SimenB
Copy link
Member

SimenB commented Feb 8, 2022

it's due to rebase merge, so the bot lost track of the connection between the commit that landed in the PR that closed this issue and the one that landed on main (PR link in commit title is not enough)

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

Successfully merging a pull request may close this issue.

3 participants