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

bug: no-if doesn't work on nested ternary operators #557

Closed
benmonro opened this issue Apr 16, 2020 · 2 comments
Closed

bug: no-if doesn't work on nested ternary operators #557

benmonro opened this issue Apr 16, 2020 · 2 comments

Comments

@benmonro
Copy link
Contributor

benmonro commented Apr 16, 2020

just discovered that if a ternary is nested inside a function call it will not be reported:

a couple examples of things that are not reporting:

it("should foo", () => {
    const thing = () => (featureFlags.foo ? "foo" : "bar"); //should report
    expect(thing()).toBe("foo");

   expect(getByText(featureFlags.foo ? "foo" : "bar")).toBeInTheDocument() // should report
});
@G-Rath
Copy link
Collaborator

G-Rath commented Apr 27, 2020

For some reason I didn't seem to get a notification about this, but totally for the second one we should be erroring.

For the function however, I think we shouldn't (which is the current behaviour if you use an if).
This is because there are valid reasons to use a conditional in an it, such as in mocking:

listUsersMock.mockImplementation(async param => {
  const i = +(param.Marker ?? 0);
  const next = i + 1;

  return Promise.resolve({
    Users: [mockUsers[i]],
    Marker: mockUsers.length === next ? undefined : next.toString()
  });
});

Thats taken from an active project of mine - while I do have that in a beforeEach, it's perfectly valid to have in the actual test method; Arguably you shouldn't due to the extra complexity, but that's not what no-if is linting.

@G-Rath G-Rath closed this as completed in 4cfcf08 Jul 26, 2020
github-actions bot pushed a commit that referenced this issue Jul 26, 2020
## [23.18.2](v23.18.1...v23.18.2) (2020-07-26)

### Bug Fixes

* **no-if:** report conditionals in call expressions ([4cfcf08](4cfcf08)), closes [#557](#557)
@github-actions
Copy link

🎉 This issue has been resolved in version 23.18.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

3 participants