@tsslint/cli 2.0.2 → 2.0.4

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.
Files changed (2) hide show
  1. package/index.js +57 -43
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -11,13 +11,13 @@ 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
- const purple = (s) => '\x1b[35m' + s + _reset;
15
- const cyan = (s) => '\x1b[36m' + s + _reset;
16
- const darkGray = (s) => '\x1b[90m' + s + _reset;
17
- const lightRed = (s) => '\x1b[91m' + s + _reset;
18
- const lightGreen = (s) => '\x1b[92m' + s + _reset;
19
- const lightYellow = (s) => '\x1b[93m' + s + _reset;
20
- const lightBlue = (s) => '\x1b[94m' + s + _reset;
14
+ const gray = (s) => '\x1b[90m' + s + _reset;
15
+ const red = (s) => '\x1b[91m' + s + _reset;
16
+ const green = (s) => '\x1b[92m' + s + _reset;
17
+ const yellow = (s) => '\x1b[93m' + s + _reset;
18
+ const blue = (s) => '\x1b[94m' + s + _reset;
19
+ const purple = (s) => '\x1b[95m' + s + _reset;
20
+ const cyan = (s) => '\x1b[96m' + s + _reset;
21
21
  // https://talyian.github.io/ansicolors/
22
22
  const tsColor = (s) => '\x1b[34m' + s + _reset;
23
23
  const tsMacroColor = (s) => '\x1b[38;5;135m' + s + _reset;
@@ -30,7 +30,7 @@ if (process.argv.includes('--threads')) {
30
30
  const threadsIndex = process.argv.indexOf('--threads');
31
31
  const threadsArg = process.argv[threadsIndex + 1];
32
32
  if (!threadsArg || threadsArg.startsWith('-')) {
33
- console.error(lightRed(`Missing argument for --threads.`));
33
+ console.error(red(`Missing argument for --threads.`));
34
34
  process.exit(1);
35
35
  }
36
36
  threads = Math.min(os.availableParallelism(), Number(threadsArg));
@@ -70,19 +70,19 @@ class Project {
70
70
  labels.push(astroColor('Astro'));
71
71
  }
72
72
  }
73
- const label = labels.join(darkGray(' | '));
73
+ const label = labels.join(gray(' | '));
74
74
  if (!this.configFile) {
75
- clack.log.error(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray('(No tsslint.config.ts found)')}`);
75
+ clack.log.error(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No tsslint.config.ts found)')}`);
76
76
  return this;
77
77
  }
78
78
  const commonLine = await parseCommonLine(this.tsconfig, this.languages);
79
79
  this.fileNames = commonLine.fileNames;
80
80
  this.options = commonLine.options;
81
81
  if (!this.fileNames.length) {
82
- clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray('(No included files)')}`);
82
+ clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No included files)')}`);
83
83
  return this;
84
84
  }
85
- clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray(`(${this.fileNames.length})`)}`);
85
+ clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray(`(${this.fileNames.length})`)}`);
86
86
  if (!process.argv.includes('--force')) {
87
87
  this.cache = cache.loadCache(this.tsconfig, this.configFile, ts.sys.createHash);
88
88
  }
@@ -106,12 +106,13 @@ class Project {
106
106
  let errors = 0;
107
107
  let warnings = 0;
108
108
  let messages = 0;
109
+ let suggestions = 0;
109
110
  let cached = 0;
110
111
  if (isTTY) {
111
112
  const write = process.stdout.write.bind(process.stdout);
112
113
  process.stdout.write = (...args) => {
113
114
  if (spinnerStopingWarn && typeof args[0] === 'string') {
114
- args[0] = args[0].replace('▲', lightYellow('▲'));
115
+ args[0] = args[0].replace('▲', yellow('▲'));
115
116
  }
116
117
  // @ts-ignore
117
118
  return write(...args);
@@ -176,7 +177,7 @@ class Project {
176
177
  options = options.filter(option => !option.label.endsWith('(0)'));
177
178
  }
178
179
  if (!options.length) {
179
- clack.log.error(lightRed('No projects found.'));
180
+ clack.log.error(red('No projects found.'));
180
181
  process.exit(1);
181
182
  }
182
183
  const selectedTsconfigs = await clack.multiselect({
@@ -195,7 +196,7 @@ class Project {
195
196
  else {
196
197
  command += ` --${language}-project ` + selectedTsconfigs.join(' ');
197
198
  }
198
- clack.log.info(`${darkGray('Command:')} ${purple(command)}`);
199
+ clack.log.info(`${gray('Command:')} ${purple(command)}`);
199
200
  for (let tsconfig of selectedTsconfigs) {
200
201
  tsconfig = resolvePath(tsconfig);
201
202
  tsconfigAndLanguages.set(tsconfig, language ? [language] : []);
@@ -244,7 +245,7 @@ class Project {
244
245
  const searchGlob = process.argv[i];
245
246
  const tsconfigs = glob.sync(searchGlob);
246
247
  if (!tsconfigs.length) {
247
- clack.log.error(lightRed(`No projects found for ${projectFlag} ${searchGlob}.`));
248
+ clack.log.error(red(`No projects found for ${projectFlag} ${searchGlob}.`));
248
249
  process.exit(1);
249
250
  }
250
251
  for (let tsconfig of tsconfigs) {
@@ -258,7 +259,7 @@ class Project {
258
259
  }
259
260
  }
260
261
  if (!foundArg) {
261
- clack.log.error(lightRed(`Missing argument for ${projectFlag}.`));
262
+ clack.log.error(red(`Missing argument for ${projectFlag}.`));
262
263
  process.exit(1);
263
264
  }
264
265
  }
@@ -277,7 +278,7 @@ class Project {
277
278
  allFilesNum += project.fileNames.length;
278
279
  }
279
280
  if (allFilesNum === 0) {
280
- (spinner?.stop ?? clack.log.message)(lightYellow('No input files.'));
281
+ (spinner?.stop ?? clack.log.message)(yellow('No input files.'));
281
282
  process.exit(1);
282
283
  }
283
284
  if (isTTY || threads >= 2) {
@@ -289,32 +290,33 @@ class Project {
289
290
  await startWorker(worker.createLocal());
290
291
  }
291
292
  (spinner?.stop ?? clack.log.message)(cached
292
- ? darkGray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + darkGray(` to ignore cache.)`)
293
- : darkGray(`Processed ${processed} files.`));
293
+ ? gray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + gray(` to ignore cache.)`)
294
+ : gray(`Processed ${processed} files.`));
294
295
  const projectsFlag = process.argv.find(arg => arg.endsWith('-projects'));
295
296
  if (projectsFlag) {
296
- clack.log.warn(darkGray(`Please use `)
297
+ clack.log.warn(gray(`Please use `)
297
298
  + cyan(`${projectsFlag.slice(0, -1)}`)
298
- + darkGray(` instead of `)
299
+ + gray(` instead of `)
299
300
  + cyan(`${projectsFlag}`)
300
- + darkGray(` starting from version 1.5.0.`));
301
+ + gray(` starting from version 1.5.0.`));
301
302
  }
302
303
  const data = [
303
- [passed, 'passed', lightGreen],
304
- [errors, 'errors', lightRed],
305
- [warnings, 'warnings', lightYellow],
306
- [messages, 'messages', lightBlue],
307
- [excluded, 'excluded', darkGray],
304
+ [passed, 'passed', green],
305
+ [errors, 'errors', red],
306
+ [warnings, 'warnings', yellow],
307
+ [messages, 'messages', blue],
308
+ [suggestions, 'suggestions', gray],
309
+ [excluded, 'excluded', gray],
308
310
  ];
309
311
  let summary = data
310
312
  .filter(([count]) => count)
311
313
  .map(([count, label, color]) => color(`${count} ${label}`))
312
- .join(darkGray(' | '));
314
+ .join(gray(' | '));
313
315
  if (hasFix) {
314
- summary += darkGray(` (Use `) + cyan(`--fix`) + darkGray(` to apply automatic fixes.)`);
316
+ summary += gray(` (Use `) + cyan(`--fix`) + gray(` to apply automatic fixes.)`);
315
317
  }
316
318
  else if (errors || warnings || messages) {
317
- summary += darkGray(` (No fixes available.)`);
319
+ summary += gray(` (No fixes available.)`);
318
320
  }
319
321
  clack.outro(summary);
320
322
  process.exit((errors || messages) ? 1 : 0);
@@ -361,17 +363,28 @@ class Project {
361
363
  else {
362
364
  project.cache[fileName] = fileCache = [fileStat.mtimeMs, {}, {}];
363
365
  }
364
- let diagnostics = await linterWorker.lint(fileName, process.argv.includes('--fix'), fileCache);
365
- diagnostics = diagnostics.filter(diagnostic => diagnostic.category !== ts.DiagnosticCategory.Suggestion);
366
+ const diagnostics = await linterWorker.lint(fileName, process.argv.includes('--fix'), fileCache);
367
+ const formatHost = {
368
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
369
+ getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? x => x : x => x.toLowerCase(),
370
+ getNewLine: () => ts.sys.newLine,
371
+ };
366
372
  if (diagnostics.length) {
367
373
  hasFix ||= await linterWorker.hasCodeFixes(fileName);
368
374
  for (const diagnostic of diagnostics) {
369
375
  hasFix ||= !!fileCache[1][diagnostic.code]?.[0];
370
- let output = ts.formatDiagnosticsWithColorAndContext([diagnostic], {
371
- getCurrentDirectory: ts.sys.getCurrentDirectory,
372
- getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? x => x : x => x.toLowerCase(),
373
- getNewLine: () => ts.sys.newLine,
374
- });
376
+ let output;
377
+ if (diagnostic.category === ts.DiagnosticCategory.Suggestion) {
378
+ output = ts.formatDiagnosticsWithColorAndContext([{
379
+ ...diagnostic,
380
+ category: ts.DiagnosticCategory.Message,
381
+ }], formatHost);
382
+ output = output.replace(/\[94mmessage/, '[90msuggestion');
383
+ output = output.replace(/\[94m/g, '[90m');
384
+ }
385
+ else {
386
+ output = ts.formatDiagnosticsWithColorAndContext([diagnostic], formatHost);
387
+ }
375
388
  output = output.trimEnd();
376
389
  if (typeof diagnostic.code === 'string') {
377
390
  output = output.replace(`TS${diagnostic.code}`, diagnostic.code);
@@ -389,6 +402,7 @@ class Project {
389
402
  log(output);
390
403
  }
391
404
  else {
405
+ suggestions++;
392
406
  log(output);
393
407
  }
394
408
  }
@@ -409,7 +423,7 @@ class Project {
409
423
  }
410
424
  async function getBuiltConfig(configFile) {
411
425
  if (!builtConfigs.has(configFile)) {
412
- builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(darkGray(s), code)));
426
+ builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(gray(s), code)));
413
427
  }
414
428
  return await builtConfigs.get(configFile);
415
429
  }
@@ -425,14 +439,14 @@ class Project {
425
439
  let msg;
426
440
  if (processFiles.size === 0) {
427
441
  if (nextFileName) {
428
- msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), nextFileName)}`);
442
+ msg = gray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), nextFileName)}`);
429
443
  }
430
444
  }
431
445
  else if (processFiles.size === 1) {
432
- msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), [...processFiles][0])}`);
446
+ msg = gray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), [...processFiles][0])}`);
433
447
  }
434
448
  else {
435
- msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] Processing ${processFiles.size} files`);
449
+ msg = gray(`[${processed + processFiles.size}/${allFilesNum}] Processing ${processFiles.size} files`);
436
450
  }
437
451
  if (!spinner && isTTY) {
438
452
  spinner = clack.spinner();
@@ -474,7 +488,7 @@ class Project {
474
488
  return require.resolve(p, { paths: [process.cwd()] });
475
489
  }
476
490
  catch {
477
- clack.log.error(lightRed(`No such file: ${p}`));
491
+ clack.log.error(red(`No such file: ${p}`));
478
492
  process.exit(1);
479
493
  }
480
494
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/cli",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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": "2.0.2",
20
- "@tsslint/core": "2.0.2",
19
+ "@tsslint/config": "2.0.4",
20
+ "@tsslint/core": "2.0.4",
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": "3454b67099474212d2e6902c1b2c9292da080985"
34
+ "gitHead": "6006d07f0f218840a49ae281f074970eed1eddbd"
35
35
  }