Skip to content

Add option to ignore files outside the workspace - #2227

Merged
Dirk Bäumer (dbaeumer) merged 7 commits into
microsoft:mainfrom
QinXi-ai:codex/limit-lint-to-workspace
Oct 16, 2026
Merged

Dirk Bäumer (dbaeumer) merged 7 commits into
microsoft:mainfrom
QinXi-ai:codex/limit-lint-to-workspace

Conversation

@QinXi-ai

@QinXi-ai QinXi (QinXi-ai) commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Opening a local file outside the current workspace can make the extension load and run an unrelated ESLint configuration. The existing behavior is useful for single-file workflows, so changing it unconditionally would break compatibility.

Design

  • Add an opt-in eslint.ignoreOutsideWorkspace resource setting, defaulting to false.
  • When enabled and at least one workspace folder is open, skip local file: documents that do not belong to any workspace folder.
  • Keep untitled and virtual documents unchanged, and keep standalone-file validation working when no folder is open.
  • Apply the boundary before explicit eslint.validate rules so the option consistently blocks external files.
  • Re-evaluate synced documents when workspace folders are added or removed, in addition to configuration changes.
  • Extract the validator behind a small injectable workspace interface so boundary behavior can be tested without a VS Code host. Preserve legacy eslint.validate entry validation, including rejecting non-boolean autoFix values.

Tests

  • npm run compile
  • npm run lint --prefix client
  • npm run lint --prefix server
  • npm test (client: 25 passed; server: 5 passed)
  • git diff --check
  • Regression tests reject string, null, numeric, object, and array autoFix values; these seven cases failed before the guard fix and pass afterward. Valid legacy entries and subsequent valid language entries remain accepted.

Fixes #1805

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@QinXi-ai

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Comment thread client/src/validator.ts Resolved
Comment thread client/src/validator.ts Resolved
@QinXi-ai

Copy link
Copy Markdown
Contributor Author

Addressed both review points in 70c63af:

  • replaced the hand-written workspace interfaces with a Pick of the VS Code workspace API
  • applied ignoreOutsideWorkspace to remote and virtual workspace documents while leaving untitled documents under ignoreUntitled
  • added remote in-workspace and outside-workspace coverage and updated the setting documentation

Validation: client TypeScript compile passed, all 9 client tests passed, and client/server lint passed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Virtual documents are incorrectly excluded, and workspace-folder transitions leave document synchronization state inconsistent.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds opt-in workspace-boundary filtering for ESLint validation while preserving standalone-file behavior.

Changes:

  • Adds and documents eslint.ignoreOutsideWorkspace.
  • Extracts validation logic into an injectable, tested validator.
  • Refreshes document synchronization when workspace folders change.
File summaries
File Description
$shared/settings.ts Adds the shared setting type.
package.json Declares the resource setting.
README.md Documents the option.
client/src/validator.ts Implements workspace-boundary validation.
client/src/tests/validator.test.ts Tests boundary behavior.
client/src/extension.ts Uses the validator during activation.
client/src/client.ts Refreshes synchronization and sends settings.
server/src/eslint.ts Adds the server-side default.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client/src/client.ts Resolved
Comment thread client/src/validator.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The extracted validator weakens validation of malformed legacy eslint.validate entries.

Review effort: Balanced
Findings: None

Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Preserve autoFix validation in the extracted type guard

client/​src/​validator.ts:17

The extracted type guard no longer validates the deprecated autoFix property. A malformed entry such as { "language": "javascript", "autoFix": "false" } is now accepted and forces validation on, whereas the previous ValidateItem.is rejected it. Preserve the old guard semantics so this refactor does not change how invalid settings are handled.

@QinXi-ai

Copy link
Copy Markdown
Contributor Author

Dirk Bäumer (@dbaeumer) Could you take another look at this PR when you have a chance? The earlier workspace-boundary and typing comments were addressed in 34bb14a, and the latest b3b5bf9 restores the legacy autoFix validation behavior identified in the follow-up review. The current head is b3b5bf9; the review threads are resolved.

I validated the current branch locally with TypeScript compilation, client/server lint, 25 client tests, and 5 server tests. The CLA check has passed. GitHub's “VS Code PR Check” has remained in progress since September 21, so I cannot claim that check is complete.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation matches the stated design and includes focused regression coverage.

0 open findings

🧠 Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation matches the stated design and includes focused regression coverage.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:35
@dbaeumer
Dirk Bäumer (dbaeumer) enabled auto-merge (squash) October 16, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The filtering, settings wiring, lifecycle handling, and regression coverage are consistent, with no unresolved blocking issues.

0 open findings

🧠 Review effort: Balanced

@dbaeumer
Dirk Bäumer (dbaeumer) merged commit dab1e2f into microsoft:main Oct 16, 2026
5 checks passed
Srikanth Palutla (sripal2013) added a commit to sripal2013/vscode-eslint that referenced this pull request Oct 16, 2026
Merge upstream PR microsoft#2227 (Validator moved to client/src/validator.ts);
re-applied eslint.showStatsOutputChannel command registrations.
Srikanth Palutla (sripal2013) added a commit to sripal2013/vscode-eslint that referenced this pull request Oct 16, 2026
Merge upstream PR microsoft#2227 (Validator moved to client/src/validator.ts);
re-applied eslint.showStatsOutputChannel command registrations.
Srikanth Palutla (sripal2013) added a commit to sripal2013/vscode-eslint that referenced this pull request Oct 16, 2026
Merge upstream PR microsoft#2227 (Validator moved to client/src/validator.ts);
re-applied eslint.showStatsOutputChannel command registrations.
@dbaeumer Dirk Bäumer (dbaeumer) added this to the 3.0.36 milestone Oct 22, 2026
Dirk Bäumer (dbaeumer) added a commit that referenced this pull request Oct 22, 2026
* Report ESLint rule performance stats in an output channel (#2057)

When the `stats: true` ESLint option is set via `eslint.options`, the
server now aggregates per-rule timing data from each lint report and sends
it to the client over a new `eslint/stats` notification. The client logs
the timings to a dedicated "ESLint Stats" output channel, sorted by time
descending, with a new `eslint.showStatsOutputChannel` command to reveal it.

Fixes #2057

(part 1: server stats aggregation + protocol + tests)

* Report ESLint rule performance stats in an output channel (#2057)

When the `stats: true` ESLint option is set via `eslint.options`, the
server now aggregates per-rule timing data from each lint report and sends
it to the client over a new `eslint/stats` notification. The client logs
the timings to a dedicated "ESLint Stats" output channel, sorted by time
descending, with a new `eslint.showStatsOutputChannel` command to reveal it.

Fixes #2057

(part 2: client stats output channel + command)

* Move stats output helpers into the ESLintClient namespace

Addresses dbaeumer's review on #2248: the stats-channel helpers now live inside the existing ESLintClient namespace instead of being exported at module top level.

* Send only the document URI in eslint/stats; render via vscode.Uri on the client

The server no longer computes a file path for the stats report. The
client parses the URI with the VS Code API and prints fsPath for file
documents, the URI string otherwise, so untitled documents keep
distinguishable identities instead of collapsing onto synthetic
workspace paths.

* Sync with upstream main (conflict resolution, part 1/3)

Merge upstream PR #2227 (Validator moved to client/src/validator.ts);
re-applied eslint.showStatsOutputChannel command registrations.

* Sync with upstream main (conflict resolution, part 2/3)

Merge upstream PR #2227 (Validator moved to client/src/validator.ts);
re-applied eslint.showStatsOutputChannel command registrations.

* Sync with upstream main (conflict resolution, part 3/3)

Merge upstream PR #2227 (Validator moved to client/src/validator.ts);
re-applied eslint.showStatsOutputChannel command registrations.

* Restore CRLF line endings on upstream-synced files

* Move Stats* import to top of file to avoid merge conflicts with upstream import refactoring

* Refactor ESLint stats notification into shared reporter

* Report ESLint stats from fix and formatting runs

* Fix shared stats reporter structure

* Fix stats URI scope in fix and format runs

* Enable configured ESLint stats for fix runs

* Type ESLint stats option for fix runs

* Remove redundant stats option override

* Pass remote-host context to validator

* Pass VS Code remote host to validator

* Test workspace filtering on remote hosts

* Define remote host context for validator

* Skip workspace exclusion on remote hosts

* Import remote host information from VS Code

* Remove remote-host validator change, keep PR scoped to stats feature

Reverts the remote-host handling in the Validator (the remoteName
condition in the ignoreOutsideWorkspace check, the ValidateEnvironment
context, and the env plumbing in extension.ts) together with its test.
validator.ts and validator.test.ts return to their upstream form; the
PR now contains only the ESLint rule-performance stats feature.

---------

Co-authored-by: Dirk Bäumer <[email protected]>
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.

Do not lint outside current project workspace directory

6 participants