Skip to content

[no-unnecessary-condition] What's the point of ignoreRhs: false option? #1017

Closed
@ark120202

Description

@ark120202

I am probably missing something, but reading through all of comments in original PR (#699) I couldn't find a reason to include ignoreRhs option. It probably made sense for strict-boolean-expressions, but I can't think of any cases where I'd want return items.length && items[0].toUpperCase() to be reported, since there is no condition part.

At the same time I think RHS should always be reported when used in a condition, like:

function test(foo: { bar: true } | undefined) {
  if (foo && foo.bar) {}
  //         ^^^^^^^
}

(note: items.length && items[0].toUpperCase() from docs isn't correct example for this rule, since toUpperCase returns possibly falsy value)

EDIT: Actually, I think it might make sense for this to be behavior for strict-boolean-expressions as well. Looks like that option was added just to avoid breaking change, see palantir/tslint#4447.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeThis change will require a new major version to be releaseddefault rule optionsDiscussions about default rule optionspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions