microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/lint/src/types.ts
69lines · modecode
| 1 | import { Program, SemanticNodeListener } from "@cadl-lang/compiler"; |
| 2 | |
| 3 | export interface RegisterRuleOptions { |
| 4 | autoEnable?: boolean; |
| 5 | } |
| 6 | |
| 7 | export interface Linter { |
| 8 | /** |
| 9 | * Register a new rule. |
| 10 | * @param rule Rule to register. |
| 11 | */ |
| 12 | registerRule(rule: LintRule): void; |
| 13 | /** |
| 14 | * Register a new set of rules. |
| 15 | * @param rule Rule to register. |
| 16 | */ |
| 17 | registerRules(rules: LintRule[]): void; |
| 18 | |
| 19 | /** |
| 20 | * Enable the rule with the given name. |
| 21 | */ |
| 22 | enableRule(name: string): void; |
| 23 | |
| 24 | /** |
| 25 | * Enable the rules with the given names. |
| 26 | */ |
| 27 | enableRules(names: string[]): void; |
| 28 | |
| 29 | /** |
| 30 | * Register the linter for this program. |
| 31 | * Doesn't lint immediately. Register the linter as a `onValidate` step. |
| 32 | * @param program Program. |
| 33 | */ |
| 34 | lintOnValidate(program: Program): void; |
| 35 | |
| 36 | /** |
| 37 | * @internal |
| 38 | * Lint the given program, adding diagnostics. |
| 39 | * @param program Program to lint |
| 40 | */ |
| 41 | lintProgram(program: Program): void; |
| 42 | } |
| 43 | |
| 44 | export interface LibraryLinter extends Linter { |
| 45 | /** |
| 46 | * Register a new rule. |
| 47 | * @param rule Rule to register. |
| 48 | */ |
| 49 | registerRule(rule: LintRule, options?: RegisterRuleOptions): void; |
| 50 | /** |
| 51 | * Register a new set of rules. |
| 52 | * @param rule Rule to register. |
| 53 | */ |
| 54 | registerRules(rules: LintRule[], options?: RegisterRuleOptions): void; |
| 55 | |
| 56 | /** |
| 57 | * Automatically enable the rules marked with auto enable |
| 58 | */ |
| 59 | autoEnableRules(): void; |
| 60 | } |
| 61 | |
| 62 | export interface LintRule { |
| 63 | name: string; |
| 64 | create(context: LintContext): SemanticNodeListener; |
| 65 | } |
| 66 | |
| 67 | export interface LintContext { |
| 68 | program: Program; |
| 69 | } |
| 70 | |