# @typescript-eslint/no-extraneous-class

> Disallow classes that are empty, only static, or only a constructor

A class with only static members is a group of functions and constants, not something you make instances of. Every call needs the `MathUtils.` prefix, and a bundler keeps the whole class even if you use one function. Export the functions and constants from the module instead. A class with only a constructor is a function, and an empty class does nothing.

A class that extends another class isn't reported. Neither is a class with a constructor that declares properties in its parameters, such as `constructor(public x: number) {}`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-extraneous-class" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-extraneous-class" = ["error", {
  allowConstructorOnly = false,
  allowEmpty = false,
  allowStaticOnly = false,
  allowWithDecorator = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```ts
export class MathUtils {
  static readonly TAU = Math.PI * 2;

  static clamp(value: number, min: number, max: number) {
    return Math.min(Math.max(value, min), max);
  }
}
```

{/* bad {"count": 2} */}
```ts
class Placeholder {}

class Startup {
  constructor() {
    console.log("started");
  }
}
```

Not reported:

{/* good */}
```ts
export const TAU = Math.PI * 2;

export function clamp(value: number, min: number, max: number) {
  return Math.min(Math.max(value, min), max);
}
```

{/* good */}
```ts
class Counter {
  static instances = 0;
  count = 0;
}

class NotFoundError extends Error {}

class Point {
  constructor(public x: number, public y: number) {}
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowConstructorOnly` | `false` | Allow a class that has only a constructor. |
| `allowEmpty` | `false` | Allow a class with no members. |
| `allowStaticOnly` | `false` | Allow a class that has only static members. |
| `allowWithDecorator` | `false` | Allow any class that has a decorator. |

Some frameworks configure a class through its decorator, and the body stays empty:

{/* good {"options": [{"allowWithDecorator": true}]} */}
```ts
import { Module } from "./framework";

@Module({ providers: [] })
export class AppModule {}
```

{/* good {"options": [{"allowStaticOnly": true}]} */}
```ts
export class Env {
  static readonly isProduction = process.env.NODE_ENV === "production";
}
```
