@@ -10,21 +10,20 @@ use oxc_diagnostics::{DiagnosticSender, DiagnosticService};
1010use oxc_span:: Span ;
1111
1212use crate :: {
13- AllowWarnDeny , ConfigStore , DisableDirectives , LintService , LintServiceOptions , Linter ,
14- TsGoLintState ,
13+ AllowWarnDeny , DisableDirectives , LintService , LintServiceOptions , Linter , TsGoLintState ,
1514} ;
1615
1716/// Unified runner that orchestrates both regular (oxc) and type-aware (tsgolint) linting
1817/// with centralized disable directives handling.
1918pub struct LintRunner {
2019 /// Regular oxc linter
21- regular_linter : Option < Linter > ,
20+ lint_service : LintService ,
2221 /// Type-aware tsgolint
2322 type_aware_linter : Option < TsGoLintState > ,
2423 /// Shared disable directives coordinator
2524 directives_store : DirectivesStore ,
26- /// Lint service options
27- lint_service_options : LintServiceOptions ,
25+ /// Current working directory
26+ cwd : PathBuf ,
2827}
2928
3029/// Manages disable directives across all linting engines.
@@ -126,30 +125,22 @@ impl Default for DirectivesStore {
126125
127126/// Builder for LintRunner
128127pub struct LintRunnerBuilder {
129- regular_linter : Option < Linter > ,
128+ regular_linter : Linter ,
130129 type_aware_enabled : bool ,
131- config_store : ConfigStore ,
132130 lint_service_options : LintServiceOptions ,
133131 silent : bool ,
134132}
135133
136134impl LintRunnerBuilder {
137- pub fn new ( lint_service_options : LintServiceOptions , config_store : ConfigStore ) -> Self {
135+ pub fn new ( lint_service_options : LintServiceOptions , linter : Linter ) -> Self {
138136 Self {
139- regular_linter : None ,
137+ regular_linter : linter ,
140138 type_aware_enabled : false ,
141- config_store,
142139 lint_service_options,
143140 silent : false ,
144141 }
145142 }
146143
147- #[ must_use]
148- pub fn with_linter ( mut self , linter : Linter ) -> Self {
149- self . regular_linter = Some ( linter) ;
150- self
151- }
152-
153144 #[ must_use]
154145 pub fn with_type_aware ( mut self , enabled : bool ) -> Self {
155146 self . type_aware_enabled = enabled;
@@ -168,31 +159,33 @@ impl LintRunnerBuilder {
168159 let directives_coordinator = DirectivesStore :: new ( ) ;
169160
170161 let type_aware_linter = if self . type_aware_enabled {
171- match TsGoLintState :: try_new ( self . lint_service_options . cwd ( ) , self . config_store . clone ( ) )
172- {
162+ match TsGoLintState :: try_new (
163+ self . lint_service_options . cwd ( ) ,
164+ self . regular_linter . config . clone ( ) ,
165+ ) {
173166 Ok ( state) => Some ( state. with_silent ( self . silent ) ) ,
174167 Err ( e) => return Err ( e) ,
175168 }
176169 } else {
177170 None
178171 } ;
179172
173+ let cwd = self . lint_service_options . cwd ( ) . to_path_buf ( ) ;
174+ let lint_service = LintService :: new ( self . regular_linter , self . lint_service_options ) ;
175+
180176 Ok ( LintRunner {
181- regular_linter : self . regular_linter ,
177+ lint_service ,
182178 type_aware_linter,
183179 directives_store : directives_coordinator,
184- lint_service_options : self . lint_service_options ,
180+ cwd ,
185181 } )
186182 }
187183}
188184
189185impl LintRunner {
190186 /// Create a new builder for LintRunner
191- pub fn builder (
192- lint_service_options : LintServiceOptions ,
193- config_store : ConfigStore ,
194- ) -> LintRunnerBuilder {
195- LintRunnerBuilder :: new ( lint_service_options, config_store)
187+ pub fn builder ( lint_service_options : LintServiceOptions , linter : Linter ) -> LintRunnerBuilder {
188+ LintRunnerBuilder :: new ( lint_service_options, linter)
196189 }
197190
198191 /// Run both regular and type-aware linting on files
@@ -205,25 +198,21 @@ impl LintRunner {
205198 file_system : Option < Box < dyn crate :: RuntimeFileSystem + Sync + Send > > ,
206199 ) -> Result < Self , String > {
207200 // Phase 1: Regular linting (collects disable directives)
208- if let Some ( linter) = self . regular_linter . take ( ) {
209- let files = files. to_owned ( ) ;
210- let directives_map = self . directives_store . map ( ) ;
211- let lint_service_options = self . lint_service_options . clone ( ) ;
212-
213- let mut lint_service = LintService :: new ( linter, lint_service_options) ;
214- lint_service. with_paths ( files) ;
215- lint_service. set_disable_directives_map ( directives_map) ;
216-
217- // Set custom file system if provided
218- if let Some ( fs) = file_system {
219- lint_service. with_file_system ( fs) ;
220- }
201+ let files = files. to_owned ( ) ;
202+ let directives_map = self . directives_store . map ( ) ;
203+
204+ self . lint_service . with_paths ( files. clone ( ) ) ;
205+ self . lint_service . set_disable_directives_map ( directives_map) ;
221206
222- lint_service. run ( & tx_error) ;
207+ // Set custom file system if provided
208+ if let Some ( fs) = file_system {
209+ self . lint_service . with_file_system ( fs) ;
223210 }
224211
212+ self . lint_service . run ( & tx_error) ;
213+
225214 if let Some ( type_aware_linter) = self . type_aware_linter . take ( ) {
226- type_aware_linter. lint ( files, self . directives_store . map ( ) , tx_error) ?;
215+ type_aware_linter. lint ( & files, self . directives_store . map ( ) , tx_error) ?;
227216 } else {
228217 drop ( tx_error) ;
229218 }
@@ -238,11 +227,7 @@ impl LintRunner {
238227 tx_error : & DiagnosticSender ,
239228 ) {
240229 if let Some ( severity) = severity {
241- self . directives_store . report_unused (
242- severity,
243- self . lint_service_options . cwd ( ) ,
244- tx_error,
245- ) ;
230+ self . directives_store . report_unused ( severity, & self . cwd , tx_error) ;
246231 }
247232 }
248233
0 commit comments