Skip to content

typed-rocks/eslint-plugin-typed-rocks

Repository files navigation

Enforce and simplify TypeScript type complexity in your codebase

eslint-plugin-typed-rocks

Features

  • Rule: typed-rocks/max-depth
    • Prevents usage of overly complex or deeply nested TypeScript types.
    • Encourages maintainable, readable, and simple type definitions.
    • Helps teams enforce a maximum type complexity policy.
    • integrated --fix command to restructure and properly organize your types.

Example Plugin Results

// ❌ Too complex:
// ❌ No reusable types:
type Teams = {
  frontend: {
    members: {
      name: string;
      age: number;
      address: {
//      ^^^ Type is too deeply nested (4). Max allowed is 3
        street: string;
        postalCode: string;
        city: string;
        country: string;
      };
      skills: {
//      ^^^ Type is too deeply nested (4). Max allowed is 3
        area: string;
        level: number;
      }[];
    }[];
  };
};

After --fix

// ✅ Simpler, more maintainable
// ✅ Reusable
// ✅ No duplication
type Teams = {
  frontend: {
    members: {
      name: string;
      age: number;
      address: Address;
      skills: Skills[];
    }[];
  };
};

type Skills = {
  area: string;
  level: number;
};

type Address = {
  street: string;
  postalCode: string;
  city: string;
  country: string;
};

Installation

npm install eslint-plugin-typed-rocks --save-dev

Usage

Add typed-rocks to your ESLint plugins and enable the rule:

{
  "plugins": ["typed-rocks"],
  "rules": {
    "typed-rocks/max-depth": ["warn", 3]
  }
}

Why?

  • Prevents hard-to-read and hard-to-maintain type definitions.
  • Encourages best practices in TypeScript codebases.
  • Makes code reviews and onboarding easier.

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published