22// particular) pound on statSync per file and benefit from in-process caching.
33require ( './lib/fs-cache.js' ) ;
44
5+ // Env vars for downstream packages must be set BEFORE any import that
6+ // transitively loads them — they're read at module-load time, not on use.
7+ process . env . TSSLINT_CLI = '1' ;
8+ if ( process . argv . includes ( '--debug-estree' ) ) {
9+ process . env . TSSLINT_DEBUG_ESTREE = '1' ;
10+ }
11+
512import ts = require( 'typescript' ) ;
613import path = require( 'path' ) ;
714import worker = require( './lib/worker.js' ) ;
@@ -12,8 +19,6 @@ import languagePlugins = require('./lib/languagePlugins.js');
1219import colors = require( './lib/colors.js' ) ;
1320import render = require( './lib/render.js' ) ;
1421
15- process . env . TSSLINT_CLI = '1' ;
16-
1722const HELP = `
1823Usage: tsslint [options]
1924
@@ -29,6 +34,7 @@ Options:
2934 --force Ignore cache (re-lint every file)
3035 --failures-only Only print errors and messages (skip warnings and suggestions)
3136 --list-rules After linting, print each rule's classification (syntactic / type-aware)
37+ --debug-estree After linting, print the actual ESTree node types converted by @tsslint/compat-eslint and their counts
3238 -h, --help Show this help message
3339
3440Examples:
@@ -362,6 +368,34 @@ const formatHost: ts.FormatDiagnosticsHost = {
362368 for ( const l of lines ) renderer . info ( l ) ;
363369 }
364370
371+ if ( process . argv . includes ( '--debug-estree' ) ) {
372+ // compat-eslint's lazy-estree publishes a per-`type` counter on
373+ // globalThis under Symbol.for('@tsslint/compat-eslint:node-type-counts')
374+ // when TSSLINT_DEBUG_ESTREE=1 (set above before any import). Reading
375+ // from the shared global side-steps Node's per-package module-
376+ // resolution: the user's project typically loads compat-eslint
377+ // from its OWN node_modules, while a `require()` here would land
378+ // on the CLI's neighbour copy — different module instances,
379+ // different counters. globalThis closes that gap.
380+ const COUNTS_KEY = Symbol . for ( '@tsslint/compat-eslint:node-type-counts' ) ;
381+ const counts = ( globalThis as any ) [ COUNTS_KEY ] as Map < string , number > | undefined ;
382+ const sorted = counts
383+ ? [ ...counts . entries ( ) ] . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] || a [ 0 ] . localeCompare ( b [ 0 ] ) )
384+ : [ ] ;
385+ const total = sorted . reduce ( ( s , [ , n ] ) => s + n , 0 ) ;
386+ const widthName = sorted . reduce ( ( w , [ n ] ) => Math . max ( w , n . length ) , 0 ) ;
387+ renderer . info (
388+ colors . cyan ( 'estree node types' )
389+ + colors . gray ( ` (${ sorted . length } kinds, ${ total . toLocaleString ( ) } nodes)` ) ,
390+ ) ;
391+ for ( const [ name , n ] of sorted ) {
392+ renderer . info ( ' ' + name . padEnd ( widthName ) + ' ' + colors . gray ( n . toLocaleString ( ) ) ) ;
393+ }
394+ if ( ! sorted . length ) {
395+ renderer . info ( colors . gray ( ' (no nodes converted — no @tsslint/compat-eslint rules ran)' ) ) ;
396+ }
397+ }
398+
365399 renderer . dispose ( ) ;
366400
367401 process . exit ( ( errors || messages || configErrors ) ? 1 : 0 ) ;
0 commit comments