Skip to content

Commit ae8ac63

Browse files
ci(lint): auto-fix
1 parent f6026c3 commit ae8ac63

8 files changed

Lines changed: 111 additions & 45 deletions

File tree

packages/cli/lib/cache-flow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// CLI's responsibility — serialization, mtime invalidation, sticky
99
// type-aware cleanup.
1010

11+
import { type Linter, NO_CACHE } from '@tsslint/core';
1112
import type * as ts from 'typescript';
12-
import { NO_CACHE, type Linter } from '@tsslint/core';
1313
import type { FileCache, SerializedDiagnostic } from './cache.js';
1414

1515
export function lintWithCache(

packages/cli/test/cache-flow.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// Run via:
55
// node packages/cli/test/cache-flow.test.js
66

7-
import * as ts from 'typescript';
87
import type { Config, RuleContext } from '@tsslint/types';
8+
import * as ts from 'typescript';
99
import type { FileCache } from '../lib/cache.js';
1010

1111
const core = require('@tsslint/core') as typeof import('@tsslint/core');
@@ -327,7 +327,10 @@ function emptyFileCache(mtime = 0): FileCache {
327327
const program = ctx.languageService.getProgram()!;
328328

329329
cacheFlow.lintWithCache(linter, '/a.ts', cache, 1, program, { incremental: true, typeAwareUnaffected: true });
330-
const second = cacheFlow.lintWithCache(linter, '/a.ts', cache, 1, program, { incremental: true, typeAwareUnaffected: true });
330+
const second = cacheFlow.lintWithCache(linter, '/a.ts', cache, 1, program, {
331+
incremental: true,
332+
typeAwareUnaffected: true,
333+
});
331334
check('second call did NOT re-run type-aware rule', runs === 1);
332335
check('second call still produced 1 diagnostic', second.length === 1);
333336
check(
@@ -536,11 +539,11 @@ function emptyFileCache(mtime = 0): FileCache {
536539
linter1.getTypeAwareRules().has('mixed-mode'),
537540
);
538541
check(
539-
'session 1: early-return file got an entry (rule wasn\'t yet type-aware at write time)',
542+
"session 1: early-return file got an entry (rule wasn't yet type-aware at write time)",
540543
!!cacheSkip.rules['mixed-mode'],
541544
);
542545
check(
543-
'session 1: early-return file\'s entry has 0 diagnostics (rule reported nothing)',
546+
"session 1: early-return file's entry has 0 diagnostics (rule reported nothing)",
544547
cacheSkip.rules['mixed-mode']?.diagnostics.length === 0,
545548
);
546549

@@ -576,7 +579,7 @@ function emptyFileCache(mtime = 0): FileCache {
576579
check(
577580
'session 2: rule body did NOT execute on early-return file (cache skipped it)',
578581
!earlyReturnRanInSession2,
579-
'cache-hit means we skip the rule entirely — body shouldn\'t run',
582+
"cache-hit means we skip the rule entirely — body shouldn't run",
580583
);
581584
void linter2; // type-only ref; linterMonitored is the one we observe
582585
}

packages/cli/test/cache.test.ts

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ function configWithMarker(marker: string): string {
9191
while (stack.length) {
9292
const dir = stack.pop()!;
9393
let entries: fs.Dirent[];
94-
try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
95-
catch { continue; }
94+
try {
95+
entries = fs.readdirSync(dir, { withFileTypes: true });
96+
}
97+
catch {
98+
continue;
99+
}
96100
for (const e of entries) {
97101
const full = path.join(dir, e.name);
98102
if (e.isDirectory()) stack.push(full);
@@ -101,9 +105,11 @@ function configWithMarker(marker: string): string {
101105
const content = fs.readFileSync(full, 'utf8');
102106
const parsed = JSON.parse(content);
103107
// Find the one we just wrote (heuristic: empty data).
104-
if (parsed.version === 'v2'
108+
if (
109+
parsed.version === 'v2'
105110
&& Object.keys(parsed.ruleModes).length === 0
106-
&& Object.keys(parsed.files).length === 0) {
111+
&& Object.keys(parsed.files).length === 0
112+
) {
107113
return full;
108114
}
109115
}
@@ -150,8 +156,12 @@ function configWithMarker(marker: string): string {
150156
while (stack.length) {
151157
const dir = stack.pop()!;
152158
let entries: fs.Dirent[];
153-
try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
154-
catch { continue; }
159+
try {
160+
entries = fs.readdirSync(dir, { withFileTypes: true });
161+
}
162+
catch {
163+
continue;
164+
}
155165
for (const e of entries) {
156166
const full = path.join(dir, e.name);
157167
if (e.isDirectory()) stack.push(full);
@@ -163,8 +173,10 @@ function configWithMarker(marker: string): string {
163173
for (const f of all) {
164174
try {
165175
const o = JSON.parse(fs.readFileSync(f, 'utf8'));
166-
if (o.version === 'v2' && Object.keys(o.files).length === 0
167-
&& Object.keys(o.ruleModes).length === 0) {
176+
if (
177+
o.version === 'v2' && Object.keys(o.files).length === 0
178+
&& Object.keys(o.ruleModes).length === 0
179+
) {
168180
// Could be from a previous test; pick first.
169181
target = f;
170182
break;
@@ -248,8 +260,12 @@ function configWithMarker(marker: string): string {
248260
while (stack.length) {
249261
const dir = stack.pop()!;
250262
let entries: fs.Dirent[];
251-
try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
252-
catch { continue; }
263+
try {
264+
entries = fs.readdirSync(dir, { withFileTypes: true });
265+
}
266+
catch {
267+
continue;
268+
}
253269
for (const e of entries) {
254270
const full = path.join(dir, e.name);
255271
if (e.isDirectory()) stack.push(full);
@@ -274,8 +290,12 @@ function configWithMarker(marker: string): string {
274290
while (stack.length) {
275291
const dir = stack.pop()!;
276292
let entries: fs.Dirent[];
277-
try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
278-
catch { continue; }
293+
try {
294+
entries = fs.readdirSync(dir, { withFileTypes: true });
295+
}
296+
catch {
297+
continue;
298+
}
279299
for (const e of entries) {
280300
const full = path.join(dir, e.name);
281301
if (e.isDirectory()) stack.push(full);
@@ -331,8 +351,12 @@ function configWithMarker(marker: string): string {
331351
while (stack.length) {
332352
const dir = stack.pop()!;
333353
let entries: fs.Dirent[];
334-
try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
335-
catch { continue; }
354+
try {
355+
entries = fs.readdirSync(dir, { withFileTypes: true });
356+
}
357+
catch {
358+
continue;
359+
}
336360
for (const e of entries) {
337361
const full = path.join(dir, e.name);
338362
if (e.isDirectory()) stack.push(full);
@@ -356,7 +380,9 @@ function configWithMarker(marker: string): string {
356380
check('incrementalState wrong type → empty cache', loaded.incrementalState === undefined);
357381

358382
const corrupt2 = {
359-
version: 'v2', ruleModes: {}, files: {},
383+
version: 'v2',
384+
ruleModes: {},
385+
files: {},
360386
incrementalState: { version: 'v3' /* tsBuildInfoText missing */ },
361387
};
362388
fs.writeFileSync(target, JSON.stringify(corrupt2));

packages/cli/test/incremental-state.test.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ const hostShim = {
8989
function captureStderr<T>(fn: () => T): { result: T; stderr: string } {
9090
const orig = process.stderr.write.bind(process.stderr);
9191
let buf = '';
92-
(process.stderr.write as any) = (chunk: any) => { buf += String(chunk); return true; };
92+
(process.stderr.write as any) = (chunk: any) => {
93+
buf += String(chunk);
94+
return true;
95+
};
9396
try {
9497
const result = fn();
9598
return { result, stderr: buf };
@@ -210,8 +213,12 @@ function captureStderr<T>(fn: () => T): { result: T; stderr: string } {
210213
});
211214
const valid = { version: inc.INCREMENTAL_STATE_VERSION, tsBuildInfoText: 'irrelevant' };
212215
const { result, stderr } = captureStderr(() => {
213-
try { return inc.reconstructOldBuilder(tsStub, valid, hostShim); }
214-
catch { return 'THREW' as const; }
216+
try {
217+
return inc.reconstructOldBuilder(tsStub, valid, hostShim);
218+
}
219+
catch {
220+
return 'THREW' as const;
221+
}
215222
});
216223
check('missing load APIs → no throw', result !== 'THREW');
217224
check('missing load APIs → undefined result', result === undefined);
@@ -227,8 +234,12 @@ function captureStderr<T>(fn: () => T): { result: T; stderr: string } {
227234
{
228235
const fakeBuilder = {} as ts.BuilderProgram;
229236
const { result, stderr } = captureStderr(() => {
230-
try { return inc.captureIncrementalState(ts.version, fakeBuilder); }
231-
catch { return 'THREW' as const; }
237+
try {
238+
return inc.captureIncrementalState(ts.version, fakeBuilder);
239+
}
240+
catch {
241+
return 'THREW' as const;
242+
}
232243
});
233244
check('missing emitBuildInfo → no throw', result !== 'THREW');
234245
check('missing emitBuildInfo → undefined state', result === undefined);
@@ -239,11 +250,17 @@ function captureStderr<T>(fn: () => T): { result: T; stderr: string } {
239250
// ── Test 9: emitBuildInfo throws → undefined + warn, no throw out ──────
240251
{
241252
const throwingBuilder = {
242-
emitBuildInfo() { throw new Error('simulated TS internal failure'); },
253+
emitBuildInfo() {
254+
throw new Error('simulated TS internal failure');
255+
},
243256
} as unknown as ts.BuilderProgram;
244257
const { result, stderr } = captureStderr(() => {
245-
try { return inc.captureIncrementalState(ts.version, throwingBuilder); }
246-
catch { return 'THREW' as const; }
258+
try {
259+
return inc.captureIncrementalState(ts.version, throwingBuilder);
260+
}
261+
catch {
262+
return 'THREW' as const;
263+
}
247264
});
248265
check('throwing emitBuildInfo → no throw', result !== 'THREW');
249266
check('throwing emitBuildInfo → undefined state', result === undefined);
@@ -261,15 +278,21 @@ function captureStderr<T>(fn: () => T): { result: T; stderr: string } {
261278
const throwingTs = new Proxy(ts, {
262279
get(target, prop) {
263280
if (prop === 'getBuildInfo') {
264-
return () => { throw new Error('synthetic parse failure'); };
281+
return () => {
282+
throw new Error('synthetic parse failure');
283+
};
265284
}
266285
return (target as any)[prop];
267286
},
268287
});
269288
const valid = { version: inc.INCREMENTAL_STATE_VERSION, tsBuildInfoText: 'whatever' };
270289
const { result, stderr } = captureStderr(() => {
271-
try { return inc.reconstructOldBuilder(throwingTs, valid, hostShim); }
272-
catch { return 'THREW' as const; }
290+
try {
291+
return inc.reconstructOldBuilder(throwingTs, valid, hostShim);
292+
}
293+
catch {
294+
return 'THREW' as const;
295+
}
273296
});
274297
check('throwing getBuildInfo → no throw', result !== 'THREW');
275298
check('throwing getBuildInfo → undefined result', result === undefined);
@@ -307,8 +330,12 @@ function captureStderr<T>(fn: () => T): { result: T; stderr: string } {
307330
},
308331
} as unknown as ts.BuilderProgram;
309332
const { result, stderr } = captureStderr(() => {
310-
try { return inc.captureIncrementalState(ts.version, oversizedBuilder); }
311-
catch { return 'THREW' as const; }
333+
try {
334+
return inc.captureIncrementalState(ts.version, oversizedBuilder);
335+
}
336+
catch {
337+
return 'THREW' as const;
338+
}
312339
});
313340
check('oversized buildinfo → no throw', result !== 'THREW');
314341
check('oversized buildinfo → undefined state', result === undefined);

packages/cli/test/integration.test.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ function findCacheFiles(): string[] {
7373
while (stack.length) {
7474
const cur = stack.pop()!;
7575
let entries: fs.Dirent[];
76-
try { entries = fs.readdirSync(cur, { withFileTypes: true }); }
77-
catch { continue; }
76+
try {
77+
entries = fs.readdirSync(cur, { withFileTypes: true });
78+
}
79+
catch {
80+
continue;
81+
}
7882
for (const e of entries) {
7983
const full = path.join(cur, e.name);
8084
if (e.isDirectory()) stack.push(full);
@@ -228,7 +232,8 @@ function makeTypeAwareFixture(): { dir: string; markerPath: string; ambient: str
228232
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'tsslint-int-l2-')));
229233
const markerPath = path.join(dir, 'marker.log');
230234
const rulePath = path.join(dir, 'type-aware-rule.ts');
231-
fs.writeFileSync(rulePath,
235+
fs.writeFileSync(
236+
rulePath,
232237
`import { defineRule } from '${repoRoot}/packages/config/index.js';\n`
233238
+ `import * as fs from 'fs';\n`
234239
+ `export default defineRule(({ file, program, report }) => {\n`
@@ -237,16 +242,21 @@ function makeTypeAwareFixture(): { dir: string; markerPath: string; ambient: str
237242
+ ` report('type-aware ran', 0, 1);\n`
238243
+ `});\n`,
239244
);
240-
fs.writeFileSync(path.join(dir, 'tsconfig.json'),
245+
fs.writeFileSync(
246+
path.join(dir, 'tsconfig.json'),
241247
JSON.stringify({
242248
compilerOptions: {
243-
target: 'es2020', module: 'esnext', moduleResolution: 'bundler',
244-
strict: true, skipLibCheck: true,
249+
target: 'es2020',
250+
module: 'esnext',
251+
moduleResolution: 'bundler',
252+
strict: true,
253+
skipLibCheck: true,
245254
},
246255
include: ['*.ts', '*.d.ts'],
247256
}),
248257
);
249-
fs.writeFileSync(path.join(dir, 'tsslint.config.ts'),
258+
fs.writeFileSync(
259+
path.join(dir, 'tsslint.config.ts'),
250260
`import { defineConfig } from '${repoRoot}/packages/config/index.js';\n`
251261
+ `export default defineConfig({\n`
252262
+ ` include: ['fixture.ts'],\n`

packages/cli/test/render.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function withCapture(isTTY: boolean, fn: (renderer: import('../lib/render').Rend
146146
r.info('after empty');
147147
});
148148
check(
149-
'empty summary doesn\'t set content flag',
149+
"empty summary doesn't set content flag",
150150
out === 'after empty\n',
151151
`got: ${JSON.stringify(out)}`,
152152
);
@@ -166,7 +166,7 @@ function withCapture(isTTY: boolean, fn: (renderer: import('../lib/render').Rend
166166
`got: ${JSON.stringify(ttyOut)}`,
167167
);
168168
check(
169-
'diagnostic doesn\'t indent in non-TTY',
169+
"diagnostic doesn't indent in non-TTY",
170170
nonTtyOut === '\nline1\nline2\n',
171171
`got: ${JSON.stringify(nonTtyOut)}`,
172172
);

packages/core/test/probe.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Run via:
1010
// node packages/core/test/probe.test.js
1111

12-
import * as ts from 'typescript';
1312
import type { Config, RuleContext } from '@tsslint/types';
13+
import * as ts from 'typescript';
1414

1515
const core = require('../index.js') as typeof import('../index.js');
1616

packages/core/test/skip-rules.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Run via:
66
// node packages/core/test/skip-rules.test.js
77

8-
import * as ts from 'typescript';
98
import type { Config, RuleContext } from '@tsslint/types';
9+
import * as ts from 'typescript';
1010

1111
const core = require('../index.js') as typeof import('../index.js');
1212

0 commit comments

Comments
 (0)