Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ impl LintRunner {
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
if self.options.type_aware {
if let Err(err) = TsGoLintState::new(options.cwd(), config_store.clone())
.with_silent(misc_options.silent)
.lint(&files_to_lint, tx_error.clone())
{
print_and_flush_stdout(stdout, &err);
Expand Down Expand Up @@ -1178,6 +1179,14 @@ mod test {
Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_tsgolint_silent() {
// TODO: test with other rules as well once diagnostics are more stable
let args = &["--type-aware", "--silent", "no-floating-promises"];
Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_tsgolint_config() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --type-aware --silent no-floating-promises
working directory: fixtures/tsgolint
----------

Found 5 warnings and 11 errors.
Finished in <variable>ms on 3 files using 1 threads.
----------
CLI result: LintFoundErrors
----------
42 changes: 30 additions & 12 deletions crates/oxc_linter/src/tsgolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct TsGoLintState {
cwd: PathBuf,
/// The configuration store for `tsgolint` (used to resolve configurations outside of `oxc_linter`)
config_store: ConfigStore,
/// If `oxlint` will output the diagnostics or not.
/// When `silent` is true, we do not need to access the file system for nice diagnostics messages.
silent: bool,
}

impl TsGoLintState {
Expand All @@ -32,9 +35,20 @@ impl TsGoLintState {
config_store,
executable_path: try_find_tsgolint_executable(cwd).unwrap_or(PathBuf::from("tsgolint")),
cwd: cwd.to_path_buf(),
silent: false,
}
}

/// Set to `true` to skip file system reads.
/// When `silent` is true, we do not need to access the file system for nice diagnostics messages.
///
/// Default is `false`.
#[must_use]
pub fn with_silent(mut self, yes: bool) -> Self {
self.silent = yes;
self
}

/// # Panics
/// - when `stdin` of subprocess cannot be opened
/// - when `stdout` of subprocess cannot be opened
Expand Down Expand Up @@ -147,18 +161,22 @@ impl TsGoLintState {
},
);

let source_text: &str =
if let Some(source_text) = source_text_map.get(&path) {
source_text.as_str()
} else {
let source_text = read_to_string(&path)
.unwrap_or_else(|_| String::new());
// Insert and get a reference to the inserted string
let entry = source_text_map
.entry(path.clone())
.or_insert(source_text);
entry.as_str()
};
let source_text: &str = if self.silent {
// The source text is not needed in silent mode.
// The source text is only here to wrap the line before and after into a nice `oxc_diagnostic` Error
""
} else if let Some(source_text) = source_text_map.get(&path)
{
source_text.as_str()
} else {
let source_text = read_to_string(&path)
.unwrap_or_else(|_| String::new());
// Insert and get a reference to the inserted string
let entry = source_text_map
.entry(path.clone())
.or_insert(source_text);
entry.as_str()
};

let diagnostics = DiagnosticService::wrap_diagnostics(
cwd_clone.clone(),
Expand Down
Loading