@tsslint/cli 0.0.7 → 0.0.9
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/bin/tsslint.js +0 -0
- package/index.js +36 -44
- package/package.json +4 -4
package/bin/tsslint.js
CHANGED
|
File without changes
|
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
|
|
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
|
-
|
|
51
|
+
await projectWorker(tsconfig);
|
|
52
52
|
}
|
|
53
53
|
else if (process.argv.includes('--projects')) {
|
|
54
54
|
const projectsIndex = process.argv.indexOf('--projects');
|
|
@@ -62,24 +62,25 @@ const glob = require("glob");
|
|
|
62
62
|
if (!tsconfig.startsWith('.')) {
|
|
63
63
|
tsconfig = `./${tsconfig}`;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
await projectWorker(tsconfig);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
-
|
|
70
|
+
await projectWorker();
|
|
71
71
|
}
|
|
72
|
-
process.exit(
|
|
72
|
+
process.exit(hasError ? 1 : 0);
|
|
73
73
|
async function projectWorker(tsconfigOption) {
|
|
74
74
|
const tsconfig = await getTsconfigPath(tsconfigOption);
|
|
75
|
-
log.
|
|
76
|
-
const configFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, '
|
|
75
|
+
log.step(`Project: ${path.relative(process.cwd(), tsconfig)} (${parseCommonLine(tsconfig).fileNames.length} input files)`);
|
|
76
|
+
const configFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'tsl.config.ts');
|
|
77
77
|
if (!configFile) {
|
|
78
|
-
|
|
78
|
+
log.error('No tsl.config.ts file found!');
|
|
79
|
+
return;
|
|
79
80
|
}
|
|
80
|
-
log.
|
|
81
|
+
log.message(`Config: ${path.relative(process.cwd(), configFile)}`);
|
|
81
82
|
if (!configs.has(configFile)) {
|
|
82
|
-
configs.set(configFile, await config.buildConfigFile(configFile));
|
|
83
|
+
configs.set(configFile, await config.buildConfigFile(configFile, ts.sys.createHash));
|
|
83
84
|
}
|
|
84
85
|
const tsslintConfig = configs.get(configFile);
|
|
85
86
|
parsed = parseCommonLine(tsconfig);
|
|
@@ -95,8 +96,7 @@ const glob = require("glob");
|
|
|
95
96
|
typescript: ts,
|
|
96
97
|
tsconfig,
|
|
97
98
|
}, tsslintConfig, false);
|
|
98
|
-
let
|
|
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
|
|
111
|
-
|
|
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
|
-
|
|
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
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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 (
|
|
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) {
|
|
@@ -169,7 +161,7 @@ const glob = require("glob");
|
|
|
169
161
|
shortTsconfig = `./${shortTsconfig}`;
|
|
170
162
|
}
|
|
171
163
|
tsconfig = await text({
|
|
172
|
-
message: 'Select the tsconfig project. (You can use --project to skip this prompt.)',
|
|
164
|
+
message: 'Select the tsconfig project. (You can use --project or --projects to skip this prompt.)',
|
|
173
165
|
placeholder: shortTsconfig ? `${shortTsconfig} (${parseCommonLine(tsconfig).fileNames.length} input files)` : 'No tsconfig.json found, please enter the path to your tsconfig.json file.',
|
|
174
166
|
defaultValue: shortTsconfig,
|
|
175
167
|
validate(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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.
|
|
20
|
-
"@tsslint/core": "0.0.
|
|
19
|
+
"@tsslint/config": "0.0.9",
|
|
20
|
+
"@tsslint/core": "0.0.9",
|
|
21
21
|
"glob": "^10.3.10"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"typescript": "*"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "ee84b80bac5dab5fad732e4265e2164c6a0724a6"
|
|
27
27
|
}
|