Coder Social home page Coder Social logo

deadcode's Introduction

deadcode

Deadcode shows you source files that are not required anywhere given entry point scripts.

Summary

What it does

Deadcode list all files not required anywhere in your project and let you remove them.

What it does not

Dynamic requires

Deadcode will ignore dynamic requires but will provide you with a list of files that contain them.

Reassigned requires

Deadcode look for import declarations and calls of the require function. In other word if you assign require to another var and use it to load a dependency, it will not handle it.

Installation

$ npm add deadcode --save-dev

Usage

$ deadcode --list-all
info 5 dependencies found
├─ /Users/dead-code/demo/index.js
├─ /Users/dead-code/demo/a.js
├─ fs
├─ /Users/dead-code/demo/b.js
└─ /Users/dead-code/demo/c.js
warning 1 files with dynamic dependencies found
└─ /Users/dead-code/demo/a.js
warning 1 ignored dependencies found
└─ /Users/dead-code/node_modules/@babel/core/lib/index.js
success 0 unparsed dependencies found
success 0 unresolved dependencies

warning 1 dead files found
└─ /Users/dead-code/demo/d.js

You can get help with:

$ deadcode --help

Options

  • config: config file to use
  • entry: array of entry point files
  • ignore: array of pattern matching files to ignore
  • src: array of pattern matching source files

How to provide options

Options could be:

  • provided as command options:
    $ deadcode --ignore="**/node_modules/**,**/__tests__/**"
    
  • loaded from file using the command option config:
    $ deadcode --config=".deadcoderc"
    
  • read from the deadcode property of your package.json:
    {
      "deadcode": {
        "ignore": ["**/node_modules/**"]
      }
    }
    

Good to know

You should know that:

  • Command options override options in config file.
  • Config file options override options in package.json.
  • If no entry is provided, the main property of your package.json will be used.

Todo

  • resolve dynamic import when possible
  • handle reassigned require
  • look for dead code in living files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.