ts-prune vs ts-unused-exports
TypeScriptの未使用コード検出ツール
ts-prunets-unused-exports

TypeScriptの未使用コード検出ツール

TypeScriptの未使用コード検出ツールは、プロジェクト内で使用されていない型やエクスポートを特定するためのライブラリです。これらのツールは、コードのクリーンアップやメンテナンスを容易にし、無駄なコードを削減することで、プロジェクトの可読性とパフォーマンスを向上させることを目的としています。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
ts-prune391,4422,06946.4 kB74年前MIT
ts-unused-exports0805141 kB511年前MIT

機能比較: ts-prune vs ts-unused-exports

機能の焦点

  • ts-prune:

    ts-pruneは、主に未使用のエクスポートを検出することに特化しており、プロジェクト内でエクスポートされたが使用されていないコードを迅速に特定します。これにより、開発者は不要なコードを簡単に削除でき、コードベースをクリーンに保つことができます。

  • ts-unused-exports:

    ts-unused-exportsは、未使用のエクスポートを見つけるだけでなく、エクスポートの依存関係を分析する機能も持っています。これにより、どのエクスポートがどのファイルで使用されていないかを明確に把握でき、プロジェクト全体のエクスポートを整理するのに役立ちます。

使用シナリオ

  • ts-prune:

    ts-pruneは、特に大規模なプロジェクトやライブラリで、未使用のエクスポートを特定する必要がある場合に最適です。特に、エクスポートされた関数や変数が他のファイルから参照されていない場合に役立ちます。

  • ts-unused-exports:

    ts-unused-exportsは、エクスポートが多く、依存関係が複雑なプロジェクトで、未使用のエクスポートを整理したい場合に適しています。特に、モジュール間での依存関係を明確にするのに役立ちます。

メンテナンス性

  • ts-prune:

    ts-pruneは、未使用のエクスポートを迅速に特定することで、コードのメンテナンスを容易にします。不要なコードを削除することで、コードベースの可読性が向上し、将来のメンテナンスが容易になります。

  • ts-unused-exports:

    ts-unused-exportsは、エクスポートの整理を支援するため、プロジェクトのメンテナンス性を向上させます。未使用のエクスポートを特定することで、コードのクリーンアップが促進され、長期的なメンテナンスが容易になります。

学習曲線

  • ts-prune:

    ts-pruneは、シンプルなコマンドラインツールであり、使い方が直感的であるため、学習曲線は比較的緩やかです。特に、TypeScriptに慣れている開発者にとっては、すぐに使い始めることができます。

  • ts-unused-exports:

    ts-unused-exportsも比較的簡単に使用できるツールですが、エクスポートの依存関係を分析する機能があるため、少し学習が必要かもしれません。しかし、基本的な使い方は直感的で、すぐに利用可能です。

拡張性

  • ts-prune:

    ts-pruneは、シンプルな設計により、他のツールやスクリプトと統合しやすく、拡張性があります。特に、CI/CDパイプラインに組み込むことで、継続的なコードクリーンアップが可能です。

  • ts-unused-exports:

    ts-unused-exportsは、エクスポートの依存関係を分析するための機能があり、他のツールと組み合わせて使用することで、さらに強力なコード分析が可能になります。

選び方: ts-prune vs ts-unused-exports

  • ts-prune:

    ts-pruneは、未使用のエクスポートを特定することに特化しており、特に大規模なコードベースでの未使用の型や関数を簡単に見つけたい場合に適しています。特に、エクスポートされた関数や変数が他のファイルから参照されていない場合に有効です。

  • ts-unused-exports:

    ts-unused-exportsは、エクスポートされているが使用されていないコードを検出するためのツールで、特にプロジェクトのエクスポートの整理を行いたい場合に便利です。特に、モジュール間での依存関係が複雑な場合に役立ちます。

ts-prune のREADME

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