@tsslint/cli 0.0.7 → 0.0.8

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 +33 -41
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -6,7 +6,7 @@ const config = require("@tsslint/config");
6
6
  const core = require("@tsslint/core");
7
7
  const glob = require("glob");
8
8
  (async () => {
9
- let errors = 0;
9
+ let hasError = false;
10
10
  let projectVersion = 0;
11
11
  let typeRootsVersion = 0;
12
12
  let parsed;
@@ -48,7 +48,7 @@ const glob = require("glob");
48
48
  if (process.argv.includes('--project')) {
49
49
  const projectIndex = process.argv.indexOf('--project');
50
50
  const tsconfig = process.argv[projectIndex + 1];
51
- errors += await projectWorker(tsconfig);
51
+ await projectWorker(tsconfig);
52
52
  }
53
53
  else if (process.argv.includes('--projects')) {
54
54
  const projectsIndex = process.argv.indexOf('--projects');
@@ -62,22 +62,23 @@ const glob = require("glob");
62
62
  if (!tsconfig.startsWith('.')) {
63
63
  tsconfig = `./${tsconfig}`;
64
64
  }
65
- errors += await projectWorker(tsconfig);
65
+ await projectWorker(tsconfig);
66
66
  }
67
67
  }
68
68
  }
69
69
  else {
70
- errors += await projectWorker();
70
+ await projectWorker();
71
71
  }
72
- process.exit(errors ? 1 : 0);
72
+ process.exit(hasError ? 1 : 0);
73
73
  async function projectWorker(tsconfigOption) {
74
74
  const tsconfig = await getTsconfigPath(tsconfigOption);
75
- log.info(`tsconfig path: ${tsconfig} (${parseCommonLine(tsconfig).fileNames.length} input files)`);
75
+ log.step(`Project: ${path.relative(process.cwd(), tsconfig)} (${parseCommonLine(tsconfig).fileNames.length} input files)`);
76
76
  const configFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'tsslint.config.ts');
77
77
  if (!configFile) {
78
- throw new Error('No tsslint.config.ts file found!');
78
+ log.error('No tsslint.config.ts file found!');
79
+ return;
79
80
  }
80
- log.info(`config path: ${configFile}`);
81
+ log.message(`Config: ${path.relative(process.cwd(), configFile)}`);
81
82
  if (!configs.has(configFile)) {
82
83
  configs.set(configFile, await config.buildConfigFile(configFile));
83
84
  }
@@ -95,8 +96,7 @@ const glob = require("glob");
95
96
  typescript: ts,
96
97
  tsconfig,
97
98
  }, tsslintConfig, false);
98
- let errors = 0;
99
- let warnings = 0;
99
+ let hasFix = false;
100
100
  for (const fileName of parsed.fileNames) {
101
101
  if (process.argv.includes('--fix')) {
102
102
  let retry = 3;
@@ -107,27 +107,10 @@ const glob = require("glob");
107
107
  retry--;
108
108
  const diagnostics = linter.lint(fileName);
109
109
  const fixes = linter.getCodeFixes(fileName, 0, Number.MAX_VALUE, diagnostics);
110
- const changes = fixes
111
- .map(fix => fix.changes)
112
- .flat()
113
- .filter(change => change.fileName === fileName && change.textChanges.length)
114
- .sort((a, b) => b.textChanges[0].span.start - a.textChanges[0].span.start);
115
- let lastChangeAt = Number.MAX_VALUE;
116
- if (changes.length) {
110
+ const textChanges = core.combineCodeFixes(fileName, fixes);
111
+ if (textChanges.length) {
117
112
  const oldSnapshot = snapshots.get(fileName);
118
- let text = oldSnapshot.getText(0, oldSnapshot.getLength());
119
- for (const change of changes) {
120
- const textChanges = [...change.textChanges].sort((a, b) => b.span.start - a.span.start);
121
- const lastChange = textChanges[0];
122
- const firstChange = textChanges[textChanges.length - 1];
123
- if (lastChangeAt >= lastChange.span.start + lastChange.span.length) {
124
- lastChangeAt = firstChange.span.start;
125
- for (const change of textChanges) {
126
- text = text.slice(0, change.span.start) + change.newText + text.slice(change.span.start + change.span.length);
127
- }
128
- }
129
- }
130
- newSnapshot = ts.ScriptSnapshot.fromString(text);
113
+ newSnapshot = core.applyTextChanges(oldSnapshot, textChanges);
131
114
  snapshots.set(fileName, newSnapshot);
132
115
  versions.set(fileName, (versions.get(fileName) ?? 0) + 1);
133
116
  projectVersion++;
@@ -144,22 +127,31 @@ const glob = require("glob");
144
127
  throw new Error(`No source file found for ${fileName}`);
145
128
  }
146
129
  const diagnostics = linter.lint(fileName);
147
- const output = ts.formatDiagnosticsWithColorAndContext(diagnostics, {
148
- getCurrentDirectory: ts.sys.getCurrentDirectory,
149
- getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? x => x : x => x.toLowerCase(),
150
- getNewLine: () => ts.sys.newLine,
151
- });
152
- if (output) {
153
- log.info(output);
130
+ for (const diagnostic of diagnostics) {
131
+ const output = ts.formatDiagnosticsWithColorAndContext([diagnostic], {
132
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
133
+ getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? x => x : x => x.toLowerCase(),
134
+ getNewLine: () => ts.sys.newLine,
135
+ });
136
+ if (diagnostic.category === ts.DiagnosticCategory.Error) {
137
+ log.error(output);
138
+ }
139
+ else if (diagnostic.category === ts.DiagnosticCategory.Warning) {
140
+ log.warn(output);
141
+ }
142
+ else {
143
+ log.info(output);
144
+ }
145
+ }
146
+ if (diagnostics.length) {
147
+ hasFix ||= linter.getCodeFixes(fileName, 0, Number.MAX_VALUE, diagnostics).length >= 1;
148
+ hasError ||= diagnostics.some(diagnostic => diagnostic.category === ts.DiagnosticCategory.Error);
154
149
  }
155
- errors += diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).length;
156
- warnings += diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Warning).length;
157
150
  }
158
151
  }
159
- if (errors || warnings) {
152
+ if (hasFix) {
160
153
  log.info(`Use --fix to apply fixes.`);
161
154
  }
162
- return errors;
163
155
  }
164
156
  async function getTsconfigPath(tsconfig) {
165
157
  if (!tsconfig) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/cli",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsslint": "./bin/tsslint.js"
@@ -16,12 +16,12 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@clack/prompts": "^0.7.0",
19
- "@tsslint/config": "0.0.7",
20
- "@tsslint/core": "0.0.7",
19
+ "@tsslint/config": "0.0.8",
20
+ "@tsslint/core": "0.0.8",
21
21
  "glob": "^10.3.10"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "typescript": "*"
25
25
  },
26
- "gitHead": "ed1086b1f11469e0a9d6a14199c7e027eb28b488"
26
+ "gitHead": "6fc30164bf7d50722f3fdb565f178b13821be692"
27
27
  }