New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3.8 - Lint task is throwing many "All imports are unused." #1052

Closed
hardikns opened this Issue Jun 22, 2017 · 27 comments

Comments

Projects
None yet
@hardikns

hardikns commented Jun 22, 2017

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

Lint task is throwing many "All imports are unused." kind of error after upgrading to 1.3.8. Some error are false positives.

What behavior are you expecting?

Such false positives should not appear. Not sure if this is issue with tslint version 5.2 or something I need to set in the tslint.json

Steps to reproduce:

  1. Create a simple ionic project with one file as under:
  2. Do ionic serve

Sample code below causes
ERROR: ..../src/utils/translate-utils.ts[1, 1]: All imports are unused.

translate-utils.ts:

import { Http } from '@angular/http';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';


export function createTranslateLoader(http: Http) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

export function _(s:string) {
  return s;
}

tslint.json:

{
  "rules": {
    "no-duplicate-variable": true,
    "no-unused-variable": [
      true
    ]
  },
  "rulesDirectory": [
    "node_modules/tslint-eslint-rules/dist/rules"
  ]
}

Which @ionic/app-scripts version are you using?
1.3.8

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

@kensodemann

This comment has been minimized.

Show comment
Hide comment
@kensodemann

kensodemann Jul 1, 2017

I got this as well when going from v1.3.7 to v1.3.12. After finding your post I verified that indeed the issue would occur when going from v1.3.7 to v1.3.8. Plenty of false positives with "no-unused-variable": true

I haven't found a solution, but as a work-around, I went to an angular-cli project that I have and copied the rules from there, leaving out the codelyzer specific rules. The rules used for that project do not include no-unused-variables but do include a lot more formatting stuff. This had the added benefit of catching some places where I had gotten sloppy with spacing or placement of braces.

FWIW, turning no-unused-variable checking on in the angular-cli project had a similar effect with lots of false positives, so I am guessing that there is an issue with tslint and/or TypeScript language services, but that is only a guess on my part.

Here is what my tslint.json is for now:

{
  "rules": {
        "callable-types": true,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "import-blacklist": [true, "rxjs"],
    "import-spacing": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "label-position": true,
    "max-line-length": [
      true,
      140
    ],
    "member-access": false,
    "member-ordering": [
      true,
      "static-before-instance",
      "variables-before-functions"
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-variable": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-eval": true,
    "no-inferrable-types": true,
    "no-shadowed-variable": true,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": true,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": true,
    "semicolon": [
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "typeof-compare": true,
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ]
  },
  "rulesDirectory": [
    "node_modules/tslint-eslint-rules/dist/rules"
  ]
}

kensodemann commented Jul 1, 2017

I got this as well when going from v1.3.7 to v1.3.12. After finding your post I verified that indeed the issue would occur when going from v1.3.7 to v1.3.8. Plenty of false positives with "no-unused-variable": true

I haven't found a solution, but as a work-around, I went to an angular-cli project that I have and copied the rules from there, leaving out the codelyzer specific rules. The rules used for that project do not include no-unused-variables but do include a lot more formatting stuff. This had the added benefit of catching some places where I had gotten sloppy with spacing or placement of braces.

FWIW, turning no-unused-variable checking on in the angular-cli project had a similar effect with lots of false positives, so I am guessing that there is an issue with tslint and/or TypeScript language services, but that is only a guess on my part.

Here is what my tslint.json is for now:

{
  "rules": {
        "callable-types": true,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "import-blacklist": [true, "rxjs"],
    "import-spacing": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "label-position": true,
    "max-line-length": [
      true,
      140
    ],
    "member-access": false,
    "member-ordering": [
      true,
      "static-before-instance",
      "variables-before-functions"
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-variable": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-eval": true,
    "no-inferrable-types": true,
    "no-shadowed-variable": true,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": true,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": true,
    "semicolon": [
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "typeof-compare": true,
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ]
  },
  "rulesDirectory": [
    "node_modules/tslint-eslint-rules/dist/rules"
  ]
}
@akaztp

This comment has been minimized.

Show comment
Hide comment
@akaztp

akaztp Jul 4, 2017

Same here.
I've read that using typescript 2.4 solves it for tslint.
Unfortunately Typescript 2.4 is incompatible is RxJS5...

akaztp commented Jul 4, 2017

Same here.
I've read that using typescript 2.4 solves it for tslint.
Unfortunately Typescript 2.4 is incompatible is RxJS5...

@napcat

This comment has been minimized.

Show comment
Hide comment
@napcat

napcat Jul 18, 2017

I'm facing the same problem.

A lot of false positives. For example by simple importing OnInit and implement it in my class will trow an warning after the compilation saying the OnInt is not being used.

napcat commented Jul 18, 2017

I'm facing the same problem.

A lot of false positives. For example by simple importing OnInit and implement it in my class will trow an warning after the compilation saying the OnInt is not being used.

@esase

This comment has been minimized.

Show comment
Hide comment
@esase

esase Jul 18, 2017

I have the same trouble. Ionic team why you didnt test carefully packages before release them?

esase commented Jul 18, 2017

I have the same trouble. Ionic team why you didnt test carefully packages before release them?

@JaneDawson

This comment has been minimized.

Show comment
Hide comment
@JaneDawson

JaneDawson Jul 18, 2017

Unfortunately, the same issue of many unused import warnings occurs with current app-scripts v. 2.0.2

JaneDawson commented Jul 18, 2017

Unfortunately, the same issue of many unused import warnings occurs with current app-scripts v. 2.0.2

@napcat

This comment has been minimized.

Show comment
Hide comment
@napcat

napcat Jul 19, 2017

Yes, I'm also on 2.0.2 and having this issue.

global packages:
ionic/cli-utils : 1.5.0
Cordova CLI : 6.5.0
Ionic CLI : 3.5.0

local packages:
ionic/app-scripts : 2.0.2
ionic/cli-plugin-cordova : 1.4.1
ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android 6.2.2
Ionic Framework : ionic-angular 3.5.3

System:
Node : v6.11.1
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 5.3.0

napcat commented Jul 19, 2017

Yes, I'm also on 2.0.2 and having this issue.

global packages:
ionic/cli-utils : 1.5.0
Cordova CLI : 6.5.0
Ionic CLI : 3.5.0

local packages:
ionic/app-scripts : 2.0.2
ionic/cli-plugin-cordova : 1.4.1
ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android 6.2.2
Ionic Framework : ionic-angular 3.5.3

System:
Node : v6.11.1
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 5.3.0

@AlejandroSilva

This comment has been minimized.

Show comment
Hide comment
@AlejandroSilva

AlejandroSilva Jul 21, 2017

one trick to remove this warning in the import section of our .ts files, is disable temporary the rule 'no-unused-variable at the start of the file, and re-enable after all the imports are done:

// tslint:disable: no-unused-variable
import {a, b,c } from 'something'
// tslint:enable: no-unused-variable

@Component({...}) ...

source: https://palantir.github.io/tslint/usage/rule-flags/

AlejandroSilva commented Jul 21, 2017

one trick to remove this warning in the import section of our .ts files, is disable temporary the rule 'no-unused-variable at the start of the file, and re-enable after all the imports are done:

// tslint:disable: no-unused-variable
import {a, b,c } from 'something'
// tslint:enable: no-unused-variable

@Component({...}) ...

source: https://palantir.github.io/tslint/usage/rule-flags/

@mburger81

This comment has been minimized.

Show comment
Hide comment
@mburger81

mburger81 Jul 22, 2017

Contributor

@AlejandroSilva what do intend wirh re-enable after all imports are done.
The imports are all fine, tslints warning is justieren wrong.

Contributor

mburger81 commented Jul 22, 2017

@AlejandroSilva what do intend wirh re-enable after all imports are done.
The imports are all fine, tslints warning is justieren wrong.

@PiWiBardy

This comment has been minimized.

Show comment
Hide comment
@PiWiBardy

PiWiBardy Jul 26, 2017

Same issue with version 2.1.0

PiWiBardy commented Jul 26, 2017

Same issue with version 2.1.0

@daveywc

This comment has been minimized.

Show comment
Hide comment
@daveywc

daveywc Jul 31, 2017

I am getting the same issue on 2.0.2:

cli packages:

@ionic/cli-plugin-cordova       : 1.5.0 
@ionic/cli-plugin-ionic-angular : 1.4.0
@ionic/cli-utils                : 1.6.0
ionic (Ionic CLI)               : 3.6.0 

global packages:

Cordova CLI : 7.0.1

local packages:

@ionic/app-scripts : 2.0.2
Cordova Platforms  : android 6.2.2 ios 4.4.0 windows 4.4.3
Ionic Framework    : ionic-angular 3.5.3

System:

Android SDK Tools : 26.0.2
Node              : v8.1.2
OS                : Windows 10
npm               : 5.3.0

daveywc commented Jul 31, 2017

I am getting the same issue on 2.0.2:

cli packages:

@ionic/cli-plugin-cordova       : 1.5.0 
@ionic/cli-plugin-ionic-angular : 1.4.0
@ionic/cli-utils                : 1.6.0
ionic (Ionic CLI)               : 3.6.0 

global packages:

Cordova CLI : 7.0.1

local packages:

@ionic/app-scripts : 2.0.2
Cordova Platforms  : android 6.2.2 ios 4.4.0 windows 4.4.3
Ionic Framework    : ionic-angular 3.5.3

System:

Android SDK Tools : 26.0.2
Node              : v8.1.2
OS                : Windows 10
npm               : 5.3.0
@Blackbaud-SteveBrush

This comment has been minimized.

Show comment
Hide comment
@Blackbaud-SteveBrush

Blackbaud-SteveBrush Jul 31, 2017

I've seen this error fire when the imported class isn't being used appropriately. For example, if I import a class and use it as an interface, TSLint doesn't like it:

Fires the "All imports are unused":

import { MyClass } from './my-class';

export class AnotherClass {
  public instance: MyClass;
  constructor() {
    this.instance = {
        name: 'Dave'
    };
  }
}

Passes TSLint:

import { MyClass } from './my-class';

export class AnotherClass {
  public instance: MyClass;
  constructor() {
    this.instance = new MyClass();
    this.instance.name = 'Dave';
  }
}

So, essentially, the imported class isn't recognized as being used, if it's used incorrectly.

Edit:

In Angular 2x, the EventEmitter requires a type; if the type used is a class, you need to instantiate the returned value (otherwise, TSLint will think MyClass is never used). For example:

public myEmitter = new EventEmitter<MyClass>();
// ...
this.myEmitter.emit(new MyClass({ ... }));
// Or...
this.myEmitter.emit({ ... } as MyClass);

Blackbaud-SteveBrush commented Jul 31, 2017

I've seen this error fire when the imported class isn't being used appropriately. For example, if I import a class and use it as an interface, TSLint doesn't like it:

Fires the "All imports are unused":

import { MyClass } from './my-class';

export class AnotherClass {
  public instance: MyClass;
  constructor() {
    this.instance = {
        name: 'Dave'
    };
  }
}

Passes TSLint:

import { MyClass } from './my-class';

export class AnotherClass {
  public instance: MyClass;
  constructor() {
    this.instance = new MyClass();
    this.instance.name = 'Dave';
  }
}

So, essentially, the imported class isn't recognized as being used, if it's used incorrectly.

Edit:

In Angular 2x, the EventEmitter requires a type; if the type used is a class, you need to instantiate the returned value (otherwise, TSLint will think MyClass is never used). For example:

public myEmitter = new EventEmitter<MyClass>();
// ...
this.myEmitter.emit(new MyClass({ ... }));
// Or...
this.myEmitter.emit({ ... } as MyClass);
@jczaplew

This comment has been minimized.

Show comment
Hide comment
@jczaplew

jczaplew Aug 23, 2017

Per a comment here, removing declare var * from declarations.d.ts resolved this issue for me.

jczaplew commented Aug 23, 2017

Per a comment here, removing declare var * from declarations.d.ts resolved this issue for me.

@daveywc

This comment has been minimized.

Show comment
Hide comment
@daveywc

daveywc Aug 24, 2017

@jczaplew Thanks for that.... for me it was removing declare module '*' from declarations.d.ts.

daveywc commented Aug 24, 2017

@jczaplew Thanks for that.... for me it was removing declare module '*' from declarations.d.ts.

@josh-m-sharpe

This comment has been minimized.

Show comment
Hide comment
@josh-m-sharpe

josh-m-sharpe Aug 29, 2017

Also removed declare module '*' from declarations.d.ts and cleared a lot of this up for me. Worth noting declarations.d.ts is not generated in a new ionic project.

josh-m-sharpe commented Aug 29, 2017

Also removed declare module '*' from declarations.d.ts and cleared a lot of this up for me. Worth noting declarations.d.ts is not generated in a new ionic project.

@mebibou

This comment has been minimized.

Show comment
Hide comment
@mebibou

mebibou Sep 6, 2017

Yes the declaration.d.ts could be removed from ionic 3.3.0, per changelog:

Another optional step is to remove the src/declarations.d.ts file. This is a legacy file introduced early with ionic-angular projects to improve compatibility between TypeScript and third-party libraries. Due to improvements in TypeScript, this file is no longer necessary. By removing this file, the TypeScript compiler will be able to provide more accurate error messages for import statements.

I believe this issue can be closed.

mebibou commented Sep 6, 2017

Yes the declaration.d.ts could be removed from ionic 3.3.0, per changelog:

Another optional step is to remove the src/declarations.d.ts file. This is a legacy file introduced early with ionic-angular projects to improve compatibility between TypeScript and third-party libraries. Due to improvements in TypeScript, this file is no longer necessary. By removing this file, the TypeScript compiler will be able to provide more accurate error messages for import statements.

I believe this issue can be closed.

@rroque6428

This comment has been minimized.

Show comment
Hide comment
@rroque6428

rroque6428 Sep 6, 2017

Yeah, just remove 'src/declarations.d.ts' file. That did the trick. Thanks a LOT. One less problem in my life.

rroque6428 commented Sep 6, 2017

Yeah, just remove 'src/declarations.d.ts' file. That did the trick. Thanks a LOT. One less problem in my life.

@hardikns

This comment has been minimized.

Show comment
Hide comment
@hardikns

hardikns Oct 26, 2017

Yes removing src/declarations.d.ts worked. We can close this issue.

hardikns commented Oct 26, 2017

Yes removing src/declarations.d.ts worked. We can close this issue.

@hardikns hardikns closed this Oct 26, 2017

@josh-m-sharpe

This comment has been minimized.

Show comment
Hide comment
@josh-m-sharpe

josh-m-sharpe Oct 26, 2017

Seems inappropriate to close this since others can still run into this and now have to find a closed GitHub issue to resolve it.

Removing the file should be baked into an upgrade script.

josh-m-sharpe commented Oct 26, 2017

Seems inappropriate to close this since others can still run into this and now have to find a closed GitHub issue to resolve it.

Removing the file should be baked into an upgrade script.

@mburger81

This comment has been minimized.

Show comment
Hide comment
@mburger81

mburger81 Oct 31, 2017

Contributor

I have to import some JavaScript modules files like this
import Locomote from './assets/js/locomote.min';

removing declartion.d.ts file I run into this error:

Typescript Error
Module './assets/js/locomote.min' was resolved to '/abc/src/components/player/flash-player/assets/js/locomote.min.js', but '--allowJs' is not set.

Not sure which should be the right behavior of get TSLINT and custom js imports work together
 
Edit:
Adding allowJs to tsconfig.json does not resolve the problem and have other problems

Contributor

mburger81 commented Oct 31, 2017

I have to import some JavaScript modules files like this
import Locomote from './assets/js/locomote.min';

removing declartion.d.ts file I run into this error:

Typescript Error
Module './assets/js/locomote.min' was resolved to '/abc/src/components/player/flash-player/assets/js/locomote.min.js', but '--allowJs' is not set.

Not sure which should be the right behavior of get TSLINT and custom js imports work together
 
Edit:
Adding allowJs to tsconfig.json does not resolve the problem and have other problems

@Aqib33

This comment has been minimized.

Show comment
Hide comment
@Aqib33

Aqib33 Jan 19, 2018

how to remove this declaration.d.ts file???????

Aqib33 commented Jan 19, 2018

how to remove this declaration.d.ts file???????

@mebibou

This comment has been minimized.

Show comment
Hide comment
@mebibou

mebibou Jan 19, 2018

@Aqib33 right click + delete ?

mebibou commented Jan 19, 2018

@Aqib33 right click + delete ?

@Aqib33

This comment has been minimized.

Show comment
Hide comment
@Aqib33

Aqib33 Jan 19, 2018

i mean where is this file please guide

Aqib33 commented Jan 19, 2018

i mean where is this file please guide

@Aqib33

This comment has been minimized.

Show comment
Hide comment
@Aqib33

Aqib33 Jan 19, 2018

@mebibou ??ill be able to delete only if i know where it is & how to do it

Aqib33 commented Jan 19, 2018

@mebibou ??ill be able to delete only if i know where it is & how to do it

@mebibou

This comment has been minimized.

Show comment
Hide comment
@mebibou

mebibou Jan 19, 2018

@Aqib33 I think it was in the src folder before, but if you dont see it, then it's probably not there.

mebibou commented Jan 19, 2018

@Aqib33 I think it was in the src folder before, but if you dont see it, then it's probably not there.

@Aqib33

This comment has been minimized.

Show comment
Hide comment
@Aqib33

Aqib33 Jan 19, 2018

its not there ;( please tell some, im stuck

Aqib33 commented Jan 19, 2018

its not there ;( please tell some, im stuck

@mebibou

This comment has been minimized.

Show comment
Hide comment
@mebibou

mebibou Jan 19, 2018

@Aqib33 if you have a specific problem, then either go to stackoverflow or create a new issue, this is not a Q&A

mebibou commented Jan 19, 2018

@Aqib33 if you have a specific problem, then either go to stackoverflow or create a new issue, this is not a Q&A

@Aqib33

This comment has been minimized.

Show comment
Hide comment
@Aqib33

Aqib33 Jan 19, 2018

Aqib33 commented Jan 19, 2018

@mboneil10 mboneil10 referenced this issue Mar 15, 2018

Merged

Address lint #456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment