Everything You Need to Know About Dead Code

2025/09/10 14:50

What Is "Dead Code"?

Dead code refers to parts of a codebase that are written but never executed, called, imported, or otherwise needed during the normal operation of the application.

Over time, as features are added, changed, or removed, some code becomes obsolete but is accidentally left behind. This can lead to:

  • Increased bundle size
  • Slower build times
  • Harder maintenance and onboarding
  • Potential security risks

Cleaning up unused code improves clarity, performance, and long-term maintainability.

What Is Considered "Dead Code"?

Here are the common categories of unused code:

  1. Unused Variables

    Declared but never used in any operation.

  2. Unused Functions or Methods

    Defined but never called anywhere.

  3. Unused Imports

    Imported modules or packages that are never referenced.

  4. Unused Exports

    Functions or components exported from a module but not imported elsewhere.

  5. Unused Files

    Complete files (components, modules, etc.) that are never imported or required.

  6. Unused Dependencies

    Libraries listed in your package manager (e.g., package.json) that are not imported or used in the codebase.

Some exceptions:

  • Disabled Features

    Features that are temporarily disabled or taken out, but will be used in the future.

  • Helper functions

    Utility functions that help with common tasks can be reviewed regularly to check if it needs to be removed.

Tools for Scanning Dead Code

The following tools help detect and analyze unused code, imports, functions, variables, and dependencies. Choose tools based on your tech stack:

  • ts-prune
  • Detects unused exported functions, constants, and types in TypeScript projects.
  • On Maintenance (no further update)
  • depcheck
  • Checks for unused npm dependencies and missing ones.
  • knip.dev (We are using this!)
  • Knip finds and fixes unused dependencies, exports and files in your JavaScript and TypeScript projects. Less code and dependencies lead to improved performance, less maintenance and easier refactorings.

How to Scan and Remove Unused Code with knip

Follow these steps to identify and safely remove unused code from your project using knip:

  1. Install knip (if not already installed):
   yarn add -D knip    # or    npm install -D knip 
  1. Run the analysis:
   yarn knip 

Note: Replace yarn with your preferred package manager (npm, pnpm, etc.).

\

  1. Review the list of unused files or exports:

  2. Go through the list from top-down, starting with high-level components, constants, and utilities.

  3. Search your codebase to verify whether each flagged file or export is truly unused.

    • If it's used elsewhere, skip it.
    • If it has no references, it’s safe to delete.

  4. Remove confirmed dead code

  5. Delete unused files, exports, or lines confidently after reviewing

    • Check with your teammates if the components/files is not used anymore or just temporarily not used

    • Validate your codebase:

    • Run linters and TypeScript checks to catch any issues:

        yarn lint   npx tsc --noEmit 
    • Start the development server to confirm everything still works:

        yarn dev 
    • Final step: Commit your changes with a clear message, e.g.:

   git commit -m "chore: remove unused code and dependencies" 

Getting rid of dead code might feel like a chore, but it’s totally worth it. Cleaner code means fewer headaches, faster builds, and easier debugging down the line. With the right tools and a step-by-step approach, it’s not that hard to keep your codebase in shape. If you’re working in a fast-paced company where keeping track of all the new code is challenging, making this part of your regular workflow is a must.

If you have any other better approach or just want to share your own process, feel free to share in the comment! I would love to hear your thought!

Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact service@support.mexc.com for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.
Share Insights

You May Also Like

Chinese Bitcoin Hardware Titans Control 95% of Market, Now Coming to America to Dodge Trump Tariff War

Chinese Bitcoin Hardware Titans Control 95% of Market, Now Coming to America to Dodge Trump Tariff War

Three of China’s largest Bitcoin hardware manufacturers are establishing production facilities in the United States as President Donald Trump’s tariff policies reshape the cryptocurrency industry. The three industry leaders, Bitmain, Canaan, and MicroBT, collectively control over 90% of the global mining rig market. These companies are the architects of Bitcoin’s physical infrastructure, manufacturing the specialized ASIC (Application-Specific Integrated Circuit) machines that form the backbone of the world’s most valuable cryptocurrency network. Every Bitcoin mined globally likely passes through hardware bearing Chinese engineering fingerprints. 95% Market Control Sparks “Digital Dependency Trap” and Security Risks According to a June 18 Reuters report, these Bitcoin mining giants are establishing U.S. operations to circumvent potential tariffs. However, critics have raised security concerns about Chinese involvement in sectors spanning semiconductor manufacturing and energy infrastructure. Guang Yang, chief technology officer at crypto technology provider Conflux Network, described the situation as extending beyond trade policy. “The U.S.-China trade war goes beyond tariffs,” Yang stated. “It’s a strategic pivot toward ‘politically acceptable’ hardware sources.” Bitmain, the largest of the three companies by revenue, initiated U.S. production of mining equipment in December , one month after Trump’s presidential election victory. Canaan began trial production in the United States on April 2 to avoid tariffs following Trump’s announcement of new trade levies. One of the largest manufacturers of #bitcoin mining machines, Canaan, has set up a base of operations outside of China. CEO Zhang says, Kazakhstan is essential to "expanding after-sales geographical coverage and providing […] support growing international customer base" pic.twitter.com/7D5Xh2ici5 — Documenting ₿itcoin 📄 (@DocumentingBTC) June 23, 2021 Third-ranked MicroBT announced in a statement that it is “actively implementing a localization strategy in the U.S.” to “avoid the impact of tariffs.” $11.9B by 2028: The Market These Giants Are Fighting for According to Frost & Sullivan’s “2024 Global Blockchain Hardware Industry White Paper,” the ASIC-based Bitcoin mining hardware market demonstrates substantial consolidation. When measured by computing power sold, these three Chinese companies command 95.4% of the global market share. The Bitcoin ecosystem encompasses five primary segments: hardware supply, mining farm operations, mining pool management, trading platforms, and payment processing services. Hardware manufacturers like Canaan, the first Bitcoin mining company to go public and the second-largest by computing power , focus exclusively on integrated circuit (IC) design, manufacturing, and equipment sales. Industry analysts project continued sector expansion, with the market expected to reach $11.9 billion by 2028, representing a compound annual growth rate of 15.3%, contingent on Bitcoin’s continued price appreciation driven by supply scarcity. Source: Frost & Sullivan China’s Historical Bitcoin Mining Advantage Understanding today’s migration requires examining how China achieved such overwhelming market control in the first place. The foundation was laid during the historic 2017 Bitcoin boom, when three key factors aligned to create Chinese mining supremacy. During the early expansion phase, Chinese officials recognized cryptocurrency mining as a profitable venture that attracted substantial foreign investment. Consequently, authorities initially overlooked the mining sector while simultaneously restricting Bitcoin trading and initial coin offerings. Hydro-power plants go on sale in China since #Bitcoin mining crackdown has reduced demand for electricity. – South China Morning Post pic.twitter.com/QKEbUzWN4g — Bitcoin Archive (@BTC_Archive) June 30, 2021 China’s extensive hydroelectric infrastructure further strengthened the country’s mining operations, providing the cheap energy essential for profitable Bitcoin production. Does Chinese Hardware Control America’s Bitcoin Network? While the United States leads global Bitcoin mining operations with over 38% of total network activity , American miners depend almost entirely on Chinese-manufactured equipment. America Leads Bitcoin Mining Operation/ Source: Bitbo This creates what security analysts describe as a “digital dependency trap,” a scenario where America’s cryptocurrency infrastructure relies fundamentally on hardware produced by its primary economic rival. Guang Yang, Conflux Network’s chief technology officer, frames this dependency in geopolitical terms that extend far beyond trade economics . “The U.S.-China trade war goes beyond tariffs,” Yang explains. “It’s a strategic pivot toward ‘politically acceptable’ hardware sources.” His assessment reflects growing concerns within the cryptocurrency community about supply chain vulnerabilities that could impact national economic security.
Share
CryptoNews2025/06/19 04:26
Share
The Day I Faced My Biggest Trading Loss

The Day I Faced My Biggest Trading Loss

…and the 7 Rules That Saved MeContinue reading on Coinmonks »
Share
Medium2025/09/10 22:33
Share