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

feat(eslint-plugin): [strict-bool-expr] add allowSafe option #1385

Conversation

Rajin9601
Copy link
Contributor

Fixes #1025

allowSafe allows non-falsey types (i.e. non string / number / boolean) to be used as boolean expressions.

This option allows user to safely check null & undefined without having to explicitly write obj == null when used with allowNullable.

// as-is
const str = obj == null && obj.foo == null && obj.foo.bar

// to-be
const str = obj && obj.foo && obj.foo.bar

Note that setting allowNullable & allowSafe to true allows boolean | null as a boolean expression, which is not safe.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Rajin9601!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Dec 28, 2019
Copy link
Member

@armano2 armano2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bradzacher bradzacher added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Dec 31, 2019
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
3 participants