@@ -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,34 @@ 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 mut lint_service = LintService :: new ( self . regular_linter , self . lint_service_options ) ;
175+ lint_service. set_disable_directives_map ( directives_coordinator. map ( ) ) ;
176+
180177 Ok ( LintRunner {
181- regular_linter : self . regular_linter ,
178+ lint_service ,
182179 type_aware_linter,
183180 directives_store : directives_coordinator,
184- lint_service_options : self . lint_service_options ,
181+ cwd ,
185182 } )
186183 }
187184}
188185
189186impl LintRunner {
190187 /// 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)
188+ pub fn builder ( lint_service_options : LintServiceOptions , linter : Linter ) -> LintRunnerBuilder {
189+ LintRunnerBuilder :: new ( lint_service_options, linter)
196190 }
197191
198192 /// Run both regular and type-aware linting on files
@@ -205,23 +199,15 @@ impl LintRunner {
205199 file_system : Option < Box < dyn crate :: RuntimeFileSystem + Sync + Send > > ,
206200 ) -> Result < Self , String > {
207201 // 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- }
202+ self . lint_service . with_paths ( files. to_owned ( ) ) ;
221203
222- lint_service. run ( & tx_error) ;
204+ // Set custom file system if provided
205+ if let Some ( fs) = file_system {
206+ self . lint_service . with_file_system ( fs) ;
223207 }
224208
209+ self . lint_service . run ( & tx_error) ;
210+
225211 if let Some ( type_aware_linter) = self . type_aware_linter . take ( ) {
226212 type_aware_linter. lint ( files, self . directives_store . map ( ) , tx_error) ?;
227213 } else {
@@ -238,11 +224,7 @@ impl LintRunner {
238224 tx_error : & DiagnosticSender ,
239225 ) {
240226 if let Some ( severity) = severity {
241- self . directives_store . report_unused (
242- severity,
243- self . lint_service_options . cwd ( ) ,
244- tx_error,
245- ) ;
227+ self . directives_store . report_unused ( severity, & self . cwd , tx_error) ;
246228 }
247229 }
248230
0 commit comments