-
-
Notifications
You must be signed in to change notification settings - Fork 860
refactor(linter): share config loading logic between lsp/cli #18672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
graphite-app
merged 1 commit into
main
from
c/01-28-refactor_linter_share_config_loading_logic_between_lsp_cli
Jan 29, 2026
+148
−87
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| use oxc_diagnostics::OxcDiagnostic; | ||
| use oxc_linter::{ | ||
| Config, ConfigStoreBuilder, ExternalLinter, ExternalPluginStore, LintFilter, Oxlintrc, | ||
| }; | ||
|
|
||
| pub struct LoadedConfig { | ||
| /// The directory this config applies to | ||
| pub dir: PathBuf, | ||
| /// The built configuration | ||
| pub config: Config, | ||
| /// Ignore patterns from this config | ||
| pub ignore_patterns: Vec<String>, | ||
| /// Paths from extends directives | ||
| pub extended_paths: Vec<PathBuf>, | ||
| } | ||
|
|
||
| /// Errors that can occur when loading configs | ||
| #[derive(Debug)] | ||
| pub enum ConfigLoadError { | ||
| /// Failed to parse the config file | ||
| Parse { path: PathBuf, error: OxcDiagnostic }, | ||
| /// Failed to build the ConfigStore | ||
| Build { path: PathBuf, error: String }, | ||
| } | ||
|
|
||
| impl ConfigLoadError { | ||
| /// Get the path of the config file that failed | ||
| pub fn path(&self) -> &Path { | ||
| match self { | ||
| ConfigLoadError::Parse { path, .. } | ConfigLoadError::Build { path, .. } => path, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct ConfigLoader<'a> { | ||
| external_linter: Option<&'a ExternalLinter>, | ||
| external_plugin_store: &'a mut ExternalPluginStore, | ||
| filters: &'a [LintFilter], | ||
| } | ||
|
|
||
| impl<'a> ConfigLoader<'a> { | ||
| /// Create a new ConfigLoader | ||
| /// | ||
| /// # Arguments | ||
| /// * `external_linter` - Optional external linter for plugin support | ||
| /// * `external_plugin_store` - Store for external plugins | ||
| /// * `filters` - Lint filters to apply to configs | ||
| pub fn new( | ||
| external_linter: Option<&'a ExternalLinter>, | ||
| external_plugin_store: &'a mut ExternalPluginStore, | ||
| filters: &'a [LintFilter], | ||
| ) -> Self { | ||
| Self { external_linter, external_plugin_store, filters } | ||
| } | ||
|
|
||
| /// Load a single config from a file path | ||
| fn load(&mut self, path: &Path) -> Result<LoadedConfig, ConfigLoadError> { | ||
| let oxlintrc = Oxlintrc::from_file(path) | ||
| .map_err(|error| ConfigLoadError::Parse { path: path.to_path_buf(), error })?; | ||
|
|
||
| let dir = oxlintrc.path.parent().unwrap().to_path_buf(); | ||
| let ignore_patterns = oxlintrc.ignore_patterns.clone(); | ||
|
|
||
| let builder = ConfigStoreBuilder::from_oxlintrc( | ||
| false, | ||
| oxlintrc, | ||
| self.external_linter, | ||
| self.external_plugin_store, | ||
| ) | ||
| .map_err(|e| ConfigLoadError::Build { path: path.to_path_buf(), error: e.to_string() })?; | ||
|
|
||
| let extended_paths = builder.extended_paths.clone(); | ||
|
|
||
| let config = | ||
| builder.with_filters(self.filters).build(self.external_plugin_store).map_err(|e| { | ||
| ConfigLoadError::Build { path: path.to_path_buf(), error: e.to_string() } | ||
| })?; | ||
|
|
||
| Ok(LoadedConfig { dir, config, ignore_patterns, extended_paths }) | ||
| } | ||
|
|
||
| /// Load multiple configs, returning successes and errors separately | ||
| /// | ||
| /// This allows callers to decide how to handle errors (fail fast vs continue) | ||
| pub fn load_many( | ||
| &mut self, | ||
| paths: impl IntoIterator<Item = impl AsRef<Path>>, | ||
| ) -> (Vec<LoadedConfig>, Vec<ConfigLoadError>) { | ||
| let mut configs = Vec::new(); | ||
| let mut errors = Vec::new(); | ||
|
|
||
| for path in paths { | ||
| match self.load(path.as_ref()) { | ||
| Ok(config) => configs.push(config), | ||
| Err(e) => errors.push(e), | ||
| } | ||
| } | ||
|
|
||
| (configs, errors) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.