Note: for support questions, please use one of these channels:
https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/
Lint task is throwing many "All imports are unused." kind of error after upgrading to 1.3.8. Some error are false positives.
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:
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)
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"
]
}
Same here.
I've read that using typescript 2.4 solves it for tslint.
Unfortunately Typescript 2.4 is incompatible is RxJS5...
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.
I have the same trouble. Ionic team why you didnt test carefully packages before release them?
Unfortunately, the same issue of many unused import warnings occurs with current app-scripts v. 2.0.2
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
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:
```myfile.ts
// tslint:disable: no-unused-variable
import {a, b,c } from 'something'
// tslint:enable: no-unused-variable
@Component({...}) ...
```
@AlejandroSilva what do intend wirh re-enable after all imports are done.
The imports are all fine, tslints warning is justieren wrong.
Same issue with version 2.1.0
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
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);
Per a comment here, removing declare var * from declarations.d.ts resolved this issue for me.
@jczaplew Thanks for that.... for me it was removing declare module '*' from declarations.d.ts.
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.
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.
Yeah, just remove 'src/declarations.d.ts' file. That did the trick. Thanks a LOT. One less problem in my life.
Yes removing src/declarations.d.ts worked. We can close this issue.
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.
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
how to remove this declaration.d.ts file???????
@Aqib33 right click + delete ?
i mean where is this file please guide
@mebibou ??ill be able to delete only if i know where it is & how to do it
@Aqib33 I think it was in the src folder before, but if you dont see it, then it's probably not there.
its not there ;( please tell some, im stuck
@Aqib33 if you have a specific problem, then either go to stackoverflow or create a new issue, this is not a Q&A
please help me i am stuck
allmodules are unused , im trying to use geolocation ,
please brother
On Sat, Jan 20, 2018 at 12:03 AM, Guillaume notifications@github.com
wrote:
@Aqib33 https://github.com/aqib33 I think it was in the src folder
before, but if you dont see it, then it's probably not there.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ionic-team/ionic-app-scripts/issues/1052#issuecomment-359059099,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ah9dzUrGjUso0f4l0KN-G6n1hT4-Z1dYks5tMOb7gaJpZM4OCsdQ
.
Most helpful comment
Yeah, just remove 'src/declarations.d.ts' file. That did the trick. Thanks a LOT. One less problem in my life.