@tsslint/cli 1.5.18 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -58
- package/lib/worker.d.ts +3 -16
- package/lib/worker.js +2 -144
- package/package.json +4 -4
- package/lib/formatting.d.ts +0 -9
- package/lib/formatting.js +0 -60
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const glob = require("glob");
|
|
|
9
9
|
const fs = require("fs");
|
|
10
10
|
const os = require("os");
|
|
11
11
|
const languagePlugins = require("./lib/languagePlugins.js");
|
|
12
|
-
|
|
12
|
+
process.env.TSSLINT_CLI = '1';
|
|
13
13
|
const _reset = '\x1b[0m';
|
|
14
14
|
const purple = (s) => '\x1b[35m' + s + _reset;
|
|
15
15
|
const cyan = (s) => '\x1b[36m' + s + _reset;
|
|
@@ -93,7 +93,6 @@ class Project {
|
|
|
93
93
|
const clack = await import('@clack/prompts');
|
|
94
94
|
const processFiles = new Set();
|
|
95
95
|
const tsconfigAndLanguages = new Map();
|
|
96
|
-
const formattingSettings = getFormattingSettings();
|
|
97
96
|
const isTTY = process.stdout.isTTY;
|
|
98
97
|
let projects = [];
|
|
99
98
|
let spinner = isTTY ? clack.spinner() : undefined;
|
|
@@ -332,7 +331,7 @@ class Project {
|
|
|
332
331
|
})[0];
|
|
333
332
|
}
|
|
334
333
|
project.workers.push(linterWorker);
|
|
335
|
-
const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.fileNames, project.options
|
|
334
|
+
const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.fileNames, project.options);
|
|
336
335
|
if (!setupSuccess) {
|
|
337
336
|
projects = projects.filter(p => p !== project);
|
|
338
337
|
startWorker(linterWorker);
|
|
@@ -357,7 +356,7 @@ class Project {
|
|
|
357
356
|
}
|
|
358
357
|
}
|
|
359
358
|
else {
|
|
360
|
-
project.cache[fileName] = fileCache = [fileStat.mtimeMs, {}, {}
|
|
359
|
+
project.cache[fileName] = fileCache = [fileStat.mtimeMs, {}, {}];
|
|
361
360
|
}
|
|
362
361
|
let diagnostics = await linterWorker.lint(fileName, process.argv.includes('--fix'), fileCache);
|
|
363
362
|
diagnostics = diagnostics.filter(diagnostic => diagnostic.category !== ts.DiagnosticCategory.Suggestion);
|
|
@@ -399,60 +398,6 @@ class Project {
|
|
|
399
398
|
cache.saveCache(project.tsconfig, project.configFile, project.cache, ts.sys.createHash);
|
|
400
399
|
await startWorker(linterWorker);
|
|
401
400
|
}
|
|
402
|
-
function getFormattingSettings() {
|
|
403
|
-
let formattingSettings;
|
|
404
|
-
if (process.argv.includes('--vscode-settings')) {
|
|
405
|
-
formattingSettings = {
|
|
406
|
-
typescript: {},
|
|
407
|
-
javascript: {},
|
|
408
|
-
vue: {},
|
|
409
|
-
};
|
|
410
|
-
for (const section of ['typescript', 'javascript']) {
|
|
411
|
-
formattingSettings[section] = {
|
|
412
|
-
...ts.getDefaultFormatCodeSettings('\n'),
|
|
413
|
-
indentStyle: ts.IndentStyle.Smart,
|
|
414
|
-
newLineCharacter: '\n',
|
|
415
|
-
insertSpaceAfterCommaDelimiter: true,
|
|
416
|
-
insertSpaceAfterConstructor: false,
|
|
417
|
-
insertSpaceAfterSemicolonInForStatements: true,
|
|
418
|
-
insertSpaceBeforeAndAfterBinaryOperators: true,
|
|
419
|
-
insertSpaceAfterKeywordsInControlFlowStatements: true,
|
|
420
|
-
insertSpaceAfterFunctionKeywordForAnonymousFunctions: true,
|
|
421
|
-
insertSpaceBeforeFunctionParenthesis: false,
|
|
422
|
-
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
|
423
|
-
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
|
424
|
-
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
|
|
425
|
-
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: true,
|
|
426
|
-
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
|
427
|
-
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
|
|
428
|
-
insertSpaceAfterTypeAssertion: false,
|
|
429
|
-
placeOpenBraceOnNewLineForFunctions: false,
|
|
430
|
-
placeOpenBraceOnNewLineForControlBlocks: false,
|
|
431
|
-
semicolons: ts.SemicolonPreference.Ignore,
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
let vscodeSettingsConfig = process.argv[process.argv.indexOf('--vscode-settings') + 1];
|
|
435
|
-
if (!vscodeSettingsConfig || vscodeSettingsConfig.startsWith('-')) {
|
|
436
|
-
clack.log.error(lightRed(`Missing argument for --vscode-settings.`));
|
|
437
|
-
process.exit(1);
|
|
438
|
-
}
|
|
439
|
-
const vscodeSettingsFile = resolvePath(vscodeSettingsConfig);
|
|
440
|
-
const vscodeSettings = (0, formatting_js_1.getVSCodeFormattingSettings)(vscodeSettingsFile);
|
|
441
|
-
formattingSettings.typescript = {
|
|
442
|
-
...formattingSettings.typescript,
|
|
443
|
-
...vscodeSettings.typescript,
|
|
444
|
-
};
|
|
445
|
-
formattingSettings.javascript = {
|
|
446
|
-
...formattingSettings.javascript,
|
|
447
|
-
...vscodeSettings.javascript,
|
|
448
|
-
};
|
|
449
|
-
formattingSettings.vue = {
|
|
450
|
-
...formattingSettings.vue,
|
|
451
|
-
...vscodeSettings.vue,
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
return formattingSettings;
|
|
455
|
-
}
|
|
456
401
|
async function getBuiltConfig(configFile) {
|
|
457
402
|
if (!builtConfigs.has(configFile)) {
|
|
458
403
|
builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(darkGray(s), code)));
|
package/lib/worker.d.ts
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
import ts = require('typescript');
|
|
2
2
|
import core = require('@tsslint/core');
|
|
3
|
-
import { type getVSCodeFormattingSettings } from './formatting.js';
|
|
4
3
|
export declare function createLocal(): {
|
|
5
|
-
setup(tsconfig: string, languages: string[], configFile: string, builtConfig: string, _fileNames: string[], _options: ts.CompilerOptions
|
|
6
|
-
javascript: ts.FormatCodeSettings;
|
|
7
|
-
typescript: ts.FormatCodeSettings;
|
|
8
|
-
vue: {
|
|
9
|
-
'script.initialIndent'?: boolean;
|
|
10
|
-
};
|
|
11
|
-
} | undefined): Promise<boolean>;
|
|
4
|
+
setup(tsconfig: string, languages: string[], configFile: string, builtConfig: string, _fileNames: string[], _options: ts.CompilerOptions): Promise<boolean>;
|
|
12
5
|
lint(fileName: string, fix: boolean, fileCache: core.FileLintCache): ts.DiagnosticWithLocation[];
|
|
13
6
|
hasCodeFixes(fileName: string): boolean;
|
|
14
7
|
hasRules(fileName: string, minimatchCache: Record<string, boolean>): boolean;
|
|
15
8
|
};
|
|
16
9
|
export declare function create(): {
|
|
17
|
-
setup(tsconfig: string, languages: string[], configFile: string, builtConfig: string, _fileNames: string[], _options: ts.CompilerOptions
|
|
18
|
-
javascript: ts.FormatCodeSettings;
|
|
19
|
-
typescript: ts.FormatCodeSettings;
|
|
20
|
-
vue: {
|
|
21
|
-
'script.initialIndent'?: boolean;
|
|
22
|
-
};
|
|
23
|
-
} | undefined): Promise<boolean>;
|
|
10
|
+
setup(tsconfig: string, languages: string[], configFile: string, builtConfig: string, _fileNames: string[], _options: ts.CompilerOptions): Promise<boolean>;
|
|
24
11
|
lint(fileName: string, fix: boolean, fileCache: core.FileLintCache): Promise<ts.DiagnosticWithLocation[]>;
|
|
25
12
|
hasCodeFixes(fileName: string): Promise<boolean>;
|
|
26
13
|
hasRules(fileName: string, minimatchCache: Record<string, boolean>): Promise<boolean>;
|
|
27
14
|
};
|
|
28
|
-
declare function setup(tsconfig: string, languages: string[], configFile: string, builtConfig: string, _fileNames: string[], _options: ts.CompilerOptions
|
|
15
|
+
declare function setup(tsconfig: string, languages: string[], configFile: string, builtConfig: string, _fileNames: string[], _options: ts.CompilerOptions): Promise<boolean>;
|
|
29
16
|
declare function lint(fileName: string, fix: boolean, fileCache: core.FileLintCache): readonly [ts.DiagnosticWithLocation[], core.FileLintCache];
|
|
30
17
|
declare function hasCodeFixes(fileName: string): boolean;
|
|
31
18
|
declare function hasRules(fileName: string, minimatchCache: core.FileLintCache[2]): readonly [boolean, Record<string, boolean>];
|
package/lib/worker.js
CHANGED
|
@@ -12,8 +12,6 @@ const languagePlugins = require("./languagePlugins.js");
|
|
|
12
12
|
const language_core_1 = require("@volar/language-core");
|
|
13
13
|
const typescript_1 = require("@volar/typescript");
|
|
14
14
|
const transform_1 = require("@volar/typescript/lib/node/transform");
|
|
15
|
-
const transform_js_1 = require("@volar/typescript/lib/node/transform.js");
|
|
16
|
-
const formatting_js_1 = require("./formatting.js");
|
|
17
15
|
let projectVersion = 0;
|
|
18
16
|
let typeRootsVersion = 0;
|
|
19
17
|
let options = {};
|
|
@@ -22,42 +20,6 @@ let language;
|
|
|
22
20
|
let linter;
|
|
23
21
|
let linterLanguageService;
|
|
24
22
|
let linterSyntaxOnlyLanguageService;
|
|
25
|
-
let fmtSettings;
|
|
26
|
-
const formatLanguageService = ts.createLanguageService({
|
|
27
|
-
...ts.sys,
|
|
28
|
-
getCompilationSettings() {
|
|
29
|
-
return options;
|
|
30
|
-
},
|
|
31
|
-
getScriptFileNames() {
|
|
32
|
-
return [];
|
|
33
|
-
},
|
|
34
|
-
getScriptVersion() {
|
|
35
|
-
return '0';
|
|
36
|
-
},
|
|
37
|
-
getScriptSnapshot() {
|
|
38
|
-
return formattingSnapshot;
|
|
39
|
-
},
|
|
40
|
-
getScriptKind() {
|
|
41
|
-
return formattingScriptKind;
|
|
42
|
-
},
|
|
43
|
-
useCaseSensitiveFileNames() {
|
|
44
|
-
return ts.sys.useCaseSensitiveFileNames;
|
|
45
|
-
},
|
|
46
|
-
getCurrentDirectory() {
|
|
47
|
-
return ts.sys.getCurrentDirectory();
|
|
48
|
-
},
|
|
49
|
-
getDefaultLibFileName() {
|
|
50
|
-
return ts.getDefaultLibFilePath(options);
|
|
51
|
-
},
|
|
52
|
-
}, undefined, true);
|
|
53
|
-
let formattingSnapshot;
|
|
54
|
-
let formattingScriptKind;
|
|
55
|
-
let formattingIndex = 0;
|
|
56
|
-
function formatVirtualScript(kind, settings, snapshot) {
|
|
57
|
-
formattingSnapshot = snapshot;
|
|
58
|
-
formattingScriptKind = kind;
|
|
59
|
-
return formatLanguageService.getFormattingEditsForDocument(`${formattingIndex++}.txt`, settings);
|
|
60
|
-
}
|
|
61
23
|
const snapshots = new Map();
|
|
62
24
|
const versions = new Map();
|
|
63
25
|
const originalHost = {
|
|
@@ -165,7 +127,7 @@ const handlers = {
|
|
|
165
127
|
hasCodeFixes,
|
|
166
128
|
hasRules,
|
|
167
129
|
};
|
|
168
|
-
async function setup(tsconfig, languages, configFile, builtConfig, _fileNames, _options
|
|
130
|
+
async function setup(tsconfig, languages, configFile, builtConfig, _fileNames, _options) {
|
|
169
131
|
const clack = await import('@clack/prompts');
|
|
170
132
|
let config;
|
|
171
133
|
try {
|
|
@@ -222,12 +184,11 @@ async function setup(tsconfig, languages, configFile, builtConfig, _fileNames, _
|
|
|
222
184
|
allowNonTsExtensions: true,
|
|
223
185
|
}
|
|
224
186
|
: _options;
|
|
225
|
-
fmtSettings = _fmtSettings;
|
|
226
187
|
linter = core.createLinter({
|
|
227
188
|
languageService: linterLanguageService,
|
|
228
189
|
languageServiceHost: linterHost,
|
|
229
190
|
typescript: ts,
|
|
230
|
-
}, path.dirname(configFile), config,
|
|
191
|
+
}, path.dirname(configFile), config, () => { }, linterSyntaxOnlyLanguageService);
|
|
231
192
|
return true;
|
|
232
193
|
}
|
|
233
194
|
function lint(fileName, fix, fileCache) {
|
|
@@ -253,114 +214,12 @@ function lint(fileName, fix, fileCache) {
|
|
|
253
214
|
}
|
|
254
215
|
const textChanges = core.combineCodeFixes(fileName, fixes);
|
|
255
216
|
if (textChanges.length) {
|
|
256
|
-
fileCache[3] = false;
|
|
257
217
|
const oldSnapshot = snapshots.get(fileName);
|
|
258
218
|
newSnapshot = core.applyTextChanges(oldSnapshot, textChanges);
|
|
259
219
|
snapshots.set(fileName, newSnapshot);
|
|
260
220
|
versions.set(fileName, (versions.get(fileName) ?? 0) + 1);
|
|
261
221
|
projectVersion++;
|
|
262
222
|
}
|
|
263
|
-
if (!fileCache[3] && fmtSettings) {
|
|
264
|
-
fileCache[3] = true;
|
|
265
|
-
let script = language?.scripts.get(fileName);
|
|
266
|
-
let linterEdits = [];
|
|
267
|
-
let serviceEdits = [];
|
|
268
|
-
if (script?.generated) {
|
|
269
|
-
for (const code of (0, language_core_1.forEachEmbeddedCode)(script.generated.root)) {
|
|
270
|
-
if ((code.languageId === 'javascript'
|
|
271
|
-
|| code.languageId === 'typescript'
|
|
272
|
-
|| code.languageId === 'javascriptreact'
|
|
273
|
-
|| code.languageId === 'typescriptreact')
|
|
274
|
-
&& code.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data))) {
|
|
275
|
-
const scriptKind = code.languageId === 'javascript' ? ts.ScriptKind.JS
|
|
276
|
-
: code.languageId === 'javascriptreact' ? ts.ScriptKind.JSX
|
|
277
|
-
: code.languageId === 'typescript' ? ts.ScriptKind.TS
|
|
278
|
-
: ts.ScriptKind.TSX;
|
|
279
|
-
const sourceFile = ts.createSourceFile(fileName, code.snapshot.getText(0, code.snapshot.getLength()), ts.ScriptTarget.Latest, true, scriptKind);
|
|
280
|
-
linterEdits.push(...linter
|
|
281
|
-
.format(sourceFile, fileCache[2])
|
|
282
|
-
.map(edit => {
|
|
283
|
-
return (0, transform_js_1.transformTextChange)(script, language, {
|
|
284
|
-
code,
|
|
285
|
-
extension: '',
|
|
286
|
-
scriptKind: scriptKind,
|
|
287
|
-
preventLeadingOffset: true,
|
|
288
|
-
}, edit, false, language_core_1.isFormattingEnabled)?.[1];
|
|
289
|
-
})
|
|
290
|
-
.filter(edit => !!edit));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
const sourceFile = originalSyntaxOnlyService.getNonBoundSourceFile(fileName);
|
|
296
|
-
linterEdits = linter.format(sourceFile, fileCache[2]);
|
|
297
|
-
}
|
|
298
|
-
if (linterEdits.length) {
|
|
299
|
-
const oldSnapshot = snapshots.get(fileName);
|
|
300
|
-
newSnapshot = core.applyTextChanges(oldSnapshot, linterEdits);
|
|
301
|
-
snapshots.set(fileName, newSnapshot);
|
|
302
|
-
versions.set(fileName, (versions.get(fileName) ?? 0) + 1);
|
|
303
|
-
projectVersion++;
|
|
304
|
-
script = language?.scripts.get(fileName);
|
|
305
|
-
}
|
|
306
|
-
if (script?.generated) {
|
|
307
|
-
let sourceFile;
|
|
308
|
-
for (const code of (0, language_core_1.forEachEmbeddedCode)(script.generated.root)) {
|
|
309
|
-
if ((code.languageId === 'javascript'
|
|
310
|
-
|| code.languageId === 'typescript'
|
|
311
|
-
|| code.languageId === 'javascriptreact'
|
|
312
|
-
|| code.languageId === 'typescriptreact')
|
|
313
|
-
&& code.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data))) {
|
|
314
|
-
const scriptKind = code.languageId === 'javascript' ? ts.ScriptKind.JS
|
|
315
|
-
: code.languageId === 'javascriptreact' ? ts.ScriptKind.JSX
|
|
316
|
-
: code.languageId === 'typescript' ? ts.ScriptKind.TS
|
|
317
|
-
: ts.ScriptKind.TSX;
|
|
318
|
-
let settings = scriptKind === ts.ScriptKind.JS || scriptKind === ts.ScriptKind.JSX
|
|
319
|
-
? fmtSettings.javascript
|
|
320
|
-
: fmtSettings.typescript;
|
|
321
|
-
if (settings.tabSize !== undefined) {
|
|
322
|
-
const firstMapping = code.mappings[0];
|
|
323
|
-
sourceFile ??= ts.createSourceFile(fileName, script.snapshot.getText(0, script.snapshot.getLength()), ts.ScriptTarget.Latest, true, ts.ScriptKind.Deferred);
|
|
324
|
-
const line = sourceFile.getLineAndCharacterOfPosition(firstMapping.sourceOffsets[0]).line;
|
|
325
|
-
const offset = sourceFile.getPositionOfLineAndCharacter(line, 0);
|
|
326
|
-
let initialIndentLevel = (0, formatting_js_1.computeInitialIndent)(script.snapshot.getText(0, script.snapshot.getLength()), offset, settings.tabSize);
|
|
327
|
-
if (script.languageId === 'vue'
|
|
328
|
-
&& fmtSettings.vue['script.initialIndent']
|
|
329
|
-
&& (code.id === 'script_raw'
|
|
330
|
-
|| code.id === 'scriptsetup_raw')) {
|
|
331
|
-
initialIndentLevel++;
|
|
332
|
-
}
|
|
333
|
-
settings = {
|
|
334
|
-
...settings,
|
|
335
|
-
baseIndentSize: initialIndentLevel * settings.tabSize,
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
serviceEdits.push(...formatVirtualScript(scriptKind, settings, code.snapshot)
|
|
339
|
-
.map(edit => {
|
|
340
|
-
return (0, transform_js_1.transformTextChange)(script, language, {
|
|
341
|
-
code,
|
|
342
|
-
extension: '',
|
|
343
|
-
scriptKind: scriptKind,
|
|
344
|
-
preventLeadingOffset: true,
|
|
345
|
-
}, edit, false, language_core_1.isFormattingEnabled)?.[1];
|
|
346
|
-
})
|
|
347
|
-
.filter(edit => !!edit));
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
const scriptKind = linterHost.getScriptKind(fileName);
|
|
353
|
-
const settings = scriptKind === ts.ScriptKind.JS || scriptKind === ts.ScriptKind.JSX ? fmtSettings.javascript : fmtSettings.typescript;
|
|
354
|
-
serviceEdits = linterLanguageService.getFormattingEditsForDocument(fileName, settings);
|
|
355
|
-
}
|
|
356
|
-
if (serviceEdits.length) {
|
|
357
|
-
const oldSnapshot = snapshots.get(fileName);
|
|
358
|
-
newSnapshot = core.applyTextChanges(oldSnapshot, serviceEdits);
|
|
359
|
-
snapshots.set(fileName, newSnapshot);
|
|
360
|
-
versions.set(fileName, (versions.get(fileName) ?? 0) + 1);
|
|
361
|
-
projectVersion++;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
223
|
}
|
|
365
224
|
if (newSnapshot) {
|
|
366
225
|
const newText = newSnapshot.getText(0, newSnapshot.getLength());
|
|
@@ -370,7 +229,6 @@ function lint(fileName, fix, fileCache) {
|
|
|
370
229
|
fileCache[0] = fs.statSync(fileName).mtimeMs;
|
|
371
230
|
fileCache[1] = {};
|
|
372
231
|
fileCache[2] = {};
|
|
373
|
-
fileCache[3] = false;
|
|
374
232
|
shouldCheck = true;
|
|
375
233
|
}
|
|
376
234
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tsslint": "./bin/tsslint.js"
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@clack/prompts": "^0.8.2",
|
|
19
|
-
"@tsslint/config": "1.
|
|
20
|
-
"@tsslint/core": "1.
|
|
19
|
+
"@tsslint/config": "1.6.1",
|
|
20
|
+
"@tsslint/core": "1.6.1",
|
|
21
21
|
"@volar/language-core": "~2.4.0",
|
|
22
22
|
"@volar/language-hub": "0.0.1",
|
|
23
23
|
"@volar/typescript": "~2.4.0",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@vue-vine/language-service": "latest",
|
|
32
32
|
"@vue/language-core": "latest"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "875699df671c2d9a8331c930af8c549ebab19f17"
|
|
35
35
|
}
|
package/lib/formatting.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
|
-
export declare function getVSCodeFormattingSettings(settingsFile: string): {
|
|
3
|
-
javascript: ts.FormatCodeSettings;
|
|
4
|
-
typescript: ts.FormatCodeSettings;
|
|
5
|
-
vue: {
|
|
6
|
-
'script.initialIndent'?: boolean;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export declare function computeInitialIndent(content: string, i: number, baseTabSize?: number): number;
|
package/lib/formatting.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVSCodeFormattingSettings = getVSCodeFormattingSettings;
|
|
4
|
-
exports.computeInitialIndent = computeInitialIndent;
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const json5 = require("json5");
|
|
7
|
-
function getVSCodeFormattingSettings(settingsFile) {
|
|
8
|
-
const jsonc = fs.readFileSync(settingsFile, 'utf8');
|
|
9
|
-
const editorSettings = json5.parse(jsonc);
|
|
10
|
-
const jsSettings = {};
|
|
11
|
-
const tsSettings = {};
|
|
12
|
-
const vueSettings = {};
|
|
13
|
-
if ('editor.insertSpaces' in editorSettings) {
|
|
14
|
-
jsSettings.convertTabsToSpaces = !!editorSettings['editor.insertSpaces'];
|
|
15
|
-
tsSettings.convertTabsToSpaces = !!editorSettings['editor.insertSpaces'];
|
|
16
|
-
}
|
|
17
|
-
if ('editor.tabSize' in editorSettings) {
|
|
18
|
-
jsSettings.tabSize = editorSettings['editor.tabSize'];
|
|
19
|
-
tsSettings.tabSize = editorSettings['editor.tabSize'];
|
|
20
|
-
}
|
|
21
|
-
for (const key in editorSettings) {
|
|
22
|
-
if (key.startsWith('javascript.format.')) {
|
|
23
|
-
const settingKey = key.slice('javascript.format.'.length);
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
jsSettings[settingKey] = editorSettings[key];
|
|
26
|
-
}
|
|
27
|
-
else if (key.startsWith('typescript.format.')) {
|
|
28
|
-
const settingKey = key.slice('typescript.format.'.length);
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
tsSettings[settingKey] = editorSettings[key];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if ('vue.format.script.initialIndent' in editorSettings) {
|
|
34
|
-
vueSettings['script.initialIndent'] = !!editorSettings['vue.format.script.initialIndent'];
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
javascript: jsSettings,
|
|
38
|
-
typescript: tsSettings,
|
|
39
|
-
vue: vueSettings,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function computeInitialIndent(content, i, baseTabSize) {
|
|
43
|
-
let nChars = 0;
|
|
44
|
-
const tabSize = baseTabSize || 4;
|
|
45
|
-
while (i < content.length) {
|
|
46
|
-
const ch = content.charAt(i);
|
|
47
|
-
if (ch === ' ') {
|
|
48
|
-
nChars++;
|
|
49
|
-
}
|
|
50
|
-
else if (ch === '\t') {
|
|
51
|
-
nChars += tabSize;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
i++;
|
|
57
|
-
}
|
|
58
|
-
return Math.floor(nChars / tabSize);
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=formatting.js.map
|