Skip to content

eslint - disallow querySelector and friends#274582

Merged
bpasero merged 1 commit intomainfrom
ben/supreme-meerkat
Nov 2, 2025
Merged

eslint - disallow querySelector and friends#274582
bpasero merged 1 commit intomainfrom
ben/supreme-meerkat

Conversation

@bpasero
Copy link
Member

@bpasero bpasero commented Nov 2, 2025

No description provided.

@bpasero bpasero merged commit b487c02 into main Nov 2, 2025
@bpasero bpasero deleted the ben/supreme-meerkat branch November 2, 2025 09:03
Copilot AI review requested due to automatic review settings November 2, 2025 09:45
@bpasero bpasero enabled auto-merge (squash) November 2, 2025 09:45
@bpasero bpasero self-assigned this Nov 2, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new ESLint rule to discourage the use of DOM query methods (querySelector, querySelectorAll, getElementById, etc.) in the browser/electron-browser layer, promoting the use of dom.ts h() for building and accessing elements directly. The rule includes a comprehensive ignore list of existing files that use these methods. Additionally, ESLint disable comments are added to auxiliaryWindowService.ts to suppress warnings where querySelector is legitimately used to clone elements from the main window document to auxiliary windows.

  • Adds no-restricted-syntax ESLint rule for browser/electron-browser layer files to restrict DOM query methods
  • Includes 98 existing files in the ignore list that currently use these methods
  • Adds inline ESLint disable comments in auxiliaryWindowService.ts for legitimate querySelector usage

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
eslint.config.js Adds new ESLint rule configuration restricting DOM query methods with extensive ignore list for existing violations
src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts Adds inline eslint-disable-next-line comments to suppress warnings for legitimate querySelector usage when cloning DOM elements

Comment on lines +406 to 407
// eslint-disable-next-line no-restricted-syntax
const metaElement = mainWindow.document.querySelector(metaTag);
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eslint-disable comment lacks an explanation for why querySelector is necessary here. Add a brief inline comment explaining that querySelector is required because these are existing DOM elements from the main window that need to be discovered and cloned, not new elements being created.

Copilot uses AI. Check for mistakes.
}
}

// eslint-disable-next-line no-restricted-syntax
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eslint-disable comment lacks an explanation for why querySelector is necessary here. Add a brief inline comment explaining that querySelector is required because this queries an existing icon link tag from the main window that needs to be cloned to the auxiliary window.

Suggested change
// eslint-disable-next-line no-restricted-syntax
// eslint-disable-next-line no-restricted-syntax -- querySelector is required here because this queries an existing icon link tag from the main window that needs to be cloned to the auxiliary window.

Copilot uses AI. Check for mistakes.
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants