Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Stop using null unnecessarily in source code #490

Closed
JoshuaKGoldberg opened this issue Aug 13, 2018 · 2 comments
Closed

Stop using null unnecessarily in source code #490

JoshuaKGoldberg opened this issue Aug 13, 2018 · 2 comments
Labels
Difficulty: Hard Only someone with heavy experience in TSLint should be able to send a pull request for this issue. Domain: Tooling Repository tasks around improving source tooling. Status: Accepting PRs
Milestone

Comments

@JoshuaKGoldberg
Copy link

There are many places in source code that use null and undefined interchangeably. As a code cleanup task, it'd be nice to consolidate on only using undefined whenever possible. This is what most libraries do, including TSLint and TypeScript.

@JoshuaKGoldberg JoshuaKGoldberg added Status: Accepting PRs Difficulty: Hard Only someone with heavy experience in TSLint should be able to send a pull request for this issue. Domain: Tooling Repository tasks around improving source tooling. labels Aug 13, 2018
@reduckted
Copy link
Contributor

There's a number of places in the code where it's using x != null or x !== null. For example:

https://github.com/Microsoft/tslint-microsoft-contrib/blob/7e87ab24758fef21611d13091e74c55c4fc70a4e/src/chaiPreferContainsToIndexOfRule.ts#L64-L66

When dealing with strings, x === undefined would be required to keep the same behavior, but when dealing with objects, which of these is the preferred style?:

if (x) {
}

or

if (x !== undefined)

@JoshuaKGoldberg
Copy link
Author

which of these is the preferred style

It'd be nice to eventually also enable strict-boolean-expressions (#491), so the x !== undefined would be nice in that regard. I've been bitten by x equaling 0 enough times to be wary of if (x).

However, if it makes it easier and less prone to bugs _(considering the many places where variables are * | null | undefined, if (x) should be fine to start here. We can always do another pass-through before enabling strict-boolean-expressions.

JoshuaKGoldberg pushed a commit that referenced this issue Oct 16, 2018
* Used undefined instead of null.

Fixes #490.

* Enabled no-null-keyword in recommended ruleset.

* Changed rule options back to use null instead of undefined.
@JoshuaKGoldberg JoshuaKGoldberg added this to the 6.0.0-beta0 milestone Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Hard Only someone with heavy experience in TSLint should be able to send a pull request for this issue. Domain: Tooling Repository tasks around improving source tooling. Status: Accepting PRs
Projects
None yet
Development

No branches or pull requests

2 participants