Tslint: no-unused-variable does not remove unused imports with --fix

Created on 18 Apr 2018  路  3Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.8.1
  • __Running TSLint via__: CLI

TypeScript code being linted

import { Bar } from './Bar';
import { Baz } from './Baz';
import { Foo } from './Foo';

console.log(Foo, Bar, /* Baz */);

with tslint.json configuration:

{
    "defaultSeverity": "error",
    "extends": [],
    "jsRules": {},
    "rules": {
        "no-unused-variable": true
    },
    "rulesDirectory": []
}

Command line:

tslint -p ./tsconfig.json -c ./tslint.json --fix

Actual behavior

ERROR: C:/Workspaces/VSC/tslint-no-unused-variable/index.ts[2, 1]: 'Baz' is declared but its value is never read.

Expected behavior

Import for Baz removed in source file, as suggested here: https://palantir.github.io/tslint/rules/no-unused-variable/

In addition to avoiding compilation errors, this rule may still be useful if you wish to have tslint automatically remove unused imports, ... when using TSLint鈥檚 --fix option.

Sample project

https://github.com/andraaspar/tslint-no-unused-variable

Fixed Bug Rule Enhancement

Most helpful comment

would love this to avoid removing around 90 instances manually :D

All 3 comments

would love this to avoid removing around 90 instances manually :D

I was experiencing the same issue in one of my projects, but it works for me after upgrading tslint:

typescript: 2.9.2
tslint: 5.9.1 (does not work), 5.10.0 (works), 5.11.0 (also works)

This should work now with the latest TSLint and TypeScript. 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

cateyes99 picture cateyes99  路  3Comments

denkomanceski picture denkomanceski  路  3Comments

Ne-Ne picture Ne-Ne  路  3Comments

jacob-robertson picture jacob-robertson  路  3Comments