Skip to content

Enhancement: [strict-boolean-expressions] Check array filter/find predicate functions as boolean locations. #8016

Closed
@Zamiell

Description

@Zamiell

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.

Description

The strict-boolean-expressions does not prevent the following bug:

const numbers: number[] = [];
const filteredNumbers = numbers.filter((element) => {
  return element; // BUG - SHOULD BE SOME KIND OF BOOLEAN COMPARISON!!!
});

This is because it does not examine function return values, it only examines comparisons.

Note that the no-unnecessary-condition rule is a similar rule, and it does support function return values. Thus, the function-examining logic needs to also be copy-pasted to this rule, so that this rule can catch the bug above.

For reference, the rule should be able to handle the following Array methods:

  • Array.every
  • Array.filter
  • Array.find
  • Array.findIndex
  • Array.findLast
  • Array.findLastIndex
  • Array.some

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked 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