@@ -24,6 +24,9 @@ pub struct TsGoLintState {
2424 cwd : PathBuf ,
2525 /// The configuration store for `tsgolint` (used to resolve configurations outside of `oxc_linter`)
2626 config_store : ConfigStore ,
27+ /// If `oxlint` will output the diagnostics or not.
28+ /// When `silent` is true, we do not need to access the file system for nice diagnostics messages.
29+ silent : bool ,
2730}
2831
2932impl TsGoLintState {
@@ -32,9 +35,20 @@ impl TsGoLintState {
3235 config_store,
3336 executable_path : try_find_tsgolint_executable ( cwd) . unwrap_or ( PathBuf :: from ( "tsgolint" ) ) ,
3437 cwd : cwd. to_path_buf ( ) ,
38+ silent : false ,
3539 }
3640 }
3741
42+ /// Set to `true` to skip file system reads.
43+ /// When `silent` is true, we do not need to access the file system for nice diagnostics messages.
44+ ///
45+ /// Default is `false`.
46+ #[ must_use]
47+ pub fn with_silent ( mut self , yes : bool ) -> Self {
48+ self . silent = yes;
49+ self
50+ }
51+
3852 /// # Panics
3953 /// - when `stdin` of subprocess cannot be opened
4054 /// - when `stdout` of subprocess cannot be opened
@@ -147,18 +161,22 @@ impl TsGoLintState {
147161 } ,
148162 ) ;
149163
150- let source_text: & str =
151- if let Some ( source_text) = source_text_map. get ( & path) {
152- source_text. as_str ( )
153- } else {
154- let source_text = read_to_string ( & path)
155- . unwrap_or_else ( |_| String :: new ( ) ) ;
156- // Insert and get a reference to the inserted string
157- let entry = source_text_map
158- . entry ( path. clone ( ) )
159- . or_insert ( source_text) ;
160- entry. as_str ( )
161- } ;
164+ let source_text: & str = if self . silent {
165+ // The source text is not needed in silent mode.
166+ // The source text is only here to wrap the line before and after into a nice `oxc_diagnostic` Error
167+ ""
168+ } else if let Some ( source_text) = source_text_map. get ( & path)
169+ {
170+ source_text. as_str ( )
171+ } else {
172+ let source_text = read_to_string ( & path)
173+ . unwrap_or_else ( |_| String :: new ( ) ) ;
174+ // Insert and get a reference to the inserted string
175+ let entry = source_text_map
176+ . entry ( path. clone ( ) )
177+ . or_insert ( source_text) ;
178+ entry. as_str ( )
179+ } ;
162180
163181 let diagnostics = DiagnosticService :: wrap_diagnostics (
164182 cwd_clone. clone ( ) ,
0 commit comments