npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@phiresky/ts-unused-class-members

v2.0.0

Published

Find unused class variables and methods in a typescript project

Downloads

3

Readme

semantic-release: angular

ts-unused-class-members

A CLI tool for finding unused class variables and methods in a TypeScript project.

Screen Shot 2021-07-01 at 2 13 47 PM

Getting Started

Prerequisites

@faire/ts-unused-class-members is hosted on :octocat:GitHub Packages. To configure npm to download @faire packages from GitHub Packages registry you need to

  1. Create a personal access token with the read:packages scope
  2. Use the command below to add the personal access token to ~/.npmrc
    echo "//npm.pkg.github.com/:_authToken=YOUR_TOKEN" >> ~/.npmrc
  3. Use the command below to configure npm to download @faire packages from GitHub Packages registry
    npm config set @faire:registry https://npm.pkg.github.com

Usage

In the same directory as your tsconfig.json, run

npx @faire/ts-unused-class-members

CLI Options

Run ts-unused-class-members with --help to see all available CLI options.

Options:
  --project          Path to the project's tsconfig.json                [string]
  --path             Path to a single directory/file to scan            [string]
  --ignoreFileRegex  Regex pattern for excluding files                  [string]

These options are optional, and you can also set them in a config file.

Configuration File

By default, ts-unused-class-members flags every class member that has no references in the project. Depends on the framework/library you use, you may want to tell the checker to ignore certain class members. You can do that by including a configuration file.

Example config file for a React + MobX project:

ts-unused-class-members.config.js in the project root

module.exports = {
  ignoreFileRegex: "(?:(\\.d)|(\\.stories)|(\\.test))\\.tsx?$",
  ignoreMemberNames: [
    "render",
    "state",
    "componentDidMount",
    "componentWillUnmount",
    "componentDidCatch",
    "componentDidUpdate",
    "shouldComponentUpdate",
    "UNSAFE_componentWillReceiveProps",
    "UNSAFE_componentWillUpdate",
    "UNSAFE_componentWillMount",
  ],
  /**
   * Ignore members decorated by MobX's @disposeOnUnmount
   */
  ignoreDecoratorNames: ["disposeOnUnmount"],
  /**
   * Ignore members initialized with MobX's reaction()
   * e.g. public myReaction = reaction(...);
   */
  ignoreInitializerNames: ["reaction"],
};

ts-unused-class-members consumes configuration using cosmiconfig, which supports some other config formats too.

  • a ts-unused-class-members property in package.json
  • a ts-unused-class-members.config.js or ts-unused-class-members.config.cjs CommonJS module exporting an object
  • a .ts-unused-class-membersrc file in JSON or YAML format

Ignoring a Specific Declaration

You can also tell ts-unused-class-members to ignore a specific class or class member by prefixing its declaration with // unused-class-members-ignore-next.

// unused-class-members-ignore-next
class Unused {
  ...
}

class A {
  // unused-class-members-ignore-next
  unused = undefined;
  ...
}

Contributing

Issues and PRs are welcome!

This project uses semantic-release to automate version management and package publishing, so make sure to follow the commit message conventions when contributing.

Acknowledgements