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

Warning Displayed For Supported no-unused-variable Rule #3219

Closed
ghost opened this issue Sep 12, 2017 · 3 comments · Fixed by #3227
Closed

Warning Displayed For Supported no-unused-variable Rule #3219

ghost opened this issue Sep 12, 2017 · 3 comments · Fixed by #3227

Comments

@ghost
Copy link

ghost commented Sep 12, 2017

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.

@tomitrescak
Copy link

tomitrescak commented Sep 13, 2017

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
    }
}

@adidahiya
Copy link
Contributor

@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.

@adidahiya
Copy link
Contributor

@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.

adidahiya pushed a commit that referenced this issue Sep 20, 2017
Remove warning printed to console when a user of `tslint` is using the
`no-unused-variable` rule while also using the TypeScript compiler
with the `noUnusedLocals` and `noUnusedParameters` options set.

While it's not technically necessary to use the `noUnusedVariableRule`
rule with the TypeScript compiler options set, using this rule
is still useful when using the `--fix` option in `tslint` to
automatically remove unused variables.

Fixes #3219
@adidahiya adidahiya added this to the TSLint v5.8 milestone Sep 21, 2017
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this issue Apr 9, 2018
Remove warning printed to console when a user of `tslint` is using the
`no-unused-variable` rule while also using the TypeScript compiler
with the `noUnusedLocals` and `noUnusedParameters` options set.

While it's not technically necessary to use the `noUnusedVariableRule`
rule with the TypeScript compiler options set, using this rule
is still useful when using the `--fix` option in `tslint` to
automatically remove unused variables.

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

Successfully merging a pull request may close this issue.

2 participants