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
null vs undefined enforcement? #138
Comments
Thank you for your idea, @toddbluhm. I would like this project to take a stance, yes. Standard does aim to provide choices, even if they're not clear cut and need to just be made. And by extension, this project. I personally use
Sounds reasonable to me. What about when those For implementation, can
I feel that it's better to make decisions before it gets popular. There's precedent in Standard JS where the authors refrain from making changes that would affect most projects. For example, I would really like dangling commas. |
I also personally have used The above link also discusses using I hear you on the dangling commas, but that is part of why I like |
Just wanted to chime in with what I personally do here; I always use I find that this works best, especially when dealing with null propagation. (e.g. This is especially necessary when dealing with GraphQL where you often have deep queries where values can either be returned null from the server, or they might be undefined because you haven't fetched the parent object yet. The same when you have a list that might be null, and want to get the first element: For me it is very uncommon to actually need to differ between I think that enforcing a project to never use |
While we may have our preferences or even attempt to enforce in projects we participate in, this does not seem like a likely candidate for this project, for practical reasons. Would you mind if it is closed? |
I completely agree. This definitely does not fit with broader standard philosophy of getting out of people’s way. |
I just wanted to bring this up, not as a huge debate, but more something to consider with typescript standard. Since typescript has types, this is possibly something we could better enforce here rather than in just the plain
standard
utility.When I was refactoring my OSS project https://github.com/toddbluhm/env-cmd to use this shared config, I ran into the age-old issue of do I check for
null
or do I check forundefined
or do I check for both when refactoring for thestrict boolean expressions
. Is that something this config could/should take a stance on?I know for the official typescript repo they only allow
undefined
https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#null-and-undefined. Perhaps this shared standard config could take a similar stance?It looks like someone has already built a plugin for it here: https://www.npmjs.com/package/eslint-plugin-no-null
Now my opinion on how the rule would work if enforced would be essentially to disallow any new usage of
null
in favor ofundefined
, but to still allow 3rd-party libraries and certain built-in utilities likeJSON.parse
to still returnnull
types since those cannot be changed.I am just trying to start this discussion to see what thoughts or opinions are out there. Perhaps this shared config is just too young to take a strong stance either way and needs more traction before tackling such a big debate?
The text was updated successfully, but these errors were encountered: