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

真偽値しか受け付けないとこに真偽値以外のobjを書くとエラーになるようにしたい #1843

Open
Hiroshiba opened this issue Feb 11, 2024 · 0 comments

Comments

@Hiroshiba
Copy link
Member

内容

undfeindの判定とかでよくif (!obj)などと書くと思います。
意外とjavascriptはfalsyな物が多く、例えばobj=""obj=0でも!objがtrueになったりします。

最近この挙動が原因で意図しない挙動が発生している事例をちょくちょく見かけたので、バグ防止のために利用不可にしたいです。

三項演算子の真偽値のとこにnumberをそのままいれて0のときの挙動が変わった例
#1832 (comment)

Recordのkey有無チェックのつもりがvalueが空文字で巻き込まれた例
https://github.com/VOICEVOX/voicevox/pull/1822/files#r1485653465

Pros 良くなる点

バグが減らせると思う

Cons 悪くなる点

多少面倒になる・・・。

実現方法

ESLintのstrict-boolean-expressionsの導入?

その他

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

1 participant