Tslint: サポートされている `no-unused-variable`ルールに対して警告が表示されます

作成日 2017年09月13日  ·  3コメント  ·  ソース: palantir/tslint

バグレポート

  • __TSLintバージョン__:
$ $(yarn bin)/tslint --version
5.7.0
  • __TypeScriptバージョン__:
$ $(yarn bin)/tsc --version
Version 2.5.2
  • __TSLintの実行__:CLI

実際の動作

既存のコードベースでtslintを実行しています。

私のプロジェクトにはno-unused-variableルールセットがあります(プリセットのようなパッケージを使用して)。

私のプロジェクトでは、TypeScriptでnoUnusedLocalsおよびnoUnusedParametersコンパイラオプションも有効になっています(これに対して、プリセットのようなパッケージを使用します)。

ルールを更新し、 tslint--fixオプションを実行して、コードを自動修正することがあります。

これには、 no-unused-variableルールの自動修正機能のメリットが含まれます。

コードベースでtslint --fixを実行したときの出力例:

$ $(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.

予想される行動

ここで述べたようにno-unused-variableルールは非推奨ではありません

ただし、警告は、ルールをまったく使用してはならないことを意味し、コンソールに多くの不要な出力を引き起こします。これにより、コード内の修正不可能な問題など、他の重要な情報が不明瞭になる可能性があります。

警告を削除しても大丈夫だと思います。

P3 Accepting PRs Bug

最も参考になるコメント

@destroyerofbuildsは良い点のように聞こえます-主に自動修正機能のためにno-unused-variableを使用しているので、警告は関係ありません。 警告を削除する必要があると思います(PRを受け入れます)。 この使用パターンを説明するために、ルールドキュメントも更新するとよいでしょう。

全てのコメント3件

私にとって、no-unused-variableは単に何もしません;(
バージョン5.7.0

これは私の設定です

{
    "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は良い点のように聞こえます-主に自動修正機能のためにno-unused-variableを使用しているので、警告は関係ありません。 警告を削除する必要があると思います(PRを受け入れます)。 この使用パターンを説明するために、ルールドキュメントも更新するとよいでしょう。

@tomitrescak TSLintをどのように実行していますか? これは、元の投稿とは別の問題のように聞こえます。 まだ開いていない場合は、別の問題を開くことをお勧めします。

このページは役に立ちましたか?
0 / 5 - 0 評価