-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathsettings.ts
178 lines (153 loc) · 4.2 KB
/
settings.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import {
WorkspaceFolder
} from 'vscode-languageserver-protocol';
namespace Is {
const toString = Object.prototype.toString;
export function boolean(value: any): value is boolean {
return value === true || value === false;
}
export function string(value: any): value is string {
return toString.call(value) === '[object String]';
}
}
export enum Validate {
on = 'on',
off = 'off',
probe = 'probe'
}
export type CodeActionSettings = {
disableRuleComment: {
enable: boolean;
location: 'separateLine' | 'sameLine';
commentStyle: 'line' | 'block';
};
showDocumentation: {
enable: boolean;
};
};
export enum CodeActionsOnSaveMode {
all = 'all',
problems = 'problems'
}
export namespace CodeActionsOnSaveMode {
export function from(value: string | undefined | null): CodeActionsOnSaveMode {
if (value === undefined || value === null || !Is.string(value)) {
return CodeActionsOnSaveMode.all;
}
switch(value.toLowerCase()) {
case CodeActionsOnSaveMode.problems:
return CodeActionsOnSaveMode.problems;
default:
return CodeActionsOnSaveMode.all;
}
}
}
export namespace CodeActionsOnSaveRules {
export function from(value: string[] | undefined | null): string[] | undefined {
if (value === undefined || value === null || !Array.isArray(value)) {
return undefined;
}
return value.filter(item => Is.string(item));
}
}
export type CodeActionsOnSaveSettings = {
mode: CodeActionsOnSaveMode;
rules?: string[];
};
export enum ESLintSeverity {
off = 'off',
warn = 'warn',
error = 'error'
}
export namespace ESLintSeverity {
export function from(value: string | undefined | null): ESLintSeverity {
if (value === undefined || value === null) {
return ESLintSeverity.off;
}
switch (value.toLowerCase()) {
case ESLintSeverity.off:
return ESLintSeverity.off;
case ESLintSeverity.warn:
return ESLintSeverity.warn;
case ESLintSeverity.error:
return ESLintSeverity.error;
default:
return ESLintSeverity.off;
}
}
}
export enum RuleSeverity {
// Original ESLint values
info = 'info',
warn = 'warn',
error = 'error',
off = 'off',
// Added severity override changes
default = 'default',
downgrade = 'downgrade',
upgrade = 'upgrade'
}
export type RuleCustomization = {
rule: string;
severity: RuleSeverity;
/** Only apply to autofixable rules */
fixable?: boolean;
};
export type RunValues = 'onType' | 'onSave';
export enum ModeEnum {
auto = 'auto',
location = 'location'
}
export namespace ModeEnum {
export function is(value: string): value is ModeEnum {
return value === ModeEnum.auto || value === ModeEnum.location;
}
}
export type ModeItem = {
mode: ModeEnum;
};
export namespace ModeItem {
export function is(item: any): item is ModeItem {
const candidate = item as ModeItem;
return candidate && ModeEnum.is(candidate.mode);
}
}
export type DirectoryItem = {
directory: string;
'!cwd'?: boolean;
};
export namespace DirectoryItem {
export function is(item: any): item is DirectoryItem {
const candidate = item as DirectoryItem;
return candidate && Is.string(candidate.directory) && (Is.boolean(candidate['!cwd']) || candidate['!cwd'] === undefined);
}
}
export type PackageManagers = 'npm' | 'yarn' | 'pnpm';
export type ESLintOptions = object & { fixTypes?: string[] };
export type ConfigurationSettings = {
validate: Validate;
packageManager: PackageManagers;
useESLintClass: boolean;
useFlatConfig?: boolean | undefined;
experimental: {
useFlatConfig: boolean;
};
codeAction: CodeActionSettings;
codeActionOnSave: CodeActionsOnSaveSettings;
format: boolean;
quiet: boolean;
onIgnoredFiles: ESLintSeverity;
options: ESLintOptions | undefined;
rulesCustomizations: RuleCustomization[];
run: RunValues;
problems: {
shortenToSingleLine: boolean;
};
nodePath: string | null;
workspaceFolder: WorkspaceFolder | undefined;
workingDirectory: ModeItem | DirectoryItem | undefined;
};