Skip to content

Enforce use of non-strict equality (==/!=) when comparing to null #6543

@sstur

Description

@sstur

Right now I use eqeqeq to enforce strict (===) equality everywhere, except when comparing to null. That is great, but I actually want to go one step further and enforce non-strict (==) equality when comparing any value to null literal.

To put it another way, this will NOT currently throw any lint warning:

let foo;
console.log('is it null', foo == null);
console.log('is it really null', foo === null);

Those two statements are not easy to tell apart during code review. The issue can arise that a coder will use strict equality out of habit yet (in our codebase) they should always use loose equality when comparing to null in order to also catch undefined. Similar code will pass lint and pass tests and then later it might fail in production when undefined sneaks in somehow. I'd like to statically enforce loose equality for null.

Would you be open to a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions