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

ESLint Config Migration: Remove strict-boolean-expressions rule #1050

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

filmaj
Copy link
Contributor

@filmaj filmaj commented Aug 9, 2021

Summary

This is a PR that should be merged into #1024 and incrementally addresses #842.

This PR turns off the @typescript-eslint/strict-boolean-expressions rule. While on the surface the intention of the rule makes sense ("prevent implicit casting to Boolean of conditional expressions"), in practice this rule gets in the way.

Consider the following real example from this code base, from ExpressReceiver.spec.ts:

const verifier = verifySignatureAndParseRawBody(noopLogger, signingSecretFn || signingSecret);

The error raised by this line is:

  426:68   error    Unexpected value in conditional. A boolean expression is required  @typescript-eslint/strict-boolean-expressions

Essentially, any values taking part in a short-circuit logical operation (like || or &&) must be a boolean. Therefore, the common pattern seen in JS/TS of using || as a means of declaring default values would always be invalid.

My suggestions is to remove this rule, as it does not seem to allow for customization to avoid the above scenario, but what does everyone else think?

Impact

Before

✖ 362 problems (173 errors, 189 warnings)
  76 errors and 0 warnings potentially fixable with the `--fix` option.

After

✖ 358 problems (169 errors, 189 warnings)
  75 errors and 0 warnings potentially fixable with the `--fix` option.

Requirements (place an x in each [ ])

@filmaj filmaj added the tests M-T: Testing work only label Aug 9, 2021
@filmaj filmaj self-assigned this Aug 9, 2021
@filmaj filmaj force-pushed the no-strict-boolean-expressions branch from 8a6d062 to d0665c0 Compare August 10, 2021 00:27
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

no objection to disabling this - too inconvenient if we follow this rule

…s the use of short-circuit logical operators (|| and &&).
@filmaj filmaj force-pushed the no-strict-boolean-expressions branch from d0665c0 to a044e81 Compare August 23, 2021 17:08
@filmaj filmaj merged commit 475f03b into tslint-to-eslint Aug 23, 2021
@filmaj filmaj deleted the no-strict-boolean-expressions branch August 23, 2021 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests M-T: Testing work only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants