1- import { execFileSync } from " node:child_process" ;
2- import { dirname , join , resolve } from " node:path" ;
3- import { fileURLToPath } from " node:url" ;
1+ import { execFileSync } from ' node:child_process' ;
2+ import { dirname , join , resolve } from ' node:path' ;
3+ import { fileURLToPath } from ' node:url' ;
44
5- import { glob } from " fast-glob" ;
6- import { describe , expect , it } from " vitest" ;
5+ import { glob } from ' fast-glob' ;
6+ import { describe , expect , it } from ' vitest' ;
77
88const __filename = fileURLToPath ( import . meta. url ) ;
99const __dirname = dirname ( __filename ) ;
1010
11- const ROOT_DIR = resolve ( __dirname , ".." ) ;
11+ const ROOT_DIR = resolve ( __dirname , '..' ) ;
1212const E2E_DIR = __dirname ;
13- const FIXTURES_DIR = join ( E2E_DIR , " fixtures" ) ;
13+ const FIXTURES_DIR = join ( E2E_DIR , ' fixtures' ) ;
1414const TSGOLINT_BIN = join (
1515 ROOT_DIR ,
16- `tsgolint${ process . platform === " win32" ? " .exe" : "" } `
16+ `tsgolint${ process . platform === ' win32' ? ' .exe' : '' } ` ,
1717) ;
1818
1919const ALL_RULES = [
20- " await-thenable" ,
21- " no-array-delete" ,
22- " no-base-to-string" ,
23- " no-confusing-void-expression" ,
24- " no-duplicate-type-constituents" ,
25- " no-floating-promises" ,
26- " no-for-in-array" ,
27- " no-implied-eval" ,
28- " no-meaningless-void-operator" ,
29- " no-misused-promises" ,
30- " no-misused-spread" ,
31- " no-mixed-enums" ,
32- " no-redundant-type-constituents" ,
33- " no-unnecessary-boolean-literal-compare" ,
34- " no-unnecessary-template-expression" ,
35- " no-unnecessary-type-arguments" ,
36- " no-unnecessary-type-assertion" ,
37- " no-unsafe-argument" ,
38- " no-unsafe-assignment" ,
39- " no-unsafe-call" ,
40- " no-unsafe-enum-comparison" ,
41- " no-unsafe-member-access" ,
42- " no-unsafe-return" ,
43- " no-unsafe-type-assertion" ,
44- " no-unsafe-unary-minus" ,
45- " non-nullable-type-assertion-style" ,
46- " only-throw-error" ,
47- " prefer-promise-reject-errors" ,
48- " prefer-reduce-type-parameter" ,
49- " prefer-return-this-type" ,
50- " promise-function-async" ,
51- " related-getter-setter-pairs" ,
52- " require-array-sort-compare" ,
53- " require-await" ,
54- " restrict-plus-operands" ,
55- " restrict-template-expressions" ,
56- " return-await" ,
57- " switch-exhaustiveness-check" ,
58- " unbound-method" ,
59- " use-unknown-in-catch-callback-variable" ,
20+ ' await-thenable' ,
21+ ' no-array-delete' ,
22+ ' no-base-to-string' ,
23+ ' no-confusing-void-expression' ,
24+ ' no-duplicate-type-constituents' ,
25+ ' no-floating-promises' ,
26+ ' no-for-in-array' ,
27+ ' no-implied-eval' ,
28+ ' no-meaningless-void-operator' ,
29+ ' no-misused-promises' ,
30+ ' no-misused-spread' ,
31+ ' no-mixed-enums' ,
32+ ' no-redundant-type-constituents' ,
33+ ' no-unnecessary-boolean-literal-compare' ,
34+ ' no-unnecessary-template-expression' ,
35+ ' no-unnecessary-type-arguments' ,
36+ ' no-unnecessary-type-assertion' ,
37+ ' no-unsafe-argument' ,
38+ ' no-unsafe-assignment' ,
39+ ' no-unsafe-call' ,
40+ ' no-unsafe-enum-comparison' ,
41+ ' no-unsafe-member-access' ,
42+ ' no-unsafe-return' ,
43+ ' no-unsafe-type-assertion' ,
44+ ' no-unsafe-unary-minus' ,
45+ ' non-nullable-type-assertion-style' ,
46+ ' only-throw-error' ,
47+ ' prefer-promise-reject-errors' ,
48+ ' prefer-reduce-type-parameter' ,
49+ ' prefer-return-this-type' ,
50+ ' promise-function-async' ,
51+ ' related-getter-setter-pairs' ,
52+ ' require-array-sort-compare' ,
53+ ' require-await' ,
54+ ' restrict-plus-operands' ,
55+ ' restrict-template-expressions' ,
56+ ' return-await' ,
57+ ' switch-exhaustiveness-check' ,
58+ ' unbound-method' ,
59+ ' use-unknown-in-catch-callback-variable' ,
6060] as const ;
6161
6262interface Diagnostic {
@@ -94,12 +94,11 @@ function parseHeadlessOutput(data: Buffer): Diagnostic[] {
9494 // Only process diagnostic messages (type 1)
9595 if ( msgType === 1 ) {
9696 try {
97- const diagnostic = JSON . parse ( payload . toString ( " utf-8" ) ) ;
97+ const diagnostic = JSON . parse ( payload . toString ( ' utf-8' ) ) ;
9898 // Make file paths relative to fixtures/ for deterministic snapshots
99- const filePath = diagnostic . file_path || "" ;
100- if ( filePath . includes ( "fixtures/" ) ) {
101- diagnostic . file_path =
102- "fixtures/" + filePath . split ( "fixtures/" ) . pop ( ) ;
99+ const filePath = diagnostic . file_path || '' ;
100+ if ( filePath . includes ( 'fixtures/' ) ) {
101+ diagnostic . file_path = 'fixtures/' + filePath . split ( 'fixtures/' ) . pop ( ) ;
103102 }
104103 diagnostics . push ( diagnostic ) ;
105104 } catch {
@@ -113,12 +112,12 @@ function parseHeadlessOutput(data: Buffer): Diagnostic[] {
113112
114113function sortDiagnostics ( diagnostics : Diagnostic [ ] ) : Diagnostic [ ] {
115114 diagnostics . sort ( ( a , b ) => {
116- const aFilePath = a . file_path || "" ;
117- const bFilePath = b . file_path || "" ;
115+ const aFilePath = a . file_path || '' ;
116+ const bFilePath = b . file_path || '' ;
118117 if ( aFilePath !== bFilePath ) return aFilePath . localeCompare ( bFilePath ) ;
119118
120- const aRule = a . rule || "" ;
121- const bRule = b . rule || "" ;
119+ const aRule = a . rule || '' ;
120+ const bRule = b . rule || '' ;
122121 if ( aRule !== bRule ) return aRule . localeCompare ( bRule ) ;
123122
124123 const aPos = ( a . range && a . range . pos ) || 0 ;
@@ -146,7 +145,7 @@ async function getTestFiles(testPath: string): Promise<string[]> {
146145 const files = await glob ( pattern , {
147146 cwd : FIXTURES_DIR ,
148147 absolute : true ,
149- ignore : [ " **/node_modules/**" , " **/*.json" ] ,
148+ ignore : [ ' **/node_modules/**' , ' **/*.json' ] ,
150149 } ) ;
151150 allFiles . push ( ...files ) ;
152151 }
@@ -156,7 +155,7 @@ async function getTestFiles(testPath: string): Promise<string[]> {
156155
157156function generateConfig (
158157 files : string [ ] ,
159- rules : readonly ( typeof ALL_RULES ) [ number ] [ ] = ALL_RULES
158+ rules : readonly ( typeof ALL_RULES ) [ number ] [ ] = ALL_RULES ,
160159) : string {
161160 // Headless payload format:
162161 // ```json
@@ -181,25 +180,25 @@ function generateConfig(
181180 return JSON . stringify ( config ) ;
182181}
183182
184- describe ( " TSGoLint E2E Snapshot Tests" , ( ) => {
185- it ( " should generate consistent diagnostics snapshot" , async ( ) => {
186- const testFiles = await getTestFiles ( " basic" ) ;
183+ describe ( ' TSGoLint E2E Snapshot Tests' , ( ) => {
184+ it ( ' should generate consistent diagnostics snapshot' , async ( ) => {
185+ const testFiles = await getTestFiles ( ' basic' ) ;
187186 expect ( testFiles . length ) . toBeGreaterThan ( 0 ) ;
188187
189188 const config = generateConfig ( testFiles ) ;
190189
191190 // Run tsgolint in headless mode with single thread for deterministic results
192191 // Set GOMAXPROCS=1 for single-threaded execution
193- const env = { ...process . env , GOMAXPROCS : "1" } ;
192+ const env = { ...process . env , GOMAXPROCS : '1' } ;
194193
195194 let output : Buffer ;
196195 output = execFileSync (
197196 TSGOLINT_BIN ,
198- [ " headless" , " -fix" , " -fix-suggestions" ] ,
197+ [ ' headless' , ' -fix' , ' -fix-suggestions' ] ,
199198 {
200199 input : config ,
201200 env,
202- }
201+ } ,
203202 ) ;
204203
205204 let diagnostics = parseHeadlessOutput ( output ) ;
@@ -210,8 +209,8 @@ describe("TSGoLint E2E Snapshot Tests", () => {
210209 expect ( diagnostics ) . toMatchSnapshot ( ) ;
211210 } ) ;
212211
213- it . runIf ( process . platform === " win32" ) (
214- " should not panic with mixed forward/backslash paths from Rust (issue #143)" ,
212+ it . runIf ( process . platform === ' win32' ) (
213+ ' should not panic with mixed forward/backslash paths from Rust (issue #143)' ,
215214 async ( ) => {
216215 // Regression test for https://github.com/oxc-project/tsgolint/issues/143
217216 // This test reproduces the issue where Rust sends paths with backslashes
@@ -220,35 +219,35 @@ describe("TSGoLint E2E Snapshot Tests", () => {
220219
221220 const testFile = join (
222221 FIXTURES_DIR ,
223- " basic" ,
224- " rules" ,
225- " no-floating-promises" ,
226- " index.ts"
222+ ' basic' ,
223+ ' rules' ,
224+ ' no-floating-promises' ,
225+ ' index.ts' ,
227226 ) ;
228227
229228 // On Windows, convert forward slashes to backslashes to simulate Rust input
230- const rustStylePath = testFile . replace ( / \/ / g, "\\" ) ;
229+ const rustStylePath = testFile . replace ( / \/ / g, '\\' ) ;
231230
232231 expect ( ( ) => {
233- execFileSync ( TSGOLINT_BIN , [ " headless" ] , {
234- input : generateConfig ( [ rustStylePath ] , [ " no-floating-promises" ] ) ,
235- env : { ...process . env , GOMAXPROCS : "1" } ,
232+ execFileSync ( TSGOLINT_BIN , [ ' headless' ] , {
233+ input : generateConfig ( [ rustStylePath ] , [ ' no-floating-promises' ] ) ,
234+ env : { ...process . env , GOMAXPROCS : '1' } ,
236235 } ) ;
237236 } ) . not . toThrow ( ) ;
238- }
237+ } ,
239238 ) ;
240239
241- it ( " should correctly evaluate project references" , async ( ) => {
242- const testFiles = await getTestFiles ( " project-references" ) ;
240+ it ( ' should correctly evaluate project references' , async ( ) => {
241+ const testFiles = await getTestFiles ( ' project-references' ) ;
243242 expect ( testFiles . length ) . toBeGreaterThan ( 0 ) ;
244243
245- const config = generateConfig ( testFiles , [ " no-unsafe-argument" ] ) ;
244+ const config = generateConfig ( testFiles , [ ' no-unsafe-argument' ] ) ;
246245
247246 // Run tsgolint in headless mode with single thread for deterministic results
248247 // Set GOMAXPROCS=1 for single-threaded execution
249- const env = { ...process . env , GOMAXPROCS : "1" } ;
248+ const env = { ...process . env , GOMAXPROCS : '1' } ;
250249
251- const output = execFileSync ( TSGOLINT_BIN , [ " headless" ] , {
250+ const output = execFileSync ( TSGOLINT_BIN , [ ' headless' ] , {
252251 input : config ,
253252 env,
254253 } ) ;
@@ -259,15 +258,15 @@ describe("TSGoLint E2E Snapshot Tests", () => {
259258 expect ( diagnostics ) . toMatchSnapshot ( ) ;
260259 } ) ;
261260
262- it ( " should correctly lint files not inside a project" , async ( ) => {
263- const testFiles = await getTestFiles ( " with-unmatched-files" ) ;
261+ it ( ' should correctly lint files not inside a project' , async ( ) => {
262+ const testFiles = await getTestFiles ( ' with-unmatched-files' ) ;
264263 expect ( testFiles . length ) . toBeGreaterThan ( 0 ) ;
265264
266- const config = generateConfig ( testFiles , [ " no-unsafe-argument" ] ) ;
265+ const config = generateConfig ( testFiles , [ ' no-unsafe-argument' ] ) ;
267266
268- const env = { ...process . env , GOMAXPROCS : "1" } ;
267+ const env = { ...process . env , GOMAXPROCS : '1' } ;
269268
270- const output = execFileSync ( TSGOLINT_BIN , [ " headless" ] , {
269+ const output = execFileSync ( TSGOLINT_BIN , [ ' headless' ] , {
271270 input : config ,
272271 env,
273272 } ) ;
@@ -278,10 +277,10 @@ describe("TSGoLint E2E Snapshot Tests", () => {
278277 expect ( diagnostics ) . toMatchSnapshot ( ) ;
279278 } ) ;
280279
281- it ( " should work with the old version of the headless payload" , async ( ) => {
280+ it ( ' should work with the old version of the headless payload' , async ( ) => {
282281 function generateV1HeadlessPayload (
283282 files : string [ ] ,
284- rules : readonly ( typeof ALL_RULES ) [ number ] [ ] = ALL_RULES
283+ rules : readonly ( typeof ALL_RULES ) [ number ] [ ] = ALL_RULES ,
285284 ) : string {
286285 const config = {
287286 files : files . map ( ( filePath ) => ( {
@@ -294,16 +293,16 @@ describe("TSGoLint E2E Snapshot Tests", () => {
294293
295294 function getDiagnostics ( config : string ) : Diagnostic [ ] {
296295 let output : Buffer ;
297- output = execFileSync ( TSGOLINT_BIN , [ " headless" ] , {
296+ output = execFileSync ( TSGOLINT_BIN , [ ' headless' ] , {
298297 input : config ,
299- env : { ...process . env , GOMAXPROCS : "1" } ,
298+ env : { ...process . env , GOMAXPROCS : '1' } ,
300299 } ) ;
301300
302301 const diagnostics = parseHeadlessOutput ( output ) ;
303302 return sortDiagnostics ( diagnostics ) ;
304303 }
305304
306- const testFiles = await getTestFiles ( " basic" ) ;
305+ const testFiles = await getTestFiles ( ' basic' ) ;
307306 expect ( testFiles . length ) . toBeGreaterThan ( 0 ) ;
308307
309308 const v1Config = generateV1HeadlessPayload ( testFiles ) ;
0 commit comments