Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
// particular) pound on statSync per file and benefit from in-process caching.
require('./lib/fs-cache.js');

// Env vars for downstream packages must be set BEFORE any import that
// transitively loads them — they're read at module-load time, not on use.
process.env.TSSLINT_CLI = '1';
if (process.argv.includes('--debug-estree')) {
process.env.TSSLINT_DEBUG_ESTREE = '1';
}

import ts = require('typescript');
import path = require('path');
import worker = require('./lib/worker.js');
Expand All @@ -12,8 +19,6 @@ import languagePlugins = require('./lib/languagePlugins.js');
import colors = require('./lib/colors.js');
import render = require('./lib/render.js');

process.env.TSSLINT_CLI = '1';

const HELP = `
Usage: tsslint [options]

Expand All @@ -29,6 +34,7 @@ Options:
--force Ignore cache (re-lint every file)
--failures-only Only print errors and messages (skip warnings and suggestions)
--list-rules After linting, print each rule's classification (syntactic / type-aware)
--debug-estree After linting, print the actual ESTree node types converted by @tsslint/compat-eslint and their counts
-h, --help Show this help message

Examples:
Expand Down Expand Up @@ -362,6 +368,34 @@ const formatHost: ts.FormatDiagnosticsHost = {
for (const l of lines) renderer.info(l);
}

if (process.argv.includes('--debug-estree')) {
// compat-eslint's lazy-estree publishes a per-`type` counter on
// globalThis under Symbol.for('@tsslint/compat-eslint:node-type-counts')
// when TSSLINT_DEBUG_ESTREE=1 (set above before any import). Reading
// from the shared global side-steps Node's per-package module-
// resolution: the user's project typically loads compat-eslint
// from its OWN node_modules, while a `require()` here would land
// on the CLI's neighbour copy — different module instances,
// different counters. globalThis closes that gap.
const COUNTS_KEY = Symbol.for('@tsslint/compat-eslint:node-type-counts');
const counts = (globalThis as any)[COUNTS_KEY] as Map<string, number> | undefined;
const sorted = counts
? [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
: [];
const total = sorted.reduce((s, [, n]) => s + n, 0);
const widthName = sorted.reduce((w, [n]) => Math.max(w, n.length), 0);
renderer.info(
colors.cyan('estree node types')
+ colors.gray(` (${sorted.length} kinds, ${total.toLocaleString()} nodes)`),
);
for (const [name, n] of sorted) {
renderer.info(' ' + name.padEnd(widthName) + ' ' + colors.gray(n.toLocaleString()));
}
if (!sorted.length) {
renderer.info(colors.gray(' (no nodes converted — no @tsslint/compat-eslint rules ran)'));
}
}

renderer.dispose();

process.exit((errors || messages || configErrors) ? 1 : 0);
Expand Down
4 changes: 4 additions & 0 deletions packages/compat-eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type * as ESLint from 'eslint';
import type * as ts from 'typescript';
import CodePathAnalyzer = require('./lib/code-path-analysis/code-path-analyzer.js');
import { convertLazy } from './lib/lazy-estree';

// Debug surface — see lib/lazy-estree.ts. Gated by env TSSLINT_DEBUG_ESTREE=1
// (set by the CLI's --debug-estree flag, or directly by external callers).
export { getNodeTypeCounts, resetNodeTypeCounts } from './lib/lazy-estree';
import { LazySourceCode } from './lib/lazy-source-code';
import { decomposeSimple, isCodePathListener } from './lib/selector-analysis';
import { convertComments, convertTokens } from './lib/tokens';
Expand Down
Loading
Loading