or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-utils.mdeslint-utils.mdindex.mdjson-schema.mdscope-analysis.mdts-eslint.mdts-estree.md

ts-eslint.mddocs/

0

# TypeScript ESLint Types

1

2

Enhanced ESLint type definitions with full TypeScript integration for rules, contexts, and AST nodes. These types provide the foundation for creating type-safe ESLint rules that work seamlessly with TypeScript code.

3

4

## Capabilities

5

6

### Rule Definition Types

7

8

Core interfaces for defining TypeScript-aware ESLint rules.

9

10

```typescript { .api }

11

/**

12

* Complete ESLint rule module with TypeScript support

13

*/

14

interface RuleModule<

15

TMessageIds extends string,

16

TOptions extends readonly unknown[],

17

TRuleListener extends RuleListener = RuleListener

18

> {

19

/** Rule metadata including messages, schema, and documentation */

20

meta: RuleMetaData<TMessageIds>;

21

/** Function that creates the rule implementation */

22

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

23

/** Default options for the rule */

24

defaultOptions?: TOptions;

25

}

26

27

/**

28

* Function signature for creating rule implementations

29

*/

30

type RuleCreateFunction<

31

TMessageIds extends string,

32

TOptions extends readonly unknown[],

33

TRuleListener extends RuleListener = RuleListener

34

> = (context: RuleContext<TMessageIds, TOptions>) => TRuleListener;

35

36

/**

37

* Rule metadata interface with TypeScript message ID support

38

*/

39

interface RuleMetaData<TMessageIds extends string> {

40

/** Rule category: 'problem' for bugs, 'suggestion' for improvements, 'layout' for formatting */

41

type: 'problem' | 'suggestion' | 'layout';

42

/** Message templates keyed by message ID */

43

messages: Record<TMessageIds, string>;

44

/** Whether the rule can automatically fix issues */

45

fixable?: 'code' | 'whitespace';

46

/** JSON schema for rule options validation */

47

schema: JSONSchema.JSONSchema7 | readonly JSONSchema.JSONSchema7[];

48

/** Whether the rule is deprecated */

49

deprecated?: boolean;

50

/** Rules that replace this deprecated rule */

51

replacedBy?: readonly string[];

52

/** Documentation metadata */

53

docs?: RuleMetaDataDocs;

54

/** Whether the rule has suggestions */

55

hasSuggestions?: boolean;

56

}

57

58

/**

59

* Rule documentation metadata

60

*/

61

interface RuleMetaDataDocs {

62

/** Description of what the rule does */

63

description: string;

64

/** Rule category for organization */

65

category?: string;

66

/** Recommendation level for the rule */

67

recommended?: boolean | 'error' | 'warn' | 'strict';

68

/** Whether the rule requires TypeScript type checking */

69

requiresTypeChecking?: boolean;

70

/** Whether this rule extends a base ESLint rule */

71

extendsBaseRule?: boolean | string;

72

/** URL to rule documentation */

73

url?: string;

74

}

75

76

/**

77

* Rule recommendation levels

78

*/

79

type RuleRecommendation = 'error' | 'strict' | 'warn' | false;

80

```

81

82

### Rule Context

83

84

The context object passed to rule implementations containing utilities and information.

85

86

```typescript { .api }

87

/**

88

* Rule execution context with TypeScript support

89

*/

90

interface RuleContext<TMessageIds extends string, TOptions extends readonly unknown[]> {

91

/** Rule configuration options */

92

readonly options: TOptions;

93

/** Shared configuration settings */

94

readonly settings: Record<string, unknown>;

95

/** Source code being analyzed */

96

readonly sourceCode: SourceCode;

97

/** Physical filename being linted */

98

readonly filename: string;

99

/** Configured parser options */

100

readonly parserOptions: ParserOptions;

101

/** Parser path used */

102

readonly parserPath: string;

103

/** Language options */

104

readonly languageOptions?: {

105

ecmaVersion?: ParserOptions['ecmaVersion'];

106

sourceType?: ParserOptions['sourceType'];

107

globals?: Record<string, boolean>;

108

};

109

110

/**

111

* Gets the current ESLint scope

112

* @returns Current scope object

113

*/

114

getScope(): Scope.Scope;

115

116

/**

117

* Gets all ancestor nodes of the current node

118

* @returns Array of ancestor nodes from closest to root

119

*/

120

getAncestors(): TSESTree.Node[];

121

122

/**

123

* Gets variables declared by the given node

124

* @param node - AST node to get variables for

125

* @returns Array of variables declared by the node

126

*/

127

getDeclaredVariables(node: TSESTree.Node): Scope.Variable[];

128

129

/**

130

* Gets the source code object for the file being linted

131

* @returns SourceCode instance

132

*/

133

getSourceCode(): SourceCode;

134

135

/**

136

* Gets the filename being linted

137

* @returns Physical filename

138

*/

139

getFilename(): string;

140

141

/**

142

* Marks a variable as used to prevent unused variable warnings

143

* @param name - Variable name to mark as used

144

* @returns True if variable was found and marked

145

*/

146

markVariableAsUsed(name: string): boolean;

147

148

/**

149

* Reports a rule violation

150

* @param descriptor - Problem description with message and location

151

*/

152

report(descriptor: ReportDescriptor<TMessageIds>): void;

153

154

/**

155

* Reports a rule violation at a specific node

156

* @param node - AST node where the problem occurs

157

* @param message - Problem message or message ID

158

* @param data - Template data for message interpolation

159

*/

160

report(node: TSESTree.Node, message: string): void;

161

report(node: TSESTree.Node, messageId: TMessageIds, data?: Record<string, unknown>): void;

162

}

163

```

164

165

### Rule Listeners

166

167

Interface for AST node visitors that rules implement.

168

169

```typescript { .api }

170

/**

171

* AST visitor interface with handlers for all node types

172

*/

173

interface RuleListener {

174

/** Visitor for ArrayExpression nodes */

175

ArrayExpression?(node: TSESTree.ArrayExpression): void;

176

/** Visitor for ArrayPattern nodes */

177

ArrayPattern?(node: TSESTree.ArrayPattern): void;

178

/** Visitor for ArrowFunctionExpression nodes */

179

ArrowFunctionExpression?(node: TSESTree.ArrowFunctionExpression): void;

180

/** Visitor for AssignmentExpression nodes */

181

AssignmentExpression?(node: TSESTree.AssignmentExpression): void;

182

/** Visitor for AssignmentPattern nodes */

183

AssignmentPattern?(node: TSESTree.AssignmentPattern): void;

184

/** Visitor for AwaitExpression nodes */

185

AwaitExpression?(node: TSESTree.AwaitExpression): void;

186

/** Visitor for BinaryExpression nodes */

187

BinaryExpression?(node: TSESTree.BinaryExpression): void;

188

/** Visitor for BlockStatement nodes */

189

BlockStatement?(node: TSESTree.BlockStatement): void;

190

/** Visitor for BreakStatement nodes */

191

BreakStatement?(node: TSESTree.BreakStatement): void;

192

/** Visitor for CallExpression nodes */

193

CallExpression?(node: TSESTree.CallExpression): void;

194

/** Visitor for CatchClause nodes */

195

CatchClause?(node: TSESTree.CatchClause): void;

196

/** Visitor for ChainExpression nodes */

197

ChainExpression?(node: TSESTree.ChainExpression): void;

198

/** Visitor for ClassBody nodes */

199

ClassBody?(node: TSESTree.ClassBody): void;

200

/** Visitor for ClassDeclaration nodes */

201

ClassDeclaration?(node: TSESTree.ClassDeclaration): void;

202

/** Visitor for ClassExpression nodes */

203

ClassExpression?(node: TSESTree.ClassExpression): void;

204

/** Visitor for ConditionalExpression nodes */

205

ConditionalExpression?(node: TSESTree.ConditionalExpression): void;

206

/** Visitor for ContinueStatement nodes */

207

ContinueStatement?(node: TSESTree.ContinueStatement): void;

208

/** Visitor for DebuggerStatement nodes */

209

DebuggerStatement?(node: TSESTree.DebuggerStatement): void;

210

/** Visitor for DoWhileStatement nodes */

211

DoWhileStatement?(node: TSESTree.DoWhileStatement): void;

212

/** Visitor for EmptyStatement nodes */

213

EmptyStatement?(node: TSESTree.EmptyStatement): void;

214

/** Visitor for ExpressionStatement nodes */

215

ExpressionStatement?(node: TSESTree.ExpressionStatement): void;

216

/** Visitor for ForInStatement nodes */

217

ForInStatement?(node: TSESTree.ForInStatement): void;

218

/** Visitor for ForOfStatement nodes */

219

ForOfStatement?(node: TSESTree.ForOfStatement): void;

220

/** Visitor for ForStatement nodes */

221

ForStatement?(node: TSESTree.ForStatement): void;

222

/** Visitor for FunctionDeclaration nodes */

223

FunctionDeclaration?(node: TSESTree.FunctionDeclaration): void;

224

/** Visitor for FunctionExpression nodes */

225

FunctionExpression?(node: TSESTree.FunctionExpression): void;

226

/** Visitor for Identifier nodes */

227

Identifier?(node: TSESTree.Identifier): void;

228

/** Visitor for IfStatement nodes */

229

IfStatement?(node: TSESTree.IfStatement): void;

230

/** Visitor for ImportDeclaration nodes */

231

ImportDeclaration?(node: TSESTree.ImportDeclaration): void;

232

/** Visitor for ImportDefaultSpecifier nodes */

233

ImportDefaultSpecifier?(node: TSESTree.ImportDefaultSpecifier): void;

234

/** Visitor for ImportNamespaceSpecifier nodes */

235

ImportNamespaceSpecifier?(node: TSESTree.ImportNamespaceSpecifier): void;

236

/** Visitor for ImportSpecifier nodes */

237

ImportSpecifier?(node: TSESTree.ImportSpecifier): void;

238

/** Visitor for LabeledStatement nodes */

239

LabeledStatement?(node: TSESTree.LabeledStatement): void;

240

/** Visitor for Literal nodes */

241

Literal?(node: TSESTree.Literal): void;

242

/** Visitor for LogicalExpression nodes */

243

LogicalExpression?(node: TSESTree.LogicalExpression): void;

244

/** Visitor for MemberExpression nodes */

245

MemberExpression?(node: TSESTree.MemberExpression): void;

246

/** Visitor for MetaProperty nodes */

247

MetaProperty?(node: TSESTree.MetaProperty): void;

248

/** Visitor for MethodDefinition nodes */

249

MethodDefinition?(node: TSESTree.MethodDefinition): void;

250

/** Visitor for NewExpression nodes */

251

NewExpression?(node: TSESTree.NewExpression): void;

252

/** Visitor for ObjectExpression nodes */

253

ObjectExpression?(node: TSESTree.ObjectExpression): void;

254

/** Visitor for ObjectPattern nodes */

255

ObjectPattern?(node: TSESTree.ObjectPattern): void;

256

/** Visitor for Program nodes */

257

Program?(node: TSESTree.Program): void;

258

/** Visitor for Property nodes */

259

Property?(node: TSESTree.Property): void;

260

/** Visitor for RestElement nodes */

261

RestElement?(node: TSESTree.RestElement): void;

262

/** Visitor for ReturnStatement nodes */

263

ReturnStatement?(node: TSESTree.ReturnStatement): void;

264

/** Visitor for SequenceExpression nodes */

265

SequenceExpression?(node: TSESTree.SequenceExpression): void;

266

/** Visitor for SpreadElement nodes */

267

SpreadElement?(node: TSESTree.SpreadElement): void;

268

/** Visitor for Super nodes */

269

Super?(node: TSESTree.Super): void;

270

/** Visitor for SwitchCase nodes */

271

SwitchCase?(node: TSESTree.SwitchCase): void;

272

/** Visitor for SwitchStatement nodes */

273

SwitchStatement?(node: TSESTree.SwitchStatement): void;

274

/** Visitor for TaggedTemplateExpression nodes */

275

TaggedTemplateExpression?(node: TSESTree.TaggedTemplateExpression): void;

276

/** Visitor for TemplateElement nodes */

277

TemplateElement?(node: TSESTree.TemplateElement): void;

278

/** Visitor for TemplateLiteral nodes */

279

TemplateLiteral?(node: TSESTree.TemplateLiteral): void;

280

/** Visitor for ThisExpression nodes */

281

ThisExpression?(node: TSESTree.ThisExpression): void;

282

/** Visitor for ThrowStatement nodes */

283

ThrowStatement?(node: TSESTree.ThrowStatement): void;

284

/** Visitor for TryStatement nodes */

285

TryStatement?(node: TSESTree.TryStatement): void;

286

/** Visitor for UnaryExpression nodes */

287

UnaryExpression?(node: TSESTree.UnaryExpression): void;

288

/** Visitor for UpdateExpression nodes */

289

UpdateExpression?(node: TSESTree.UpdateExpression): void;

290

/** Visitor for VariableDeclaration nodes */

291

VariableDeclaration?(node: TSESTree.VariableDeclaration): void;

292

/** Visitor for VariableDeclarator nodes */

293

VariableDeclarator?(node: TSESTree.VariableDeclarator): void;

294

/** Visitor for WhileStatement nodes */

295

WhileStatement?(node: TSESTree.WhileStatement): void;

296

/** Visitor for WithStatement nodes */

297

WithStatement?(node: TSESTree.WithStatement): void;

298

/** Visitor for YieldExpression nodes */

299

YieldExpression?(node: TSESTree.YieldExpression): void;

300

301

// TypeScript-specific nodes

302

/** Visitor for TSAbstractKeyword nodes */

303

TSAbstractKeyword?(node: TSESTree.TSAbstractKeyword): void;

304

/** Visitor for TSAbstractMethodDefinition nodes */

305

TSAbstractMethodDefinition?(node: TSESTree.TSAbstractMethodDefinition): void;

306

/** Visitor for TSAbstractPropertyDefinition nodes */

307

TSAbstractPropertyDefinition?(node: TSESTree.TSAbstractPropertyDefinition): void;

308

/** Visitor for TSAnyKeyword nodes */

309

TSAnyKeyword?(node: TSESTree.TSAnyKeyword): void;

310

/** Visitor for TSArrayType nodes */

311

TSArrayType?(node: TSESTree.TSArrayType): void;

312

/** Visitor for TSAsExpression nodes */

313

TSAsExpression?(node: TSESTree.TSAsExpression): void;

314

/** Visitor for TSBigIntKeyword nodes */

315

TSBigIntKeyword?(node: TSESTree.TSBigIntKeyword): void;

316

/** Visitor for TSBooleanKeyword nodes */

317

TSBooleanKeyword?(node: TSESTree.TSBooleanKeyword): void;

318

/** Visitor for TSCallSignatureDeclaration nodes */

319

TSCallSignatureDeclaration?(node: TSESTree.TSCallSignatureDeclaration): void;

320

/** Visitor for TSConditionalType nodes */

321

TSConditionalType?(node: TSESTree.TSConditionalType): void;

322

/** Visitor for TSConstructorType nodes */

323

TSConstructorType?(node: TSESTree.TSConstructorType): void;

324

/** Visitor for TSConstructSignatureDeclaration nodes */

325

TSConstructSignatureDeclaration?(node: TSESTree.TSConstructSignatureDeclaration): void;

326

/** Visitor for TSDeclareFunction nodes */

327

TSDeclareFunction?(node: TSESTree.TSDeclareFunction): void;

328

/** Visitor for TSDeclareKeyword nodes */

329

TSDeclareKeyword?(node: TSESTree.TSDeclareKeyword): void;

330

/** Visitor for TSEmptyBodyFunctionExpression nodes */

331

TSEmptyBodyFunctionExpression?(node: TSESTree.TSEmptyBodyFunctionExpression): void;

332

/** Visitor for TSEnumDeclaration nodes */

333

TSEnumDeclaration?(node: TSESTree.TSEnumDeclaration): void;

334

/** Visitor for TSEnumMember nodes */

335

TSEnumMember?(node: TSESTree.TSEnumMember): void;

336

/** Visitor for TSExportKeyword nodes */

337

TSExportKeyword?(node: TSESTree.TSExportKeyword): void;

338

/** Visitor for TSExternalModuleReference nodes */

339

TSExternalModuleReference?(node: TSESTree.TSExternalModuleReference): void;

340

/** Visitor for TSFunctionType nodes */

341

TSFunctionType?(node: TSESTree.TSFunctionType): void;

342

/** Visitor for TSImportEqualsDeclaration nodes */

343

TSImportEqualsDeclaration?(node: TSESTree.TSImportEqualsDeclaration): void;

344

/** Visitor for TSImportType nodes */

345

TSImportType?(node: TSESTree.TSImportType): void;

346

/** Visitor for TSIndexedAccessType nodes */

347

TSIndexedAccessType?(node: TSESTree.TSIndexedAccessType): void;

348

/** Visitor for TSIndexSignature nodes */

349

TSIndexSignature?(node: TSESTree.TSIndexSignature): void;

350

/** Visitor for TSInferType nodes */

351

TSInferType?(node: TSESTree.TSInferType): void;

352

/** Visitor for TSInterfaceBody nodes */

353

TSInterfaceBody?(node: TSESTree.TSInterfaceBody): void;

354

/** Visitor for TSInterfaceDeclaration nodes */

355

TSInterfaceDeclaration?(node: TSESTree.TSInterfaceDeclaration): void;

356

/** Visitor for TSInterfaceHeritage nodes */

357

TSInterfaceHeritage?(node: TSESTree.TSInterfaceHeritage): void;

358

/** Visitor for TSIntersectionType nodes */

359

TSIntersectionType?(node: TSESTree.TSIntersectionType): void;

360

/** Visitor for TSIntrinsicKeyword nodes */

361

TSIntrinsicKeyword?(node: TSESTree.TSIntrinsicKeyword): void;

362

/** Visitor for TSLiteralType nodes */

363

TSLiteralType?(node: TSESTree.TSLiteralType): void;

364

/** Visitor for TSMappedType nodes */

365

TSMappedType?(node: TSESTree.TSMappedType): void;

366

/** Visitor for TSMethodSignature nodes */

367

TSMethodSignature?(node: TSESTree.TSMethodSignature): void;

368

/** Visitor for TSModuleBlock nodes */

369

TSModuleBlock?(node: TSESTree.TSModuleBlock): void;

370

/** Visitor for TSModuleDeclaration nodes */

371

TSModuleDeclaration?(node: TSESTree.TSModuleDeclaration): void;

372

/** Visitor for TSNamedTupleMember nodes */

373

TSNamedTupleMember?(node: TSESTree.TSNamedTupleMember): void;

374

/** Visitor for TSNamespaceExportDeclaration nodes */

375

TSNamespaceExportDeclaration?(node: TSESTree.TSNamespaceExportDeclaration): void;

376

/** Visitor for TSNeverKeyword nodes */

377

TSNeverKeyword?(node: TSESTree.TSNeverKeyword): void;

378

/** Visitor for TSNonNullExpression nodes */

379

TSNonNullExpression?(node: TSESTree.TSNonNullExpression): void;

380

/** Visitor for TSNullKeyword nodes */

381

TSNullKeyword?(node: TSESTree.TSNullKeyword): void;

382

/** Visitor for TSNumberKeyword nodes */

383

TSNumberKeyword?(node: TSESTree.TSNumberKeyword): void;

384

/** Visitor for TSObjectKeyword nodes */

385

TSObjectKeyword?(node: TSESTree.TSObjectKeyword): void;

386

/** Visitor for TSOptionalType nodes */

387

TSOptionalType?(node: TSESTree.TSOptionalType): void;

388

/** Visitor for TSParameterProperty nodes */

389

TSParameterProperty?(node: TSESTree.TSParameterProperty): void;

390

/** Visitor for TSPrivateKeyword nodes */

391

TSPrivateKeyword?(node: TSESTree.TSPrivateKeyword): void;

392

/** Visitor for TSPropertySignature nodes */

393

TSPropertySignature?(node: TSESTree.TSPropertySignature): void;

394

/** Visitor for TSProtectedKeyword nodes */

395

TSProtectedKeyword?(node: TSESTree.TSProtectedKeyword): void;

396

/** Visitor for TSPublicKeyword nodes */

397

TSPublicKeyword?(node: TSESTree.TSPublicKeyword): void;

398

/** Visitor for TSQualifiedName nodes */

399

TSQualifiedName?(node: TSESTree.TSQualifiedName): void;

400

/** Visitor for TSReadonlyKeyword nodes */

401

TSReadonlyKeyword?(node: TSESTree.TSReadonlyKeyword): void;

402

/** Visitor for TSRestType nodes */

403

TSRestType?(node: TSESTree.TSRestType): void;

404

/** Visitor for TSStaticKeyword nodes */

405

TSStaticKeyword?(node: TSESTree.TSStaticKeyword): void;

406

/** Visitor for TSStringKeyword nodes */

407

TSStringKeyword?(node: TSESTree.TSStringKeyword): void;

408

/** Visitor for TSSymbolKeyword nodes */

409

TSSymbolKeyword?(node: TSESTree.TSSymbolKeyword): void;

410

/** Visitor for TSTemplateLiteralType nodes */

411

TSTemplateLiteralType?(node: TSESTree.TSTemplateLiteralType): void;

412

/** Visitor for TSThisType nodes */

413

TSThisType?(node: TSESTree.TSThisType): void;

414

/** Visitor for TSTupleType nodes */

415

TSTupleType?(node: TSESTree.TSTupleType): void;

416

/** Visitor for TSTypeAliasDeclaration nodes */

417

TSTypeAliasDeclaration?(node: TSESTree.TSTypeAliasDeclaration): void;

418

/** Visitor for TSTypeAnnotation nodes */

419

TSTypeAnnotation?(node: TSESTree.TSTypeAnnotation): void;

420

/** Visitor for TSTypeAssertion nodes */

421

TSTypeAssertion?(node: TSESTree.TSTypeAssertion): void;

422

/** Visitor for TSTypeLiteral nodes */

423

TSTypeLiteral?(node: TSESTree.TSTypeLiteral): void;

424

/** Visitor for TSTypeOperator nodes */

425

TSTypeOperator?(node: TSESTree.TSTypeOperator): void;

426

/** Visitor for TSTypeParameter nodes */

427

TSTypeParameter?(node: TSESTree.TSTypeParameter): void;

428

/** Visitor for TSTypeParameterDeclaration nodes */

429

TSTypeParameterDeclaration?(node: TSESTree.TSTypeParameterDeclaration): void;

430

/** Visitor for TSTypeParameterInstantiation nodes */

431

TSTypeParameterInstantiation?(node: TSESTree.TSTypeParameterInstantiation): void;

432

/** Visitor for TSTypePredicate nodes */

433

TSTypePredicate?(node: TSESTree.TSTypePredicate): void;

434

/** Visitor for TSTypeQuery nodes */

435

TSTypeQuery?(node: TSESTree.TSTypeQuery): void;

436

/** Visitor for TSTypeReference nodes */

437

TSTypeReference?(node: TSESTree.TSTypeReference): void;

438

/** Visitor for TSUndefinedKeyword nodes */

439

TSUndefinedKeyword?(node: TSESTree.TSUndefinedKeyword): void;

440

/** Visitor for TSUnionType nodes */

441

TSUnionType?(node: TSESTree.TSUnionType): void;

442

/** Visitor for TSUnknownKeyword nodes */

443

TSUnknownKeyword?(node: TSESTree.TSUnknownKeyword): void;

444

/** Visitor for TSVoidKeyword nodes */

445

TSVoidKeyword?(node: TSESTree.TSVoidKeyword): void;

446

447

// Exit handlers (called when leaving nodes)

448

/** Exit handler for ArrayExpression nodes */

449

'ArrayExpression:exit'?(node: TSESTree.ArrayExpression): void;

450

/** Exit handler for Program nodes (commonly used for cleanup) */

451

'Program:exit'?(node: TSESTree.Program): void;

452

453

// Add all other exit handlers...

454

[key: string]: ((node: TSESTree.Node) => void) | undefined;

455

}

456

```

457

458

### Error Reporting

459

460

Types for reporting rule violations and providing fixes.

461

462

```typescript { .api }

463

/**

464

* Descriptor for reporting rule violations

465

*/

466

interface ReportDescriptor<TMessageIds extends string> {

467

/** AST node where the problem occurs */

468

node: TSESTree.Node;

469

/** Message ID from rule metadata */

470

messageId: TMessageIds;

471

/** Template data for message interpolation */

472

data?: Record<string, unknown>;

473

/** Specific source location (overrides node location) */

474

loc?: TSESTree.SourceLocation | TSESTree.LineAndColumnData;

475

/** Function to generate fix for the problem */

476

fix?: ReportFixFunction;

477

/** Array of suggested fixes */

478

suggest?: SuggestionReportDescriptor<TMessageIds>[];

479

}

480

481

/**

482

* Function that generates a fix for a rule violation

483

*/

484

type ReportFixFunction = (fixer: RuleFixer) => RuleFix | readonly RuleFix[];

485

486

/**

487

* Interface for applying code fixes

488

*/

489

interface RuleFixer {

490

/**

491

* Inserts text after the given node or token

492

*/

493

insertTextAfter(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix;

494

495

/**

496

* Inserts text after the specified range

497

*/

498

insertTextAfterRange(range: readonly [number, number], text: string): RuleFix;

499

500

/**

501

* Inserts text before the given node or token

502

*/

503

insertTextBefore(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix;

504

505

/**

506

* Inserts text before the specified range

507

*/

508

insertTextBeforeRange(range: readonly [number, number], text: string): RuleFix;

509

510

/**

511

* Removes the given node or token

512

*/

513

remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix;

514

515

/**

516

* Removes text in the specified range

517

*/

518

removeRange(range: readonly [number, number]): RuleFix;

519

520

/**

521

* Replaces the given node or token with text

522

*/

523

replaceText(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix;

524

525

/**

526

* Replaces text in the specified range

527

*/

528

replaceTextRange(range: readonly [number, number], text: string): RuleFix;

529

}

530

531

/**

532

* Individual fix operation

533

*/

534

interface RuleFix {

535

/** Character range to modify */

536

range: readonly [number, number];

537

/** Text to insert/replace */

538

text: string;

539

}

540

541

/**

542

* Suggestion descriptor for alternative fixes

543

*/

544

interface SuggestionReportDescriptor<TMessageIds extends string> {

545

/** Message ID for the suggestion */

546

messageId: TMessageIds;

547

/** Template data for suggestion message */

548

data?: Record<string, unknown>;

549

/** Function to generate the suggested fix */

550

fix: ReportFixFunction;

551

/** Human-readable description */

552

desc?: string;

553

}

554

```

555

556

### Source Code Interface

557

558

Enhanced source code interface with TypeScript support.

559

560

```typescript { .api }

561

/**

562

* Source code representation with TypeScript enhancements

563

*/

564

declare class SourceCode {

565

/** Raw source text */

566

readonly text: string;

567

/** AST root node */

568

readonly ast: TSESTree.Program;

569

/** Parsed tokens */

570

readonly tokens: TSESTree.Token[];

571

/** Comment tokens */

572

readonly comments: TSESTree.Comment[];

573

/** Token and comment locations */

574

readonly tokensAndComments: (TSESTree.Token | TSESTree.Comment)[];

575

/** Source location mapping */

576

readonly lines: string[];

577

/** Scope manager instance */

578

readonly scopeManager: Scope.ScopeManager;

579

/** AST visitor keys */

580

readonly visitorKeys: SourceCode.VisitorKeys;

581

582

/**

583

* Creates a new SourceCode instance

584

*/

585

constructor(text: string, ast: SourceCode.Program);

586

constructor(config: SourceCode.SourceCodeConfig);

587

588

/**

589

* Gets the source text for a node or range

590

*/

591

getText(node?: TSESTree.Node): string;

592

getText(node: TSESTree.Node, beforeCount: number, afterCount: number): string;

593

594

/**

595

* Gets all tokens in the source

596

*/

597

getTokens(): TSESTree.Token[];

598

getTokens(node: TSESTree.Node): TSESTree.Token[];

599

getTokens(node: TSESTree.Node, options: SourceCode.CursorWithSkipOptions): TSESTree.Token[];

600

getTokens(node: TSESTree.Node, beforeCount: number, afterCount: number): TSESTree.Token[];

601

602

/**

603

* Gets the first token of a node

604

*/

605

getFirstToken(node: TSESTree.Node): TSESTree.Token | null;

606

getFirstToken(node: TSESTree.Node, options: SourceCode.CursorWithSkipOptions): TSESTree.Token | null;

607

608

/**

609

* Gets the last token of a node

610

*/

611

getLastToken(node: TSESTree.Node): TSESTree.Token | null;

612

getLastToken(node: TSESTree.Node, options: SourceCode.CursorWithSkipOptions): TSESTree.Token | null;

613

614

/**

615

* Gets the token before a node or token

616

*/

617

getTokenBefore(node: TSESTree.Node | TSESTree.Token): TSESTree.Token | null;

618

getTokenBefore(node: TSESTree.Node | TSESTree.Token, options: SourceCode.CursorWithSkipOptions): TSESTree.Token | null;

619

620

/**

621

* Gets the token after a node or token

622

*/

623

getTokenAfter(node: TSESTree.Node | TSESTree.Token): TSESTree.Token | null;

624

getTokenAfter(node: TSESTree.Node | TSESTree.Token, options: SourceCode.CursorWithSkipOptions): TSESTree.Token | null;

625

626

/**

627

* Gets tokens between two nodes or tokens

628

*/

629

getTokensBetween(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token): TSESTree.Token[];

630

getTokensBetween(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token, padding: number): TSESTree.Token[];

631

632

/**

633

* Gets all comments

634

*/

635

getAllComments(): TSESTree.Comment[];

636

637

/**

638

* Gets comments before a node or token

639

*/

640

getCommentsBefore(node: TSESTree.Node | TSESTree.Token): TSESTree.Comment[];

641

642

/**

643

* Gets comments after a node or token

644

*/

645

getCommentsAfter(node: TSESTree.Node | TSESTree.Token): TSESTree.Comment[];

646

647

/**

648

* Gets comments inside a node

649

*/

650

getCommentsInside(node: TSESTree.Node): TSESTree.Comment[];

651

652

/**

653

* Checks if comments exist between two nodes

654

*/

655

commentsExistBetween(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token): boolean;

656

657

/**

658

* Checks if there's whitespace between two nodes

659

*/

660

isSpaceBetween(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token): boolean;

661

662

/**

663

* Gets the scope for a node

664

*/

665

getScope(node: TSESTree.Node): Scope.Scope;

666

667

/**

668

* Marks a variable as used

669

*/

670

markVariableAsUsed(name: string, node: TSESTree.Node): boolean;

671

}

672

673

declare namespace SourceCode {

674

interface Program extends TSESTree.Program {

675

comments: TSESTree.Comment[];

676

tokens: TSESTree.Token[];

677

}

678

679

interface SourceCodeConfig {

680

text: string;

681

ast: Program;

682

}

683

684

type VisitorKeys = Record<string, readonly string[]>;

685

686

type FilterPredicate = (token: TSESTree.Token) => boolean;

687

688

interface CursorWithSkipOptions {

689

skip?: number;

690

includeComments?: boolean;

691

filter?: FilterPredicate;

692

}

693

694

interface CursorWithCountOptions {

695

count?: number;

696

includeComments?: boolean;

697

filter?: FilterPredicate;

698

}

699

}

700

```

701

702

### Parser Options

703

704

TypeScript-specific parser configuration options.

705

706

```typescript { .api }

707

/**

708

* Parser options for TypeScript files

709

*/

710

interface ParserOptions {

711

/** ECMAScript version to parse */

712

ecmaVersion?: EcmaVersion;

713

/** Source type: module or script */

714

sourceType?: 'module' | 'script';

715

/** ECMAScript features */

716

ecmaFeatures?: {

717

globalReturn?: boolean;

718

impliedStrict?: boolean;

719

jsx?: boolean;

720

};

721

/** Path to TypeScript config file */

722

project?: string | string[];

723

/** TypeScript config file content */

724

tsconfigRootDir?: string;

725

/** Programs to use for type checking */

726

programs?: unknown[];

727

/** Create default program */

728

createDefaultProgram?: boolean;

729

/** Extra file extensions */

730

extraFileExtensions?: string[];

731

/** Debug level */

732

debugLevel?: DebugLevel;

733

/** Error on unknown AST node type */

734

errorOnUnknownASTType?: boolean;

735

/** Error on type script syntax in .js files */

736

errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;

737

/** Allow invalid AST */

738

allowInvalidAST?: boolean;

739

/** Tokens to include */

740

tokens?: boolean;

741

/** Comments to include */

742

comment?: boolean;

743

/** Include locations */

744

loc?: boolean;

745

/** Include ranges */

746

range?: boolean;

747

/** Attach comments */

748

attachComments?: boolean;

749

}

750

751

/**

752

* ECMAScript version specification

753

*/

754

type EcmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 'latest';

755

756

/**

757

* Parser debug levels

758

*/

759

type DebugLevel = boolean | ('typescript-eslint' | 'eslint' | 'typescript')[];

760

```

761

762

### Configuration Types

763

764

Shared configuration interfaces.

765

766

```typescript { .api }

767

/**

768

* Shared configuration between rules

769

*/

770

interface SharedConfigurationSettings {

771

[name: string]: unknown;

772

}

773

774

/**

775

* Linter environment configuration

776

*/

777

interface Environment {

778

[name: string]: boolean;

779

}

780

781

namespace Linter {

782

interface Environment {

783

[name: string]: boolean;

784

}

785

786

interface GlobalsConfig {

787

[name: string]: boolean | 'readonly' | 'writable' | 'off';

788

}

789

790

interface ProcessorConfig {

791

[name: string]: unknown;

792

}

793

}

794

```

795

796

## AST Types

797

798

```typescript { .api }

799

/**

800

* AST token representation

801

*/

802

namespace AST {

803

interface Range extends ReadonlyArray<number> {

804

0: number;

805

1: number;

806

}

807

808

interface SourceLocation {

809

start: Position;

810

end: Position;

811

}

812

813

interface Position {

814

/** 1-based line number */

815

line: number;

816

/** 0-based column number */

817

column: number;

818

}

819

820

interface Token {

821

type: string;

822

value: string;

823

range: Range;

824

loc: SourceLocation;

825

}

826

827

type TokenType =

828

| 'Boolean'

829

| 'Null'

830

| 'Identifier'

831

| 'Keyword'

832

| 'Punctuator'

833

| 'Numeric'

834

| 'String'

835

| 'RegularExpression'

836

| 'Template'

837

| 'JSXIdentifier'

838

| 'JSXText'

839

| 'Block'

840

| 'Line';

841

}

842

```