Skip to content

Conversation

@magic-akari
Copy link
Contributor

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 20, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI C-enhancement Category - New feature or request labels Oct 20, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 20, 2025

CodSpeed Performance Report

Merging #14814 will not alter performance

Comparing magic-akari:fix/issue-14777 (5980f4a) with main (1fcf56c)

Summary

✅ 37 untouched

@camc314 camc314 self-assigned this Oct 20, 2025
@magic-akari magic-akari marked this pull request as ready for review October 20, 2025 16:15
@magic-akari magic-akari requested a review from camc314 as a code owner October 20, 2025 16:15
Copilot AI review requested due to automatic review settings October 20, 2025 16:15
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 adds a cwd (current working directory) property to the JavaScript plugin Context object, making it accessible to custom linter rules. The change threads the cwd parameter through the linting pipeline from the Rust side to the JavaScript plugin context.

Key Changes:

  • Added cwd parameter to the linter's run and run_with_disable_directives methods
  • Updated external linter callbacks to accept and pass through the cwd parameter
  • Exposed cwd as a property on the JavaScript Context class

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/oxc_linter/src/lib.rs Added cwd parameter to run and run_with_disable_directives methods and passed it to external rule execution
crates/oxc_linter/src/external_linter.rs Updated ExternalLinterLintFileCb type signature to include cwd parameter
crates/oxc_linter/src/service/runtime.rs Updated calls to linter methods to include me.cwd
apps/oxlint/src/run.rs Updated JsLintFileCb type to include cwd in function arguments
apps/oxlint/src/js_plugins/external_linter.rs Updated callback wrapper to accept and forward cwd parameter
apps/oxlint/src-js/plugins/lint.ts Added cwd parameter to lintFile and lintFileImpl functions with validation
apps/oxlint/src-js/plugins/context.ts Added cwd property to InternalContext interface and Context class with getter
apps/oxlint/src-js/cli.ts Updated wrapper function to include cwd parameter
tasks/benchmark/benches/linter.rs Added path as cwd argument to linter.run call
napi/playground/src/lib.rs Added Path::new(".") as cwd argument to linter run call
apps/oxlint/test/fixtures/context_properties/plugin.ts Added test that reports the cwd value
apps/oxlint/test/fixtures/context_properties/output.snap.md Updated snapshot with expected output including cwd reports

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

can we not use process.cwd?

passing across the cwd for every file we need to lint feels expensive, especially as the cwd never chanegs (as far as i know)

@camc314
Copy link
Contributor

camc314 commented Oct 20, 2025

I looked at eslint's implementation, and it just uses process.cwd() (but can be overridden via cli arguments).

We don't support CLI arguments, for overriding the current working directory, so we can just use process.cwd() on the JS side

refs:
https://github.com/eslint/eslint/blob/43a5f9e36f1aade16f81fc49ef4b333660faadab/lib/linter/linter.js#L1358
https://github.com/eslint/eslint/blob/43a5f9e36f1aade16f81fc49ef4b333660faadab/lib/linter/linter.js#L1274

@magic-akari
Copy link
Contributor Author

I looked at eslint's implementation, and it just uses process.cwd() (but can be overridden via cli arguments).

We don't support CLI arguments, for overriding the current working directory, so we can just use process.cwd() on the JS side

refs: https://github.com/eslint/eslint/blob/43a5f9e36f1aade16f81fc49ef4b333660faadab/lib/linter/linter.js#L1358 https://github.com/eslint/eslint/blob/43a5f9e36f1aade16f81fc49ef4b333660faadab/lib/linter/linter.js#L1274

@camc314 Thanks for the review! Just to confirm I understand correctly: You're suggesting we use process.cwd() directly in JavaScript instead of passing cwd between Rust and JavaScript for every file, right?

@camc314
Copy link
Contributor

camc314 commented Oct 20, 2025

I looked at eslint's implementation, and it just uses process.cwd() (but can be overridden via cli arguments).
We don't support CLI arguments, for overriding the current working directory, so we can just use process.cwd() on the JS side
refs: https://github.com/eslint/eslint/blob/43a5f9e36f1aade16f81fc49ef4b333660faadab/lib/linter/linter.js#L1358 https://github.com/eslint/eslint/blob/43a5f9e36f1aade16f81fc49ef4b333660faadab/lib/linter/linter.js#L1274

@camc314 Thanks for the review! Just to confirm I understand correctly: You're suggesting we use process.cwd() directly in JavaScript instead of passing cwd between Rust and JavaScript for every file, right?

Yep exactly!

Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@camc314 camc314 merged commit 54ec8e3 into oxc-project:main Oct 21, 2025
18 checks passed
graphite-app bot pushed a commit that referenced this pull request Nov 5, 2025
Follow-on after #14814. Small perf optimization. `cwd` is either `null` or a string, so use cheaper `=== null` check instead of `??` (which is equivalent to `cwd === null || cwd === undefined`).

Also rename the var, just for brevity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter plugins: Add cwd property to Context

2 participants