/
types.ts
121 lines (98 loc) · 3.72 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import type { DiagnosticSeverity } from '@stoplight/types';
import type { Format } from './format';
import type { RulesetFunction, RulesetFunctionWithValidator } from '../types';
import type { Formats } from './formats';
export type HumanReadableDiagnosticSeverity = 'error' | 'warn' | 'info' | 'hint' | 'off';
export type FileRuleSeverityDefinition = DiagnosticSeverity | HumanReadableDiagnosticSeverity | boolean;
export type FileRulesetSeverityDefinition = 'off' | 'recommended' | 'all';
export type FileRuleDefinition = RuleDefinition | FileRuleSeverityDefinition;
export type ParserOptions = {
duplicateKeys: DiagnosticSeverity | HumanReadableDiagnosticSeverity;
incompatibleValues: DiagnosticSeverity | HumanReadableDiagnosticSeverity;
};
export type RuleDefinition = {
type?: 'validation' | 'style';
formats?: Formats | Format[];
documentationUrl?: string;
// A meaningful feedback about the error
message?: string;
// A long-form description of the rule formatted in markdown
description?: string;
// The severity of results this rule generates
severity?: DiagnosticSeverity | HumanReadableDiagnosticSeverity;
// some rules are more important than others, recommended rules will be enabled by default
// true by default
recommended?: boolean;
// Filter the target down to a subset[] with a JSON path
given: GivenDefinition;
// If false, rule will operate on original (unresolved) data
// If undefined or true, resolved data will be supplied
resolved?: boolean;
then: IRuleThen | IRuleThen[];
};
export interface IRuleThen {
// the `path.to.prop` to field, or special `@key` value to target keys for matched `given` object
// EXAMPLE: if the target object is an oas object and given = `$..responses[*]`, then `@key` would be the response code (200, 400, etc)
field?: string;
// name of the function to run
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function: RulesetFunction<any, any> | RulesetFunctionWithValidator<any, any>;
// Options passed to the function
functionOptions?: unknown;
}
export type GivenDefinition = string | string[];
export type RulesetExtendsDefinition =
| RulesetDefinition
| (RulesetDefinition | [RulesetDefinition, FileRulesetSeverityDefinition])[];
export type RulesetOverrideDefinition = Pick<RulesetDefinition, 'formats' | 'parserOptions' | 'aliases'> &
(
| {
extends: RulesetExtendsDefinition;
}
| {
rules: Record<string, Readonly<FileRuleDefinition>>;
}
| {
extends: RulesetExtendsDefinition;
rules: Record<string, Readonly<FileRuleDefinition>>;
}
);
export type RulesetOverridesDefinition = ReadonlyArray<{ files: string[] } & RulesetOverrideDefinition>;
export type RulesetScopedAliasDefinition = {
description?: string;
targets: {
formats: Formats | Format[];
given: string[];
}[];
};
export type RulesetAliasesDefinition = Record<string, string[] | RulesetScopedAliasDefinition>;
export type RulesetDefinition = Readonly<
{
documentationUrl?: string;
description?: string;
formats?: Formats | Format[];
parserOptions?: Partial<ParserOptions>;
overrides?: RulesetOverridesDefinition;
aliases?: RulesetAliasesDefinition;
} & Readonly<
| {
overrides: RulesetOverridesDefinition;
}
| {
extends: RulesetExtendsDefinition;
}
| {
rules: Record<string, Readonly<RuleDefinition>>;
}
| {
extends: RulesetExtendsDefinition;
rules: Record<string, Readonly<FileRuleDefinition>>;
}
>
>;
// eslint-disable-next-line @typescript-eslint/ban-types
export type Stringifable<T> = T extends object
? {
[P in keyof T]: Stringifable<T[P]> | { toJSON?(): Stringifable<T[P]> };
}
: T;