@tsslint/cli 1.5.17 → 1.6.0

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 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
- const formatting_js_1 = require("./lib/formatting.js");
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;
@@ -290,12 +289,6 @@ class Project {
290
289
  (spinner?.stop ?? clack.log.message)(cached
291
290
  ? darkGray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + darkGray(` to ignore cache.)`)
292
291
  : darkGray(`Processed ${processed} files.`));
293
- if (process.argv.includes('--fix') && !formattingSettings) {
294
- const vscodeSettings = ts.findConfigFile(process.cwd(), ts.sys.fileExists, '.vscode/settings.json');
295
- if (vscodeSettings) {
296
- clack.log.message(darkGray(`Found available editor settings, you can use `) + cyan(`--vscode-settings ${path.relative(process.cwd(), vscodeSettings)}`) + darkGray(` to enable code format.`));
297
- }
298
- }
299
292
  const projectsFlag = process.argv.find(arg => arg.endsWith('-projects'));
300
293
  if (projectsFlag) {
301
294
  clack.log.warn(darkGray(`Please use `)
@@ -338,7 +331,7 @@ class Project {
338
331
  })[0];
339
332
  }
340
333
  project.workers.push(linterWorker);
341
- const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.fileNames, project.options, formattingSettings);
334
+ const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.fileNames, project.options);
342
335
  if (!setupSuccess) {
343
336
  projects = projects.filter(p => p !== project);
344
337
  startWorker(linterWorker);
@@ -363,7 +356,7 @@ class Project {
363
356
  }
364
357
  }
365
358
  else {
366
- project.cache[fileName] = fileCache = [fileStat.mtimeMs, {}, {}, false];
359
+ project.cache[fileName] = fileCache = [fileStat.mtimeMs, {}, {}];
367
360
  }
368
361
  let diagnostics = await linterWorker.lint(fileName, process.argv.includes('--fix'), fileCache);
369
362
  diagnostics = diagnostics.filter(diagnostic => diagnostic.category !== ts.DiagnosticCategory.Suggestion);
@@ -405,60 +398,6 @@ class Project {
405
398
  cache.saveCache(project.tsconfig, project.configFile, project.cache, ts.sys.createHash);
406
399
  await startWorker(linterWorker);
407
400
  }
408
- function getFormattingSettings() {
409
- let formattingSettings;
410
- if (process.argv.includes('--vscode-settings')) {
411
- formattingSettings = {
412
- typescript: {},
413
- javascript: {},
414
- vue: {},
415
- };
416
- for (const section of ['typescript', 'javascript']) {
417
- formattingSettings[section] = {
418
- ...ts.getDefaultFormatCodeSettings('\n'),
419
- indentStyle: ts.IndentStyle.Smart,
420
- newLineCharacter: '\n',
421
- insertSpaceAfterCommaDelimiter: true,
422
- insertSpaceAfterConstructor: false,
423
- insertSpaceAfterSemicolonInForStatements: true,
424
- insertSpaceBeforeAndAfterBinaryOperators: true,
425
- insertSpaceAfterKeywordsInControlFlowStatements: true,
426
- insertSpaceAfterFunctionKeywordForAnonymousFunctions: true,
427
- insertSpaceBeforeFunctionParenthesis: false,
428
- insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
429
- insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
430
- insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
431
- insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: true,
432
- insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
433
- insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
434
- insertSpaceAfterTypeAssertion: false,
435
- placeOpenBraceOnNewLineForFunctions: false,
436
- placeOpenBraceOnNewLineForControlBlocks: false,
437
- semicolons: ts.SemicolonPreference.Ignore,
438
- };
439
- }
440
- let vscodeSettingsConfig = process.argv[process.argv.indexOf('--vscode-settings') + 1];
441
- if (!vscodeSettingsConfig || vscodeSettingsConfig.startsWith('-')) {
442
- clack.log.error(lightRed(`Missing argument for --vscode-settings.`));
443
- process.exit(1);
444
- }
445
- const vscodeSettingsFile = resolvePath(vscodeSettingsConfig);
446
- const vscodeSettings = (0, formatting_js_1.getVSCodeFormattingSettings)(vscodeSettingsFile);
447
- formattingSettings.typescript = {
448
- ...formattingSettings.typescript,
449
- ...vscodeSettings.typescript,
450
- };
451
- formattingSettings.javascript = {
452
- ...formattingSettings.javascript,
453
- ...vscodeSettings.javascript,
454
- };
455
- formattingSettings.vue = {
456
- ...formattingSettings.vue,
457
- ...vscodeSettings.vue,
458
- };
459
- }
460
- return formattingSettings;
461
- }
462
401
  async function getBuiltConfig(configFile) {
463
402
  if (!builtConfigs.has(configFile)) {
464
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, _fmtSettings: {
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, _fmtSettings: {
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, _fmtSettings: ReturnType<typeof getVSCodeFormattingSettings> | undefined): Promise<boolean>;
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, _fmtSettings) {
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, 'cli', linterSyntaxOnlyLanguageService);
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.5.17",
3
+ "version": "1.6.0",
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.5.17",
20
- "@tsslint/core": "1.5.17",
19
+ "@tsslint/config": "1.6.0",
20
+ "@tsslint/core": "1.6.0",
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": "e9f145a91f3e7bd9ba86dd0de41ff7a8ffd99b46"
34
+ "gitHead": "c1cec085945f166911af87454f6f1dd3e9fc2986"
35
35
  }
@@ -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