Visual Studio Find Unused Code



  1. Visual Studio Code Find Unused Code Typescript
  2. Visual Studio Code Find Unused Variables
  3. C# Find Unused Code
  4. Visual Studio 2019 Find Unused Code

Automatically find all exports in typescript and javascript files which are not imported in other files.

The complication comes from trying to detect variables that are 'unused' within code, but is used in other domains (e.g. Visualforce, Lightning). For Lightning (Aura and LWC), variables whose names are dimmed are not used. For example: Here, you can see the event parameter is unused. Visual studio code has released a new feature last year in April in 2018 which allow users to change their settings to remove unused imports automatically on save. The Remove Unused Usings option in the Visual Studio user interface removes using directives, using aliases, and extern aliases that are not used in the source code. There are two ways to call the operation: Main Menu - On the Edit menu, point to IntelliSense, point to Organize Usings, and then click Remove Unused. Unused variable detection - Unused variables are grayed-out in your JavaScript/TypeScript files. Move to new file refactoring - Easily pull classes and functions into their own files. Update imports on move/rename - Automatically update import paths in JavaScript/TypeScript. Find-unused README Find and delete unused static resource, press F1 or ctrl+shift+p, then enter findUnused find to find unused static files, then the files will be listed in unused.md. Check the file list carefully and delete the line that the file you still need.

Features

  • Automatically find all exports and imports in .ts and .tsx files
  • Automatically find all exports and imports in .js and .jsx files, if tsconfig.json allows for .js files in project
  • All imports from node modules are ignored
  • Configurable display of results as expanded or collapsed
  • If tsconfig.json defines baseUrl, it will resolve all imports using paths relative to baseUrl
  • A file having all exports not used will be marked as 'not used' and a delete button will be available
  • If there are no unused exports, then the panel will display an entry saying this
  • Can detect circular imports, which produce undefined variables by import
    • Only the first set of circular imports for a file is displayed in panel (for clarity of the circular path)

Usage

This extension has its own panel. The symbol of this panel is a ban sign with two arrows (see bellow).

Open the panel and the extension will start the scan of the project. If you made changes to the files, the extension will not detect these to avoid unnecessary scans. You can force a rescan using the reload button found at top right of the panel.

If there are no unused exports, the panel will display a single entry saying this.

Visual Studio Find Unused Code

Screenshot

Bellow you can see the list of unused exports found in the currently opened project as are they displayed by this extension:

Requirements

There are no special requirements.

Extension Settings

  • findUnusedExports.defaultResultExpanded:

    • Find unused exports: show all found results initially expanded (otherwise collapsed)
    • default false
  • findUnusedExports.debug:

    • Find unused exports: log all actions in an output window
    • default false
  • findUnusedExports.showIgnoredExports

    • Find unused exports: show all unused exports, even if they are marked as ignored
    • default false
  • findUnusedExports.detectCircularImports

    • Find unused exports: detect circular imports
    • default false

Known Issues

For the moment there are no known issues.

Note: If the main/entry file has exports then this extension marks it as 'not used' and allows you to remove it. Hence, please check before deleting any file if it is the main/entry file.

Studio

Change Log

See Change Log here

UnusedVisual studio code find unused code typescript

Issues

Code

Submit an issue if you find any bug or have any request.

Contribution

Fork the repo and submit pull requests.

-->

This refactoring applies to:

  • C#
  • Visual Basic

What: Fades out unused parameters and generates a warning for unused expression values. The compiler also performs a flow analysis to find any unused value assignments. Unused value assignments fade out and a light bulb appears with a Quick Action to remove the redundant assignment. Unused variables with unknown values show a Quick Action suggestion to use discards instead. (Discards are temporary, dummy variables that are intentionally unused in application code. They can reduce memory allocation and make your code easier to read.)

When: You have value assignments, parameters, or expression values that are never used.

Visual Studio Code Find Unused Code Typescript

Why: Sometimes it's difficult to tell if a value assignment, variable, or parameter is no longer being used. By fading out these values or generating a warning, you get a visual cue of what code you can delete.

Visual Studio Code Find Unused Variables

Unused expression values and parameters diagnostic

C# Find Unused Code

  1. Have any value assignment, variable, or parameter that isn't used.
  2. The unused value assignment or parameter appears faded out. The unused expression value generates a warning.

Visual Studio 2019 Find Unused Code

See also