ts-prune vs ts-unused-exports
TypeScript Code Analysis Tools Comparison
1 Year
ts-prunets-unused-exports
What's TypeScript Code Analysis Tools?

TypeScript code analysis tools help developers identify and manage unused code within their projects, enhancing code quality and maintainability. These tools analyze TypeScript files to detect exports and declarations that are not utilized anywhere in the codebase, allowing developers to clean up their code and reduce bloat. By removing unused code, teams can improve readability, reduce bundle sizes, and streamline the development process. Both 'ts-prune' and 'ts-unused-exports' serve this purpose but differ in their approach and features.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
ts-prune236,9202,05046.4 kB33 years agoMIT
ts-unused-exports193,596762141 kB423 months agoMIT
Feature Comparison: ts-prune vs ts-unused-exports

Scope of Analysis

  • ts-prune:

    ts-prune analyzes the entire project to identify all unused exports, regardless of their location in the codebase. This makes it ideal for comprehensive cleanup tasks, especially in larger applications where unused exports can accumulate over time.

  • ts-unused-exports:

    ts-unused-exports focuses on detecting unused exports in TypeScript files, providing a more targeted analysis. It is particularly effective for smaller projects or specific modules where you want to quickly identify and remove unused exports.

Integration

  • ts-prune:

    ts-prune can be easily integrated into build processes or CI/CD pipelines, allowing for automated checks for unused exports during development. This ensures that code quality is maintained continuously without manual intervention.

  • ts-unused-exports:

    ts-unused-exports can also be integrated into build processes, but it is often used as a quick command-line tool for on-the-fly checks. This makes it convenient for developers who want to quickly scan files without setting up extensive configurations.

Output Format

  • ts-prune:

    ts-prune provides a clear output of unused exports, indicating the specific files and lines where unused code exists. This detailed reporting helps developers quickly locate and address issues in their codebase.

  • ts-unused-exports:

    ts-unused-exports offers a straightforward output that lists unused exports, but it may not provide as much context or detail as ts-prune. This can be beneficial for quick checks but may require additional effort to locate the exact lines in the code.

Performance

  • ts-prune:

    ts-prune is designed to efficiently analyze large codebases without significant performance overhead. Its comprehensive analysis ensures that all unused exports are identified without slowing down the development process.

  • ts-unused-exports:

    ts-unused-exports is lightweight and fast, making it suitable for quick checks in smaller projects. However, its performance may vary in larger codebases where it could take longer to scan all files.

Community and Support

  • ts-prune:

    ts-prune has a growing community and is actively maintained, providing users with regular updates and support. This can be beneficial for developers looking for a reliable tool with ongoing improvements.

  • ts-unused-exports:

    ts-unused-exports also has a supportive community, but it may not have as extensive documentation or resources as ts-prune. Users may find it easier to get help for more common issues with ts-prune.

How to Choose: ts-prune vs ts-unused-exports
  • ts-prune:

    Choose ts-prune if you need a tool that focuses on identifying unused exports across your entire codebase, providing a comprehensive overview of what can be removed. It is particularly useful for larger projects where manual tracking of exports can be cumbersome.

README for ts-prune

Build npm GitHub issues

ts-prune

Find potentially unused exports in your Typescript project with zero configuration.

asciicast Join the chat at https://gitter.im/ts-prune/community

Getting Started

ts-prune exposes a cli that reads your tsconfig file and prints out all the unused exports in your source files.

Installing

Install ts-prune with yarn or npm

# npm
npm install ts-prune --save-dev
# yarn
yarn add -D ts-prune

Usage

You can install it in your project and alias it to a npm script in package.json.

{
  "scripts": {
    "find-deadcode": "ts-prune"
  }
}

If you want to run against different Typescript configuration than tsconfig.json:

ts-prune -p tsconfig.dev.json

Examples

Configuration

ts-prune supports CLI and file configuration via cosmiconfig (all file formats are supported).

Configuration options

  • -p, --project - tsconfig.json path(tsconfig.json by default)
  • -i, --ignore - errors ignore RegExp pattern
  • -e, --error - return error code if unused exports are found
  • -s, --skip - skip these files when determining whether code is used. (For example, .test.ts? will stop ts-prune from considering an export in test file usages)

CLI configuration options:

ts-prune -p my-tsconfig.json -i my-component-ignore-patterns?

Configuration file example ts-prunerc:

{
  "ignore": "my-component-ignore-patterns?"
}

FAQ

How do I get the count of unused exports?

ts-prune | wc -l

How do I ignore a specific path?

ts-prune | grep -v src/ignore-this-path

How do I ignore a specific identifier?

You can either,

1. Prefix the export with // ts-prune-ignore-next
// ts-prune-ignore-next
export const thisNeedsIgnoring = foo;
2. Use grep -v to ignore a more widely used export name
ts-prune | grep -v ignoreThisThroughoutMyCodebase

Acknowledgements

Contributors

Nadeesha
Nadeesha Cabral
Snyk
Snyk bot
Dan
Dan Vanderkam
Vitaly
Vitaly Iegorov
Amir
Amir Arad
David
David Graham
Davis
Davis Ford
Ivo
Ivo Raisr
Josh
Josh Goldberg
Kristján
Kristján Oddsson
Simon
Simon Jang
The
The Gitter Badger
Tim
Tim Saunders
Torkel
Torkel Rogstad
William
William Candillon
phiresky/
phiresky