Skip to content
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

TypeScript --noUnusedParameters and --noUnusedLocals flags #615

Closed
adzhiljano opened this issue Feb 22, 2017 · 8 comments
Closed

TypeScript --noUnusedParameters and --noUnusedLocals flags #615

adzhiljano opened this issue Feb 22, 2017 · 8 comments

Comments

@adzhiljano
Copy link

Hello, I am currently using tslint as a linter for my ts files and I was ignoring the ts file, generated by your awesome lib.
Now, tslint started to deprecate the unused varuable flag (Start to deprecate no-unused-variable rule) , because in newer versions of Typescript noUnusedParameters and noUnusedLocals flags have been added (Flag unused declarations with --noUnusedParameters and --noUnusedLocals)
If you set them to true and try to compile the ts file, generated by NSwag you will get at least:

  • error TS6133: 'caught' is declared but never used, when setting noUnusedParameters to true (caused by this)
  • error TS6133: 'RequestOptionsArgs' is declared but never used, when setting noUnusedLocals to true (caused by this)

As far as I can see the latest is caused, because it is used in the TransformOptionsMethod here

There might be some other errors, those are the onse I stumbled upon.
Thank you!

@RicoSuter
Copy link
Owner

Good find, is there a way to completely disable validation for a .ts document (there is already a comment for TSLint)?

@grovesNL
Copy link
Contributor

@RSuter You can't disable validation currently because it's at the TypeScript compiler level.

I have some changes in a branch to solve the particular issues here, but I couldn't send a PR last night because of the diff problem.

We'll probably want to go through the other clients besides Angular 2 and check those as well.

@RicoSuter
Copy link
Owner

Yes, we should fix all tpls

@adzhiljano
Copy link
Author

@RSuter Yes, you can skip the validation with TSLint for some files, but you shouldn't bother with TSLint, mostly because its usage is optional and the usage of the TS compiler is required : )

As @grovesNL said, those flags are now part of the Typescript compiler itself. You can disasble the validation if you set them to false(the default values), but you can't disable them for some files. So It's either on or off for all of your ts files. As I said, and as @grovesNL pointed out, there might be some other problems (due to some other flags in the TS compiler config) and in other TS templates from(I posted this issue just for the Angular2 template).

We could start with min NSwag configuration, generate all of the possible TS templates and then run them with through the TS compiler with max strictness options. Something like:

"compilerOptions": {
...
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
...
  }

@grovesNL
Copy link
Contributor

I'll try to look at this soon. #563 is related to noImplicitAny too.

@RicoSuter
Copy link
Owner

Maybe we should also improve the integration tests so that the generated TS outputs are compiled and linted... Currently I regenerate the integration svcs and only check the diff...

grovesNL added a commit to grovesNL/NSwag that referenced this issue Feb 26, 2017
grovesNL added a commit to grovesNL/NSwag that referenced this issue Feb 26, 2017
RicoSuter added a commit that referenced this issue Feb 26, 2017
@RicoSuter
Copy link
Owner

Can we close this one?

@adzhiljano
Copy link
Author

Very good job, @RSuter , @grovesNL . Thank you very much!

This issue is resolved, so you can close it now : )

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

No branches or pull requests

3 participants