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

no-unused-variable interferes with other rules #3455

Closed
kevinbuhmann opened this issue Nov 5, 2017 · 9 comments
Closed

no-unused-variable interferes with other rules #3455

kevinbuhmann opened this issue Nov 5, 2017 · 9 comments

Comments

@kevinbuhmann
Copy link

kevinbuhmann commented Nov 5, 2017

Bug Report

  • TSLint version: 5.8.0
  • TypeScript version: 2.6.1
  • Running TSLint via: CLI

TypeScript code being linted

import { EventEmitter } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';

export const f1 = () => returnsVoid(); // error
export const obs1 = Observable.of(undefined).do(() => returnsVoid()); // error

export class Component {
  subject = new Subject<void>();
  event = new EventEmitter<void>();

  obs2 = Observable.of(undefined).do(() => this.subject.next()); // error
  obs3 = Observable.of(undefined).do(() => this.event.next()); // no error, but should be

  obs4 = Observable.of(undefined).do(this.subject.next); // error
  obs5 = Observable.of(undefined).do(this.event.next); // no error, but should be
}

function returnsVoid() { }

with tslint.json configuration:

{
  "rules": {
    "no-unused-variable": [
      true,
      "check-parameters", {
        "ignore-pattern": "^_"
      }
    ],
    "no-unbound-method": true,
    "no-void-expression": true
  }
}

Actual behavior

When the no-unused-variable variable is enabled, the no-void-expression rule does not report an
error on line 15 and the no-unbound-method rule does not report an error on line 18. But if you
disable the no-unused-variable rule, the no-void-expression and no-unbound-method rules
correctly reports all of the noted errors.

Expected behavior

The no-unused-variable rule should not interfere with other rules.

kevinbuhmann added a commit to kevinbuhmann/no-unused-variable-bug that referenced this issue Nov 5, 2017
@kevinbuhmann
Copy link
Author

kevinbuhmann commented Nov 5, 2017

Repro: https://github.com/kevinphelps/no-unused-variable-bug

git clone https://github.com/kevinphelps/no-unused-variable-bug.git
cd no-unused-variable-bug
yarn
yarn run lint

@kevinbuhmann
Copy link
Author

(did not mean to close the issue)

@kevinbuhmann kevinbuhmann changed the title no-void-expression misses errors when no-unused-variable is listed first no-unused-expression interferes with other rules Nov 5, 2017
@kevinbuhmann kevinbuhmann changed the title no-unused-expression interferes with other rules no-unused-variable interferes with other rules Nov 5, 2017
@ajafff
Copy link
Contributor

ajafff commented Nov 5, 2017

Duplicate of #2649 and #2736
Fix is available in #2763 but unlikely to be merged soon (if at all)

@ajafff ajafff closed this as completed Nov 5, 2017
@kevinbuhmann
Copy link
Author

Sorry about that...

@ajafff
Copy link
Contributor

ajafff commented Nov 5, 2017

Don't worry about that. The other issues were hard to find.
I just renamed one of them to make it easier to find.

@kevinbuhmann
Copy link
Author

I saw that. I thought I was an idiot until I saw the rename.

@kevinbuhmann
Copy link
Author

I would love to just enable the proper TypeScript settings and just remove no-unused-any, but I can't do that until I upgrade my project to Angular 5 to ngc issues. So my temporary workaround is to run the no-unused-any rule by itself and then run the rest in a separate process.

@ajafff
Copy link
Contributor

ajafff commented Nov 5, 2017

You mean the Parameter '$event' is declared but never used. error when compiling AOT?
You just need to disable --noUnusedParameters while still using --noUnusedLocals.
To still find unused parameters you can use the no-unused rule from my package tslint-consistent-codestyle: https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/no-unused.md

@kevinbuhmann
Copy link
Author

I'll give that a shot! Thanks!

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

No branches or pull requests

2 participants