@tsslint/cli 0.0.5 → 0.0.6
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.d.ts +0 -1
- package/index.js +33 -49
- package/package.json +4 -4
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -13,17 +13,18 @@ const glob = require("glob");
|
|
|
13
13
|
const { log, text } = await import('@clack/prompts');
|
|
14
14
|
const snapshots = new Map();
|
|
15
15
|
const versions = new Map();
|
|
16
|
+
const configs = new Map();
|
|
16
17
|
const languageServiceHost = {
|
|
17
18
|
...ts.sys,
|
|
19
|
+
useCaseSensitiveFileNames() {
|
|
20
|
+
return ts.sys.useCaseSensitiveFileNames;
|
|
21
|
+
},
|
|
18
22
|
getProjectVersion() {
|
|
19
23
|
return projectVersion.toString();
|
|
20
24
|
},
|
|
21
25
|
getTypeRootsVersion() {
|
|
22
26
|
return typeRootsVersion;
|
|
23
27
|
},
|
|
24
|
-
useCaseSensitiveFileNames() {
|
|
25
|
-
return ts.sys.useCaseSensitiveFileNames;
|
|
26
|
-
},
|
|
27
28
|
getCompilationSettings() {
|
|
28
29
|
return parsed.options;
|
|
29
30
|
},
|
|
@@ -51,13 +52,18 @@ const glob = require("glob");
|
|
|
51
52
|
}
|
|
52
53
|
else if (process.argv.includes('--projects')) {
|
|
53
54
|
const projectsIndex = process.argv.indexOf('--projects');
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
for (let i = projectsIndex + 1; i < process.argv.length; i++) {
|
|
56
|
+
if (process.argv[i].startsWith('-')) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
const searchGlob = process.argv[i];
|
|
60
|
+
const tsconfigs = glob.sync(searchGlob);
|
|
61
|
+
for (let tsconfig of tsconfigs) {
|
|
62
|
+
if (!tsconfig.startsWith('.')) {
|
|
63
|
+
tsconfig = `./${tsconfig}`;
|
|
64
|
+
}
|
|
65
|
+
errors += await projectWorker(tsconfig);
|
|
59
66
|
}
|
|
60
|
-
errors += await projectWorker(tsconfig);
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
else {
|
|
@@ -72,29 +78,25 @@ const glob = require("glob");
|
|
|
72
78
|
throw new Error('No tsslint.config.ts file found!');
|
|
73
79
|
}
|
|
74
80
|
log.info(`config path: ${configFile}`);
|
|
75
|
-
|
|
81
|
+
if (!configs.has(configFile)) {
|
|
82
|
+
configs.set(configFile, await config.buildConfigFile(configFile));
|
|
83
|
+
}
|
|
84
|
+
const tsslintConfig = configs.get(configFile);
|
|
76
85
|
parsed = parseCommonLine(tsconfig);
|
|
77
86
|
if (!parsed.fileNames) {
|
|
78
87
|
throw new Error('No input files found in tsconfig!');
|
|
79
88
|
}
|
|
80
89
|
projectVersion++;
|
|
81
90
|
typeRootsVersion++;
|
|
82
|
-
const
|
|
83
|
-
...core.getBuiltInPlugins(false),
|
|
84
|
-
...tsslintConfig.plugins ?? [],
|
|
85
|
-
].map(plugin => plugin({
|
|
91
|
+
const linter = core.createLinter({
|
|
86
92
|
configFile,
|
|
87
93
|
languageService,
|
|
88
94
|
languageServiceHost,
|
|
89
95
|
typescript: ts,
|
|
90
96
|
tsconfig,
|
|
91
|
-
})
|
|
92
|
-
for (const plugin of plugins) {
|
|
93
|
-
if (plugin.resolveRules) {
|
|
94
|
-
tsslintConfig.rules = plugin.resolveRules(tsslintConfig.rules ?? {});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
+
}, tsslintConfig, false);
|
|
97
98
|
let errors = 0;
|
|
99
|
+
let warnings = 0;
|
|
98
100
|
for (const fileName of parsed.fileNames) {
|
|
99
101
|
if (process.argv.includes('--fix')) {
|
|
100
102
|
let retry = 3;
|
|
@@ -103,31 +105,17 @@ const glob = require("glob");
|
|
|
103
105
|
while (shouldRetry && retry) {
|
|
104
106
|
shouldRetry = false;
|
|
105
107
|
retry--;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
throw new Error(`No source file found for ${fileName}`);
|
|
109
|
-
}
|
|
110
|
-
let diagnostics = plugins
|
|
111
|
-
.map(plugin => plugin.lint?.(sourceFile, tsslintConfig.rules ?? {}))
|
|
112
|
-
.flat()
|
|
113
|
-
.filter((diag) => !!diag);
|
|
114
|
-
for (const plugin of plugins) {
|
|
115
|
-
if (plugin.resolveDiagnostics) {
|
|
116
|
-
diagnostics = plugin.resolveDiagnostics(diagnostics);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const fixes = plugins
|
|
120
|
-
.map(plugin => plugin.getFixes?.(fileName, 0, sourceFile.text.length, diagnostics))
|
|
121
|
-
.flat()
|
|
122
|
-
.filter((fix) => !!fix);
|
|
108
|
+
const diagnostics = linter.lint(fileName);
|
|
109
|
+
const fixes = linter.getCodeFixes(fileName, 0, Number.MAX_VALUE, diagnostics);
|
|
123
110
|
const changes = fixes
|
|
124
111
|
.map(fix => fix.changes)
|
|
125
112
|
.flat()
|
|
126
|
-
.filter(change => change.fileName ===
|
|
113
|
+
.filter(change => change.fileName === fileName && change.textChanges.length)
|
|
127
114
|
.sort((a, b) => b.textChanges[0].span.start - a.textChanges[0].span.start);
|
|
128
|
-
let lastChangeAt =
|
|
115
|
+
let lastChangeAt = Number.MAX_VALUE;
|
|
129
116
|
if (changes.length) {
|
|
130
|
-
|
|
117
|
+
const oldSnapshot = snapshots.get(fileName);
|
|
118
|
+
let text = oldSnapshot.getText(0, oldSnapshot.getLength());
|
|
131
119
|
for (const change of changes) {
|
|
132
120
|
const textChanges = [...change.textChanges].sort((a, b) => b.span.start - a.span.start);
|
|
133
121
|
const lastChange = textChanges[0];
|
|
@@ -140,8 +128,8 @@ const glob = require("glob");
|
|
|
140
128
|
}
|
|
141
129
|
}
|
|
142
130
|
newSnapshot = ts.ScriptSnapshot.fromString(text);
|
|
143
|
-
snapshots.set(
|
|
144
|
-
versions.set(
|
|
131
|
+
snapshots.set(fileName, newSnapshot);
|
|
132
|
+
versions.set(fileName, (versions.get(fileName) ?? 0) + 1);
|
|
145
133
|
projectVersion++;
|
|
146
134
|
shouldRetry = true;
|
|
147
135
|
}
|
|
@@ -155,12 +143,7 @@ const glob = require("glob");
|
|
|
155
143
|
if (!sourceFile) {
|
|
156
144
|
throw new Error(`No source file found for ${fileName}`);
|
|
157
145
|
}
|
|
158
|
-
|
|
159
|
-
for (const plugin of plugins) {
|
|
160
|
-
if (plugin.resolveDiagnostics) {
|
|
161
|
-
diagnostics = plugin.resolveDiagnostics(diagnostics);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
146
|
+
const diagnostics = linter.lint(fileName);
|
|
164
147
|
const output = ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
165
148
|
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
166
149
|
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? x => x : x => x.toLowerCase(),
|
|
@@ -170,9 +153,10 @@ const glob = require("glob");
|
|
|
170
153
|
log.info(output);
|
|
171
154
|
}
|
|
172
155
|
errors += diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).length;
|
|
156
|
+
warnings += diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Warning).length;
|
|
173
157
|
}
|
|
174
158
|
}
|
|
175
|
-
if (errors) {
|
|
159
|
+
if (errors || warnings) {
|
|
176
160
|
log.info(`Use --fix to apply fixes.`);
|
|
177
161
|
}
|
|
178
162
|
return errors;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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.6",
|
|
20
|
+
"@tsslint/core": "0.0.6",
|
|
21
21
|
"glob": "^10.3.10"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"typescript": "*"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "a9a381f7c5e84819c99b70f6b429150ce766739c"
|
|
27
27
|
}
|