Tslint: Warning Displayed For Supported `no-unused-variable` Rule

Created on 13 Sep 2017  ·  3Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__:
$ $(yarn bin)/tslint --version
5.7.0
  • __TypeScript version__:
$ $(yarn bin)/tsc --version
Version 2.5.2
  • __Running TSLint via__: CLI

Actual behavior

I'm running tslint over an existing code base.

My project has the no-unused-variable rule set (through the use of a preset-like package).

My project also has the noUnusedLocals and noUnusedParameters compiler options enabled for TypeScript (against, through the use of a preset-like package).

I occasionally update my rules and run tslint's --fix option to auto-fix my code.

That includes benefiting from the auto-fix feature of the no-unused-variable rule.

Example output when running tslint --fix on my code base:

$ $(yarn bin)/tslint --project tsconfig.json --config tslint.json --fix src/**/*.ts
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.
WARNING: 'no-unused-variable' lint rule does not need to be set if the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.

Expected behavior

As noted here the no-unused-variable rule was un-deprecated because users (including myself) benefit from the auto-fix feature.

However the warning implies that I shouldn't be using the rule at all, and causes a lot of unnecessary output to the console, which may obscure other important information such as un-fixable problems in the code.

I believe it would be alright removing the warning.

P3 Accepting PRs Bug

Most helpful comment

@destroyerofbuilds that sounds like a good point -- you're using no-unused-variable primarily for the auto-fix functionality, so the warning is irrelevant. I think we should remove the warning (accepting PRs). It would be nice to also update the rule docs to describe this usage pattern.

All 3 comments

To me, the no-unused-variable simply does not do anything ;(
Version 5.7.0

This is my config

{
    "extends": [
        "tslint:latest",
        "tslint-react",
        "tslint-config-prettier"
    ],
    "rules": {
        "ban-types": false,
        "interface-name": null,
        "interface-over-type-literal": false,
        "jsx-boolean-value": null,
        "jsx-no-lambda": null,
        "max-classes-per-file": [],
        "member-access": false,
        "no-namespace": null,
        "no-unused-expression": [false],
        "no-unused-variable": true,
        "no-var-requires": false,
        "object-literal-shorthand": false,
        "object-literal-sort-keys": false,
        "only-arrow-functions": null,
        "ordered-imports": null,
        "prefer-const": false,
        "variable-name": false,
        "no-invalid-template-strings": false,
        "no-submodule-imports": false
    }
}

@destroyerofbuilds that sounds like a good point -- you're using no-unused-variable primarily for the auto-fix functionality, so the warning is irrelevant. I think we should remove the warning (accepting PRs). It would be nice to also update the rule docs to describe this usage pattern.

@tomitrescak how are you running TSLint? That sounds like a separate issue from the original post; I would encourage you to open another issue if you haven't already.

Was this page helpful?
0 / 5 - 0 ratings