refactor(linter): LintService and Runtime accept file_system and paths as parameters#15515
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the linting service to pass file_system and paths as method parameters instead of storing them as struct fields. This change improves the API design by reducing mutable state and making the dependencies explicit at call sites.
Key Changes
- Removed
file_systemandpathsfields from theRuntimestruct - Updated all public methods (
run,run_source,run_test_source) to acceptfile_systemandpathsas parameters - Changed method signatures from
&mut selfto&selfwhere applicable, improving concurrency safety - Made
OsFileSystempublic to allow external instantiation
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_linter/src/service/runtime.rs | Removed file_system and paths fields; updated all methods to accept them as parameters; made helper methods static where appropriate |
| crates/oxc_linter/src/service/mod.rs | Updated LintService public API to pass file_system and paths to Runtime methods; removed builder-style methods |
| crates/oxc_linter/src/tester.rs | Updated to pass file_system and paths directly to run_test_source |
| crates/oxc_linter/src/lint_runner.rs | Updated to instantiate OsFileSystem locally and pass it along with paths to service methods |
| crates/oxc_linter/src/lib.rs | Exported OsFileSystem for public use |
| crates/oxc_language_server/src/linter/isolated_lint_handler.rs | Updated to pass file system reference directly without boxing |
| crates/oxc_language_server/src/linter/server_linter.rs | Removed mut qualifier from lock as mutation is no longer needed |
| apps/oxlint/src/lint.rs | Updated to convert boxed file system to reference when calling lint_files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #15515 will not alter performanceComparing Summary
Footnotes
|
0822aeb to
c903409
Compare
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merge activity
|
…aths` as parameters (#15515) from #15506 Refactor LintService and Runtime to remove mutable builder-style methods ## Changes Made ### Core Refactoring - Removed `paths` and `file_system` fields from `Runtime` struct - they are no longer stored as mutable state - Removed `with_file_system()` and `with_paths()` builder methods from both `Runtime` and `LintService` - Updated method signatures to accept these as parameters: - `run(&self, file_system: &(dyn RuntimeFileSystem + Sync + Send), paths: Vec<Arc<OsStr>>, tx_error: &DiagnosticSender)` - `run_source(&self, file_system: &(dyn RuntimeFileSystem + Sync + Send), paths: Vec<Arc<OsStr>>)` - `run_test_source(&self, file_system: &(dyn RuntimeFileSystem + Sync + Send), paths: Vec<Arc<OsStr>>, check_syntax_errors: bool, tx_error: &DiagnosticSender)` ### Internal Changes - Updated `resolve_modules`, `process_path`, `process_path_to_module`, and `get_source_type_and_text` to accept file_system and paths as parameters - Made `OsFileSystem` public and exported it from the crate for use by calling code - Converted paths to `IndexSet` at the entry points for efficient lookup during processing - Changed methods from `&mut self` to `&self` where appropriate (papaya HashMap is concurrent and doesn't require mutable access) - Made `get_source_type_and_text` an associated function since it doesn't use `self` - Fixed outdated comments that referenced removed `self.paths` field ### Call Site Updates - **lint_runner.rs**: Updated `lint_files()` and `run_source()` to take references and pass parameters directly - **apps/oxlint**: Updated call to `lint_files()` to pass reference - **tester.rs**: Updated test infrastructure to use new parameter-based API and removed unnecessary `mut` - **oxc_language_server**: Updated `IsolatedLintHandler` methods to use `&self` and pass references ## Testing - ✅ All 820 oxc_linter tests pass - ✅ All 136 oxlint tests pass - ✅ All 92 oxc_language_server tests pass - ✅ All clippy warnings resolved (including `just lint`) - ✅ Code formatted with cargo fmt - ✅ Clean rebase onto latest main (2f0518d) <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > Refactor the oxc_linter crate so that LintService and Runtime no longer mutate internal state via with_file_system and with_paths builder-style methods. Instead, pass the file system and paths as parameters to the run, run_source and run_test_source APIs. > > Scope and requirements: > - Identify the places in crates/oxc_linter/src where LintService and Runtime expose `with_file_system` and `with_paths` methods that mutate internal state. Remove these mutation methods. > - Add parameters to the runtime execution methods to accept the file system and paths at call time. Specifically update signatures for `run`, `run_source`, and `run_test_source` to accept the file system and paths. The exact types should follow existing crate types (e.g., &FileSystem or FileSystem, and &[PathBuf] or Vec<PathBuf]) — keep API ergonomic and idiomatic for the codebase. > - Update any internal implementations to use the passed-in file system and paths instead of using mutated state. > - Update all call sites across the repository that previously relied on `with_file_system`/`with_paths` to instead pass those values into `run`/`run_source`/`run_test_source`. > - This includes code in crates/oxlint and crates/oxc_language_server and tests under crates/oxc_linter. > - Run the test suites for crates: > - crates/oxc_linter > - crates/oxlint > - crates/oxc_language_server > Ensure all tests pass and behavior is unchanged. > - If any tests or call sites need minor adjustments due to signature changes, update them accordingly. > - Keep changes localized and avoid unrelated refactors. Maintain public API compatibility where feasible for external consumers by providing deprecation shims if necessary. > - Add or update unit tests if the refactor requires changes to ensure behavior remains the same. > - Run `cargo fmt`/`cargo clippy` where appropriate and ensure build is clean. > > Deliverables: > - A Git branch with the changes and a single PR opened against main in oxc-project/oxc. > - A concise PR description summarizing what changed and why, and listing which tests were run and their results. > > Notes for implementer: > - Use repository root as workspace. The task only touches oxc_linter public API and call sites. > - Do not change unrelated crates or versions. > - If there are ambiguous type choices, prefer explicit & references (borrowed) rather than owning where feasible to avoid cloning large structures. > - Ensure the language server integration (oxc_language_server) still works with the new call signatures. > > Run tests and report failures if any, fix them so the tests pass. > </details> *This pull request was created as a result of the following prompt from Copilot chat.* > Refactor the oxc_linter crate so that LintService and Runtime no longer mutate internal state via with_file_system and with_paths builder-style methods. Instead, pass the file system and paths as parameters to the run, run_source and run_test_source APIs. > > Scope and requirements: > - Identify the places in crates/oxc_linter/src where LintService and Runtime expose `with_file_system` and `with_paths` methods that mutate internal state. Remove these mutation methods. > - Add parameters to the runtime execution methods to accept the file system and paths at call time. Specifically update signatures for `run`, `run_source`, and `run_test_source` to accept the file system and paths. The exact types should follow existing crate types (e.g., &FileSystem or FileSystem, and &[PathBuf] or Vec<PathBuf]) — keep API ergonomic and idiomatic for the codebase. > - Update any internal implementations to use the passed-in file system and paths instead of using mutated state. > - Update all call sites across the repository that previously relied on `with_file_system`/`with_paths` to instead pass those values into `run`/`run_source`/`run_test_source`. > - This includes code in crates/oxlint and crates/oxc_language_server and tests under crates/oxc_linter. > - Run the test suites for crates: > - crates/oxc_linter > - crates/oxlint > - crates/oxc_language_server > Ensure all tests pass and behavior is unchanged. > - If any tests or call sites need minor adjustments due to signature changes, update them accordingly. > - Keep changes localized and avoid unrelated refactors. Maintain public API compatibility where feasible for external consumers by providing deprecation shims if necessary. > - Add or update unit tests if the refactor requires changes to ensure behavior remains the same. > - Run `cargo fmt`/`cargo clippy` where appropriate and ensure build is clean. > > Deliverables: > - A Git branch with the changes and a single PR opened against main in oxc-project/oxc. > - A concise PR description summarizing what changed and why, and listing which tests were run and their results. > > Notes for implementer: > - Use repository root as workspace. The task only touches oxc_linter public API and call sites. > - Do not change unrelated crates or versions. > - If there are ambiguous type choices, prefer explicit & references (borrowed) rather than owning where feasible to avoid cloning large structures. > - Ensure the language server integration (oxc_language_server) still works with the new call signatures. > > Run tests and report failures if any, fix them so the tests pass. > <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
c903409 to
9675b51
Compare

from #15506
Refactor LintService and Runtime to remove mutable builder-style methods
Changes Made
Core Refactoring
pathsandfile_systemfields fromRuntimestruct - they are no longer stored as mutable statewith_file_system()andwith_paths()builder methods from bothRuntimeandLintServicerun(&self, file_system: &(dyn RuntimeFileSystem + Sync + Send), paths: Vec<Arc<OsStr>>, tx_error: &DiagnosticSender)run_source(&self, file_system: &(dyn RuntimeFileSystem + Sync + Send), paths: Vec<Arc<OsStr>>)run_test_source(&self, file_system: &(dyn RuntimeFileSystem + Sync + Send), paths: Vec<Arc<OsStr>>, check_syntax_errors: bool, tx_error: &DiagnosticSender)Internal Changes
resolve_modules,process_path,process_path_to_module, andget_source_type_and_textto accept file_system and paths as parametersOsFileSystempublic and exported it from the crate for use by calling codeIndexSetat the entry points for efficient lookup during processing&mut selfto&selfwhere appropriate (papaya HashMap is concurrent and doesn't require mutable access)get_source_type_and_textan associated function since it doesn't useselfself.pathsfieldCall Site Updates
lint_files()andrun_source()to take references and pass parameters directlylint_files()to pass referencemutIsolatedLintHandlermethods to use&selfand pass referencesTesting
just lint)Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.