Skip to content

chore(eslint): forbid browser bundle value imports in tool, config and telemetry modules - #3558

Merged
Lightning00Blade merged 1 commit into
mainfrom
chore/eslint-no-browser-imports
Nov 23, 2026
Merged

Lightning00Blade merged 1 commit into
mainfrom
chore/eslint-no-browser-imports

Conversation

@yulunz

@yulunz yulunz commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Refs #3427

Follow-up to Lightning00Blade's comment on #3518 ("this is not a test but more of a linting rule which we enforce via test"). Stacked on #3529 in stack #3530.

What

  • eslint.config.js: new config block for src/tools/**, src/config/** and src/telemetry/** that enables @typescript-eslint/no-restricted-imports with one pattern:
    • regex: '(^|/)third_party/browser\\.js$', allowTypeImports: true.
    • A value import from third_party/browser.js is an error, with the hint to use loadBrowser() or a dynamic import() inside the handler. import type stays allowed.
    • I used the built-in typescript-eslint rule rather than a new @local rule. Core no-restricted-imports has no allowTypeImports. Configuring it in a narrower block would also replace the src/** patterns (devtools-frontend, MCP client) for those files, because flat config doesn't merge rule options.
  • AGENTS.md: the "Third-party bundles" section now mentions the lint rule, and says the test covers indirect imports.

Lint rule vs. test

ESLint rule tests/browser-imports.test.ts
Catches a direct value import of browser.js in a tool, config or telemetry file any transitive static import chain from a listed entry to browser.js, e.g. tools/memory.js -> formatters/HeapSnapshotFormatter.js -> third_party/browser.js
Feedback in the editor and npm run format / check-format npm run test, after a build
Scope every file in the three directories the listed entries (including tools/tools.js) and everything they import

ESLint looks at one file at a time and cannot follow imports into other modules. Most regressions in this series were indirect, through a formatter, LogpointManager.ts or PerformanceTrace.ts. So the test stays as the transitive check, and the lint rule gives earlier, cheaper feedback for the direct case.

Test plan

  • Deliberate bad import in src/tools/emulation.ts (reverted):
    import {TimeoutError} from '../third_party/browser.js';
    import type {Page} from '../third_party/browser.js';
    npm run check-format reported only the value import:
    src/tools/emulation.ts
      9:1  error  '../third_party/browser.js' import is restricted from being used by a pattern. Do not import values from third_party/browser.js here; use loadBrowser() or a dynamic import() inside the handler  @typescript-eslint/no-restricted-imports
    
    The import type line on line 10 was not reported.
  • npm run format is clean on the current code: no existing tool, config or telemetry file imports values from browser.js.
  • Full npm run test passes.

@yulunz
yulunz removed this pull request from stack #3530 November 19, 2026 22:06
@yulunz
yulunz added this pull request to stack #3567 November 19, 2026 22:08
@Lightning00Blade
Lightning00Blade force-pushed the chore/eslint-no-browser-imports branch from d132fbc to 2cbe6df Compare November 23, 2026 12:36
@Lightning00Blade
Lightning00Blade enabled stacked auto-merge November 23, 2026 12:40
@Lightning00Blade
Lightning00Blade added this pull request to the merge queue Nov 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 23, 2026
Base automatically changed from docs/agents-third-party-bundles to main November 23, 2026 13:23
…d telemetry modules

Configure @typescript-eslint/no-restricted-imports so that modules under
src/tools/, src/config/ and src/telemetry/ cannot import values from
third_party/browser.js. Type-only imports stay allowed. The rule only
sees direct imports, so tests/browser-imports.test.ts keeps checking that
the listed modules do not reach browser.js through other modules.

Refs #3427
@Lightning00Blade
Lightning00Blade force-pushed the chore/eslint-no-browser-imports branch from 2cbe6df to 297fbd4 Compare November 23, 2026 13:23
@Lightning00Blade
Lightning00Blade added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 1e07274 Nov 23, 2026
17 checks passed
@Lightning00Blade
Lightning00Blade deleted the chore/eslint-no-browser-imports branch November 23, 2026 13:49
OrKoN pushed a commit to JasonOA888/chrome-devtools-mcp that referenced this pull request Nov 23, 2026
…omeDevTools#3561)

Refs ChromeDevTools#3427

Follow-up to ChromeDevTools#3558. Stacked on ChromeDevTools#3558 in stack #3530.

## What

ChromeDevTools#3558 adds an ESLint rule (`@typescript-eslint/no-restricted-imports`)
that rejects value imports from `third_party/browser.js` in
`src/tools/`, `src/config/` and `src/telemetry/`. This PR relies on that
rule instead of the import-graph test:

- Removes `tests/browser-imports.test.ts` and its `tests/BUILD.gn`
entry.
- Removes the shared `tests/importGraph.ts` helper.
`tests/cli-imports.test.ts` was its only other user, so the graph walk
goes back inline there. That file is now identical to its version before
ChromeDevTools#3518, so the CLI check behaves exactly as before.
- `AGENTS.md`: the "Third-party bundles" section now describes only the
lint rule: it rejects direct value imports from `browser.js` in
`src/tools/`, `src/config/` and `src/telemetry/`.

## Known limitation

ESLint checks one file at a time and only sees direct imports. An
indirect import through another module is no longer caught, for example
`tools/memory.ts` → `formatters/HeapSnapshotFormatter.ts` →
`third_party/browser.js`. The removed test used to catch that case by
walking the built import graph.

## Test plan

- `npm run format`.
- `npm run test tests/cli-imports.test.ts` and the full `npm run test`
pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants