or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

best-practices-rules.mdcode-quality-rules.mdindex.mdplugin-configuration.mdstyle-formatting-rules.mdtype-safety-rules.md

index.mddocs/

0

# TypeScript ESLint Plugin

1

2

The TypeScript ESLint Plugin is a comprehensive ESLint plugin specifically designed for TypeScript codebases, providing 131 lint rules that help developers write better, more consistent TypeScript code. It integrates seamlessly with the TypeScript compiler and ESLint ecosystem to provide static analysis and code quality enforcement for TypeScript projects.

3

4

## Package Information

5

6

- **Package Name**: @typescript-eslint/eslint-plugin

7

- **Package Type**: npm (ESLint plugin)

8

- **Language**: TypeScript/JavaScript

9

- **Installation**: `npm install @typescript-eslint/eslint-plugin`

10

11

## Core Imports

12

13

```typescript

14

// Main plugin import

15

import plugin from "@typescript-eslint/eslint-plugin";

16

17

// Individual rules access

18

import rules from "@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules";

19

20

// Raw plugin with additional exports

21

import { plugin, parser, flatConfigs } from "@typescript-eslint/eslint-plugin/use-at-your-own-risk/raw-plugin";

22

```

23

24

For CommonJS:

25

26

```javascript

27

// Main plugin import

28

const plugin = require("@typescript-eslint/eslint-plugin");

29

30

// Individual rules access

31

const rules = require("@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules");

32

33

// Raw plugin with additional exports

34

const { plugin, parser, flatConfigs } = require("@typescript-eslint/eslint-plugin/use-at-your-own-risk/raw-plugin");

35

```

36

37

## Basic Usage

38

39

```typescript

40

// Basic ESLint configuration (legacy format)

41

module.exports = {

42

parser: "@typescript-eslint/parser",

43

plugins: ["@typescript-eslint"],

44

extends: [

45

"@typescript-eslint/recommended",

46

"@typescript-eslint/recommended-type-checked"

47

],

48

parserOptions: {

49

project: "./tsconfig.json"

50

},

51

rules: {

52

"@typescript-eslint/no-unused-vars": "error",

53

"@typescript-eslint/explicit-function-return-type": "warn"

54

}

55

};

56

57

// Flat configuration format (ESLint 9+)

58

import tseslint from "@typescript-eslint/eslint-plugin/use-at-your-own-risk/raw-plugin";

59

60

export default [

61

...tseslint.flatConfigs["flat/recommended"],

62

{

63

languageOptions: {

64

parser: tseslint.parser,

65

parserOptions: {

66

project: "./tsconfig.json"

67

}

68

},

69

plugins: {

70

"@typescript-eslint": tseslint.plugin

71

},

72

rules: {

73

"@typescript-eslint/no-unused-vars": "error"

74

}

75

}

76

];

77

```

78

79

## Architecture

80

81

The TypeScript ESLint Plugin is built around several key components:

82

83

- **Plugin System**: ESLint plugin architecture providing rules, configurations, and metadata

84

- **Rule Engine**: 108 individual lint rules covering TypeScript-specific language features and best practices

85

- **Configuration Presets**: Pre-configured rule sets (recommended, strict, stylistic) for different project needs

86

- **Type Integration**: Seamless integration with TypeScript compiler for type-aware linting

87

- **Dual Config Support**: Compatible with both legacy ESLint RC and modern flat configuration formats

88

89

## Capabilities

90

91

### Plugin Configuration

92

93

Core plugin setup and configuration presets for different project requirements. Provides both legacy and modern configuration formats.

94

95

```typescript { .api }

96

interface PluginExport {

97

configs: Record<string, ClassicConfig.Config>;

98

meta: FlatConfig.PluginMeta;

99

rules: TypeScriptESLintRules;

100

}

101

102

interface RawPluginExport {

103

flatConfigs: Record<string, FlatConfig.Config | FlatConfig.ConfigArray>;

104

parser: FlatConfig.Parser;

105

plugin: PluginExport;

106

}

107

```

108

109

[Plugin Configuration](./plugin-configuration.md)

110

111

### Type Safety Rules

112

113

Rules focused on TypeScript type safety, preventing common type-related errors and enforcing proper type usage.

114

115

```typescript { .api }

116

// Example type safety rules

117

interface TypeSafetyRules {

118

"no-unsafe-assignment": RuleModule;

119

"no-unsafe-call": RuleModule;

120

"no-unsafe-member-access": RuleModule;

121

"no-unsafe-return": RuleModule;

122

"no-floating-promises": RuleModule;

123

"await-thenable": RuleModule;

124

"no-misused-promises": RuleModule;

125

}

126

```

127

128

[Type Safety Rules](./type-safety-rules.md)

129

130

### Code Quality Rules

131

132

Rules that enforce code quality, consistency, and best practices specific to TypeScript development.

133

134

```typescript { .api }

135

// Example code quality rules

136

interface CodeQualityRules {

137

"consistent-type-imports": RuleModule;

138

"consistent-type-definitions": RuleModule;

139

"explicit-function-return-type": RuleModule;

140

"explicit-member-accessibility": RuleModule;

141

"no-duplicate-enum-values": RuleModule;

142

"no-empty-interface": RuleModule;

143

}

144

```

145

146

[Code Quality Rules](./code-quality-rules.md)

147

148

### Style and Formatting Rules

149

150

Rules focused on code style, naming conventions, and formatting preferences for TypeScript code.

151

152

```typescript { .api }

153

// Example stylistic rules

154

interface StyleRules {

155

"naming-convention": RuleModule;

156

"member-ordering": RuleModule;

157

"array-type": RuleModule;

158

"consistent-type-assertions": RuleModule;

159

"method-signature-style": RuleModule;

160

"class-literal-property-style": RuleModule;

161

}

162

```

163

164

[Style and Formatting Rules](./style-formatting-rules.md)

165

166

### Best Practices Rules

167

168

Rules that promote TypeScript and JavaScript best practices, preventing common pitfalls and anti-patterns.

169

170

```typescript { .api }

171

// Example best practice rules

172

interface BestPracticeRules {

173

"prefer-optional-chain": RuleModule;

174

"prefer-nullish-coalescing": RuleModule;

175

"prefer-as-const": RuleModule;

176

"prefer-for-of": RuleModule;

177

"prefer-includes": RuleModule;

178

"no-unnecessary-type-assertion": RuleModule;

179

}

180

```

181

182

[Best Practices Rules](./best-practices-rules.md)

183

184

## Core Types

185

186

```typescript { .api }

187

interface RuleModuleWithMetaDocs<

188

TMessageIds extends string,

189

TOptions extends readonly unknown[],

190

TDocs extends object

191

> {

192

meta: RuleMetaData<TMessageIds, TDocs>;

193

create(context: RuleContext<TMessageIds, TOptions>): RuleListener;

194

}

195

196

interface ESLintPluginDocs {

197

extendsBaseRule?: boolean | string;

198

recommended?: RuleRecommendation | RuleRecommendationAcrossConfigs<unknown[]>;

199

requiresTypeChecking?: boolean;

200

}

201

202

type ESLintPluginRuleModule = RuleModuleWithMetaDocs<

203

string,

204

readonly unknown[],

205

ESLintPluginDocs

206

>;

207

208

interface TypeScriptESLintRules {

209

[ruleName: string]: ESLintPluginRuleModule;

210

}

211

212

interface ClassicConfig {

213

extends?: string[];

214

plugins?: string[];

215

rules?: Record<string, RuleConfig>;

216

parser?: string;

217

parserOptions?: ParserOptions;

218

}

219

220

interface FlatConfig {

221

languageOptions?: {

222

parser?: Parser;

223

parserOptions?: ParserOptions;

224

};

225

plugins?: Record<string, Plugin>;

226

rules?: Record<string, RuleConfig>;

227

}

228

```