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

Feature Request - Show unused imports TypeScript #1063

Closed
3 tasks done
superheri opened this issue Jan 18, 2019 · 29 comments
Closed
3 tasks done

Feature Request - Show unused imports TypeScript #1063

superheri opened this issue Jan 18, 2019 · 29 comments

Comments

@superheri
Copy link

superheri commented Jan 18, 2019

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: Win 10 1809
  • Vetur version: 0.14.5
  • VS Code version: 1.31.0-insider

Problem

Unused imports are not shown in Vue Files like it is in VS Code TypeScrfipt files. Would be nice to have this to know which imports are not used and can be removed.

In a TS file :
image

In a Vue file :
image

Even if I never used lodash in my code the import is still shown the same color as other imports unlike in TS files.

Reproducible Case

Add whatever imports in a Vue files and don't use them.

@adamalfredsson
Copy link

I am looking for the same feature! Would help a lot!

@TimeBandit
Copy link

This would help our team too.

@essenmitsosse
Copy link

Have you tried adding "noUnusedLocals": true to compilerOptions in your tsconfig? This way the typescript complier handles unused variables (instead of just VS Code). For me this gives me a warning about unused variables and imports, even in .vue files.

@octref
Copy link
Member

octref commented Mar 14, 2019

Depends on #682. We are using TS 2.8 still and it doesn't have this feature yet.

@octref
Copy link
Member

octref commented Mar 24, 2019

Blocked by microsoft/language-server-protocol#500.

@octref octref added this to the March 2019 milestone Mar 26, 2019
@octref
Copy link
Member

octref commented Mar 26, 2019

image

Will be available in next version.

For <script>, you need to set checkJs to true is jsconfig/tsconfig, though.

@superheri
Copy link
Author

@octref Do we need checkJs even if we use tsconfig with <script lang="ts">?

@octref
Copy link
Member

octref commented Mar 26, 2019

No, lang="ts" works OOTB because the script type is typescript, so no check "js".

@superheri
Copy link
Author

Ok. Thanks a lot for this new feature!

@mengdi
Copy link

mengdi commented Apr 3, 2019

@octref It doesn't seem to work in v0.18.0 with <script lang="ts">.
@superheri Did you try this ?

@octref
Copy link
Member

octref commented Apr 3, 2019

image

@superheri
Copy link
Author

Does not work on my side too. I don't understand why...

@octref
Copy link
Member

octref commented Apr 3, 2019

@mengdi @superheri Can you use either https://github.com/octref/veturpack or vue-cli to create a minimal reproducible example?

@superheri
Copy link
Author

superheri commented Apr 4, 2019

In my big project at work with ~1250 files of JS/TS/Vue it can't seem to work. But in veturpack it seems to work though. I found a way to produce a bug with veturpack by changing the file client/views/Home.vue with this :

<template>
  <div class="page">
    <counter></counter>
  </div>
</template>

<script lang="ts">
import Counter from 'components/Counter'
import * as _ from 'lodash';
export default {
  components: {
    Counter
  }
}
</script>

As we can see in this image (You can use it at the same time as a proof I use Vetur 0.18.0) :

image

In this case even if we are not using the declared _ we still don't see the not used message.

I will try hard to reproduce more cases. I'll keep you updated with this.

EDIT : I just realized Counter.vue while adding lang="ts" reproduces it exactly.

@octref octref reopened this Apr 4, 2019
@octref octref closed this as completed Apr 4, 2019
octref added a commit to octref/veturpack that referenced this issue Apr 4, 2019
@octref
Copy link
Member

octref commented Apr 4, 2019

Hmm, I just realized that this works:

"vetur.useWorkspaceDependencies": true with Veturpack loading TS 2.9.2.

When using bundled TS 3.3 this breaks.

@octref
Copy link
Member

octref commented Apr 4, 2019

I see the problem. lang="ts" is not recognized as TS file...If you add checkJS: true to tsconfig/jsconfig this works.

@octref
Copy link
Member

octref commented Apr 4, 2019

We are looking at two issues here:

@octref octref closed this as completed Apr 4, 2019
@superheri
Copy link
Author

After testing and trying a way to reproduce the bug I have with my big project, I can't find a way to reproduce it on a minimalist case. Maybe it is a mix of multiple fonctionnalities that creates this bug. Or because it is so slow on big projects that Vetur become unstable.

@TimeBandit
Copy link

This issues is not resolved for us. We are using "typescript": "^3.3.4000" and <script lang="ts"> the unused imports in our Vue files are now underlined with red.

@octref
Copy link
Member

octref commented Apr 11, 2019

Please create a repro case and open new issues.

@douglasg14b
Copy link

douglasg14b commented Jun 5, 2020

Yeah, this feature doesn't work....

What is the actual resolution here? A reproduction case is literally any project with any .vue file that uses typecript. At least in my experience thus far.

@superheri
Copy link
Author

I can confirm this problems still happens to me. I haven't used Vetur in about a year, but when I got back to it some weeks ago, the problem was there... Seems like a regression at some point. Would be great if it could be fixed...

@undergroundwires
Copy link

Still does not work in 2021 😢

@LinusBorg
Copy link
Member

And it likely won't for you in 2022 if people continue to ignore requests by the maintainer for a reproduction.

It seems to work in most cases - works for me, for example. That's also why the issue is closed.

It seems, from what you folks indicate, to break under certain condition - conditions that you, the ones experiencing the problem, have to enable the maintainer to understand and reproduce.

So coming here and posting sad smiley will not help us fix this.

@LinusBorg
Copy link
Member

LinusBorg commented Jan 9, 2021

the default tsconfig in vue-cli projects isn't set up to report unused locals. just set it to do so (typescript docs will help you with that).

still not a bug.

@undergroundwires
Copy link

So the expected behavior is that it does not work without configuring noUnusedLocals 🤔. Apparently I have wrongly assumed that it was designed to lint visually regardless of the setting. In my opinion it would be better to not depend on the tsconfig and lint anyway. In the end it's not a bug then, thanks for clearing this out.

@LinusBorg
Copy link
Member

You can use eslint for that too

@undergroundwires
Copy link

In my case ESLint without noUnusedLocals does not work on ts in .Vue files but works in .ts files. Repro: vue create hello-world

@yoyo930021
Copy link
Member

Please open a new issue and provide a repro case next time.

I slove this problem in next version, because I just understand this problem.

undergroundwires added a commit to undergroundwires/privacy.sexy that referenced this issue Jan 26, 2021
LarrMarburger pushed a commit to LarrMarburger/privacy.sexy that referenced this issue Nov 16, 2023
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

10 participants