Skip to content

Commit 80e0a62

Browse files
compat-eslint: --debug-estree + JSX attribute parent fix + shape-table refactor (#88)
1 parent ae8ac63 commit 80e0a62

5 files changed

Lines changed: 1410 additions & 674 deletions

File tree

packages/cli/index.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
// particular) pound on statSync per file and benefit from in-process caching.
33
require('./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+
512
import ts = require('typescript');
613
import path = require('path');
714
import worker = require('./lib/worker.js');
@@ -12,8 +19,6 @@ import languagePlugins = require('./lib/languagePlugins.js');
1219
import colors = require('./lib/colors.js');
1320
import render = require('./lib/render.js');
1421

15-
process.env.TSSLINT_CLI = '1';
16-
1722
const HELP = `
1823
Usage: 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
3440
Examples:
@@ -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);

packages/compat-eslint/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type * as ESLint from 'eslint';
33
import type * as ts from 'typescript';
44
import CodePathAnalyzer = require('./lib/code-path-analysis/code-path-analyzer.js');
55
import { convertLazy } from './lib/lazy-estree';
6+
7+
// Debug surface — see lib/lazy-estree.ts. Gated by env TSSLINT_DEBUG_ESTREE=1
8+
// (set by the CLI's --debug-estree flag, or directly by external callers).
9+
export { getNodeTypeCounts, resetNodeTypeCounts } from './lib/lazy-estree';
610
import { LazySourceCode } from './lib/lazy-source-code';
711
import { decomposeSimple, isCodePathListener } from './lib/selector-analysis';
812
import { convertComments, convertTokens } from './lib/tokens';

0 commit comments

Comments
 (0)