Git Product home page Git Product logo

ts-retype's Introduction

tests CodeQL npm version coverage

TS retype

Discover duplicate TypeScript types in your codebase. TS retype finds duplicates of Literal and Interface types.

Install

npm install -g ts-retype

or

yarn global add ts-retype

Usage with CLI

ts-retype /path/to/project

or

npx ts-retype /path/to/project

Usage with Library

import { scan } from 'ts-retype';

const { data, meta } = scan({
    exclude: ['**/node_modules/**', '**/dist/**'],
    include: ['**/*.{ts,tsx}'],
    rootDir: '.',
});

console.log(meta);

for (const dup of data) {
    console.log(dup.group, dup.names, dup.files);
}

See Data Format for result format.

Configuration

CLI options

Usage: ts-retype [options] [rootDir]

Discover duplicate TypeScript types in your codebase.

Options:
  -V, --version                      output the version number
  -c, --config [file-path]           load config - if no path provided, loads
                                     .retyperc from current directory. if not
                                     set, use default config
  -e, --exclude [glob...]            glob patterns that will be ignored
  -g, --init [file-path]             initializes with default config. if no
                                     path is provided, creates .retyperc in the
                                     current directory
  -i, --include [glob...]            glob patterns that will be included in
                                     search
  -j, --json <file-path>             file path to export JSON report to. if not
                                     set, does not export JSON.
  -n, --noHtml                       if set, does not export HTML
  -o, --output <file-path|dir-path>  HTML report file path - if provided with
                                     dir, create index.html file inside the dir
  -h, --help                         display help for command

.retyperc

{
  "exclude": ["**/node_modules/**","**/dist/**"],
  "include": ["**/*.{ts,tsx}"],
  "json": "./apps/vis/src/assets/data.json",
  "noHtml": false,
  "output": "./retype-report.html",
  "rootDir": "."
}

Data Format

Defined in TypeDuplicate

export type TypeDuplicate = {
  files: {
    name: string;
    file: string;
    lines: [number, number];
    pos: [number, number];
    offset: number;
    type: 'interface' | 'literal' | 'alias' | 'function' | 'enum' | 'union';
    src: string;
    srcHgl?: TokenRoot;
    properties?: { name: string; type: string }[];
  }[];
  group: 'different' | 'renamed' | 'identical';
  names: { count: number; name: string }[];
  members?: string[];
  parameters?: { name: string; type: string }[];
  properties?: { name: string; type: string }[];
  returnType?: string;
  signature?: {
    name?: string;
    params: { name: string; type?: string }[];
    return?: string;
    strMin?: string;
    strFull?: string;
  };
  types?: string[];
};

Development

just clean
just install
just build-all
just test-all
just dev vis
just dev doc
just build-watch uikit
just rebuild uikit
just build uikit
just test search

ts-retype's People

Contributors

petlack avatar

Stargazers

 avatar

Watchers

 avatar

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.