8000 Bug: [strict-boolean-expressions] autofix can be incorrect with allowNullableObject set to false · Issue #7743 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
Bug: [strict-boolean-expressions] autofix can be incorrect with allowNullableObject set to false #7743
Closed as not planned
@barroudjo

Description

@barroudjo

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.2&fileType=.tsx&code=LAKAxg9gdgzgLgAgGYQgIwIYCcEF4EYwCeUYCAFEgK6kD8AXBQJR4B8CUVANly7uwG9QCBJFiIkASygYuAMRplcwkckUIAPhpUjy5Pu048mAbhVYApnCpYoyabIWl9ZkAF8TQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYkACAXAngA4oDG0AlobgLQrzkB2uA9MrhSTQEYD2PSAQwa0AHoWgpk5Hg1QYA2pETRoPaJAA0mcBCgD48HgHcAyu0YBzdGABm%2B5Ig06IkfYaMA5WAFsuy63bwDk66egbGXgYCXEgA8lwAVoicAfaOzmHukfDRSABCfIIMqUHpoa7hngg5MYhmFAxWGIHBGRVZ1bmIXr7%2BzWkhuu0RnbUAogw%2BJa3lbsYAggz402VDc0YASgiIACo8WwwA6uS4ABY8sLj15JzZAMKnyQDWyACSANIMxoenAriv828ABEeJYVhkIABfAC6kJAkKAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const foobar = async (func?: () => null) => {
  const finalFunc =
    func ||
    (() => null);
  return finalFunc();
};

ESLint Config

module.exports = {
  "rules": {"@typescript-eslint/strict-boolean-expressions": ["error", {
    "allowString": false,
    "allowNumber": false,
    "allowNullableObject": false,
    "allowNullableBoolean": false,
    "allowNullableString": false,
    "allowNullableNumber": false,
    "allowNullableEnum": false,
    "allowAny": false,
    "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": false
      }]}
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

The auto fix introduces a bug in this case, as it replaces func || (() => null); with func != null || (() => null); which is now either a boolean or a function, when the original code was such that it always resulted in a function.

In this case there should be no auto fix, or the actual fix is to use nullish coalescing (func ?? (() => null);), but that seems a bit beyond the scope of this rule...

Actual Result

The auto fix introduces a bug in this case, as it replaces func || (() => null); with func != null || (() => null); which is now either a boolean or a function, when the original code was such that it always resulted in a function.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingduplicateThis issue or pull request already existslocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0