@@ -25,23 +25,24 @@ use crate::{ConcurrentHashMap, LINT_CONFIG_FILE};
2525
2626use super :: config_walker:: ConfigWalker ;
2727
28- pub struct ServerLinter {
29- isolated_linter : Arc < Mutex < IsolatedLintHandler > > ,
30- ignore_matcher : LintIgnoreMatcher ,
31- gitignore_glob : Vec < Gitignore > ,
32- diagnostics : Arc < ConcurrentHashMap < String , Option < Vec < DiagnosticReport > > > > ,
33- extended_paths : FxHashSet < PathBuf > ,
28+ pub struct ServerLinterBuilder {
29+ root_uri : Uri ,
30+ options : LSPLintOptions ,
3431}
3532
36- impl ServerLinter {
33+ impl ServerLinterBuilder {
34+ pub fn new ( root_uri : Uri , options : LSPLintOptions ) -> Self {
35+ Self { root_uri, options }
36+ }
37+
3738 /// # Panics
3839 /// Panics if the root URI cannot be converted to a file path.
39- pub fn new ( root_uri : & Uri , options : & LSPLintOptions ) -> Self {
40- let root_path = root_uri. to_file_path ( ) . unwrap ( ) ;
40+ pub fn build ( & self ) -> ServerLinter {
41+ let root_path = self . root_uri . to_file_path ( ) . unwrap ( ) ;
4142 let mut nested_ignore_patterns = Vec :: new ( ) ;
4243 let ( nested_configs, mut extended_paths) =
43- Self :: create_nested_configs ( & root_path, options, & mut nested_ignore_patterns) ;
44- let config_path = options. config_path . as_ref ( ) . map_or ( LINT_CONFIG_FILE , |v| v) ;
44+ Self :: create_nested_configs ( & root_path, & self . options , & mut nested_ignore_patterns) ;
45+ let config_path = self . options . config_path . as_ref ( ) . map_or ( LINT_CONFIG_FILE , |v| v) ;
4546 let config = normalize_path ( root_path. join ( config_path) ) ;
4647 let oxlintrc = if config. try_exists ( ) . is_ok_and ( |exists| exists) {
4748 if let Ok ( oxlintrc) = Oxlintrc :: from_file ( & config) {
@@ -66,8 +67,8 @@ impl ServerLinter {
6667 . unwrap_or_default ( ) ;
6768
6869 // TODO(refactor): pull this into a shared function, because in oxlint we have the same functionality.
69- let use_nested_config = options. use_nested_configs ( ) ;
70- let fix_kind = FixKind :: from ( options. fix_kind . clone ( ) ) ;
70+ let use_nested_config = self . options . use_nested_configs ( ) ;
71+ let fix_kind = FixKind :: from ( self . options . fix_kind . clone ( ) ) ;
7172
7273 let use_cross_module = config_builder. plugins ( ) . has_import ( )
7374 || ( use_nested_config
@@ -81,7 +82,7 @@ impl ServerLinter {
8182
8283 let lint_options = LintOptions {
8384 fix : fix_kind,
84- report_unused_directive : match options. unused_disable_directives {
85+ report_unused_directive : match self . options . unused_disable_directives {
8586 UnusedDisableDirectives :: Allow => None , // or AllowWarnDeny::Allow, should be the same?
8687 UnusedDisableDirectives :: Warn => Some ( AllowWarnDeny :: Warn ) ,
8788 UnusedDisableDirectives :: Deny => Some ( AllowWarnDeny :: Deny ) ,
@@ -107,27 +108,22 @@ impl ServerLinter {
107108 config_store,
108109 & IsolatedLintHandlerOptions {
109110 use_cross_module,
110- type_aware : options. type_aware ,
111- fix_kind : FixKind :: from ( options. fix_kind . clone ( ) ) ,
111+ type_aware : self . options . type_aware ,
112+ fix_kind : FixKind :: from ( self . options . fix_kind . clone ( ) ) ,
112113 root_path : root_path. to_path_buf ( ) ,
113- tsconfig_path : options. ts_config_path . as_ref ( ) . map ( |path| {
114+ tsconfig_path : self . options . ts_config_path . as_ref ( ) . map ( |path| {
114115 let path = Path :: new ( path) . to_path_buf ( ) ;
115116 if path. is_relative ( ) { root_path. join ( path) } else { path }
116117 } ) ,
117118 } ,
118119 ) ;
119120
120- Self {
121- isolated_linter : Arc :: new ( Mutex :: new ( isolated_linter) ) ,
122- ignore_matcher : LintIgnoreMatcher :: new (
123- & base_patterns,
124- & root_path,
125- nested_ignore_patterns,
126- ) ,
127- gitignore_glob : Self :: create_ignore_glob ( & root_path) ,
121+ ServerLinter :: new (
122+ Arc :: new ( Mutex :: new ( isolated_linter) ) ,
123+ LintIgnoreMatcher :: new ( & base_patterns, & root_path, nested_ignore_patterns) ,
124+ Self :: create_ignore_glob ( & root_path) ,
128125 extended_paths,
129- diagnostics : Arc :: new ( ConcurrentHashMap :: default ( ) ) ,
130- }
126+ )
131127 }
132128
133129 /// Searches inside root_uri recursively for the default oxlint config files
@@ -213,6 +209,33 @@ impl ServerLinter {
213209
214210 gitignore_globs
215211 }
212+ }
213+
214+ pub struct ServerLinter {
215+ isolated_linter : Arc < Mutex < IsolatedLintHandler > > ,
216+ ignore_matcher : LintIgnoreMatcher ,
217+ gitignore_glob : Vec < Gitignore > ,
218+ extended_paths : FxHashSet < PathBuf > ,
219+ diagnostics : Arc < ConcurrentHashMap < String , Option < Vec < DiagnosticReport > > > > ,
220+ }
221+
222+ impl ServerLinter {
223+ /// # Panics
224+ /// Panics if the root URI cannot be converted to a file path.
225+ pub fn new (
226+ isolated_linter : Arc < Mutex < IsolatedLintHandler > > ,
227+ ignore_matcher : LintIgnoreMatcher ,
228+ gitignore_glob : Vec < Gitignore > ,
229+ extended_paths : FxHashSet < PathBuf > ,
230+ ) -> Self {
231+ Self {
232+ isolated_linter,
233+ ignore_matcher,
234+ gitignore_glob,
235+ extended_paths,
236+ diagnostics : Arc :: new ( ConcurrentHashMap :: default ( ) ) ,
237+ }
238+ }
216239
217240 pub fn remove_diagnostics ( & self , uri : & Uri ) {
218241 self . diagnostics . pin ( ) . remove ( & uri. to_string ( ) ) ;
@@ -336,14 +359,14 @@ mod test {
336359 use serde_json:: json;
337360
338361 use crate :: {
339- linter:: { options:: LintOptions , server_linter:: ServerLinter } ,
362+ linter:: { options:: LintOptions , server_linter:: ServerLinterBuilder } ,
340363 tester:: { Tester , get_file_path} ,
341364 } ;
342365
343366 #[ test]
344367 fn test_create_nested_configs_with_disabled_nested_configs ( ) {
345368 let mut nested_ignore_patterns = Vec :: new ( ) ;
346- let ( configs, _) = ServerLinter :: create_nested_configs (
369+ let ( configs, _) = ServerLinterBuilder :: create_nested_configs (
347370 Path :: new ( "/root/" ) ,
348371 & LintOptions { disable_nested_config : true , ..LintOptions :: default ( ) } ,
349372 & mut nested_ignore_patterns,
@@ -355,7 +378,7 @@ mod test {
355378 #[ test]
356379 fn test_create_nested_configs ( ) {
357380 let mut nested_ignore_patterns = Vec :: new ( ) ;
358- let ( configs, _) = ServerLinter :: create_nested_configs (
381+ let ( configs, _) = ServerLinterBuilder :: create_nested_configs (
359382 & get_file_path ( "fixtures/linter/init_nested_configs" ) ,
360383 & LintOptions :: default ( ) ,
361384 & mut nested_ignore_patterns,
0 commit comments