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: improve unnecessary conditional, value is always falsy. #2043

Open
ImBIOS opened this issue Dec 17, 2024 · 1 comment · May be fixed by #2044
Open

bug: improve unnecessary conditional, value is always falsy. #2043

ImBIOS opened this issue Dec 17, 2024 · 1 comment · May be fixed by #2044

Comments

@ImBIOS
Copy link

ImBIOS commented Dec 17, 2024

Provide environment information

System:
OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 3.06 GB / 15.41 GB
Container: Yes
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.18.0 - ~/.proto/shims/node
Yarn: 3.4.1 - ~/.proto/shims/yarn
npm: 10.8.1 - ~/.proto/shims/npm
bun: 1.1.38 - ~/.bun/bin/bun
Watchman: 2024.12.02.00 - /home/linuxbrew/.linuxbrew/bin/watchman

Describe the bug

Any expression being used as a condition must be able to evaluate as truthy or falsy in order to be considered "necessary". Conversely, any expression that always evaluates to truthy or always evaluates to falsy, as determined by the type of the expression, is considered unnecessary.

Reproduction repo

if (!ctx.session || !ctx.session.user) {

To reproduce

here:

if (!ctx.session || !ctx.session.user) {

Additional information

Isn't this is better:

    if (!ctx.session?.user) {
@ImBIOS
Copy link
Author

ImBIOS commented Dec 17, 2024

This code is exist in a lot of this codebase

@ImBIOS ImBIOS changed the title bug: unnecessary conditional, value is always falsy. bug: improve unnecessary conditional, value is always falsy. Dec 17, 2024
@ImBIOS ImBIOS linked a pull request Dec 17, 2024 that will close this issue
3 tasks
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.

1 participant