Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-unused-expression gives lint error on expressions like o && o.foo() #1413

Closed
gmoothart opened this issue Jul 18, 2016 · 3 comments
Closed

Comments

@gmoothart
Copy link

Bug Report

  • TSLint version: 3.13.0
  • TypeScript version: 1.8.10
  • Running TSLint via: CLI

TypeScript code being linted

  let el: ng.IAugmentedJQuery;
  ...
  afterEach(() => {
    el && el.remove();
  });

with tslint.json configuration:

{
    "rules": {
        "no-unused-expression": true
    }
}

Actual behavior

test.ts[67, 5]: expected an assignment or function call - on the line el && el.remove();

Expected behavior

I expected this to not produce any errors. It seems like a valid usage and perfectly readable.

@IllusionMH
Copy link
Contributor

IllusionMH commented Aug 14, 2016

Something like a && <call expression> or even a && b && ... && <call expression> are easy to fix.

@adidahiya, @jkillian is there any need for support of a || <call expression> or different combinations with parenthesis something like (a || required('a')) && (b || required('b'))?

UPS. Seems like there already is issue #1169 related to support of || in this rule.

@jkillian
Copy link
Contributor

It's a little tricky, because someObj.someFunc() may not have side-effects and the expression may actually be unused. However, I'd okay with a feature that allows the use cases you mentioned above @IllusionMH.

(Sidenote: what's the correct term for a function that is without side-effects but not necessarily pure?)

@IllusionMH
Copy link
Contributor

Fixed with #1638allow-fast-null-checks option added.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants