Skip to content
Merged
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
17 changes: 16 additions & 1 deletion crates/oxc_linter/src/tsgolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,11 @@ fn parse_single_message(
/// Tries to find the `tsgolint` executable. In priority order, this will check:
/// 1. The `OXLINT_TSGOLINT_PATH` environment variable.
/// 2. The `tsgolint` binary in the current working directory's `node_modules/.bin` directory.
/// 3. The `tsgolint` binary in the system PATH.
///
/// # Errors
/// Returns an error if `OXLINT_TSGOLINT_PATH` is set but does not exist or is not a file.
/// Returns an error if the tsgolint executable could not be resolve inside `node_modules/.bin`.
/// Returns an error if the tsgolint executable could not be found.
pub fn try_find_tsgolint_executable(cwd: &Path) -> Result<PathBuf, String> {
// Check the environment variable first
if let Ok(path_str) = std::env::var("OXLINT_TSGOLINT_PATH") {
Expand Down Expand Up @@ -848,6 +849,20 @@ pub fn try_find_tsgolint_executable(cwd: &Path) -> Result<PathBuf, String> {
}
}

// Finally, search in the system PATH
// This supports package managers that install binaries globally and make them
// available via PATH
if let Ok(path_env) = std::env::var("PATH") {
for dir in std::env::split_paths(&path_env) {
for file in files {
let candidate = dir.join(file);
if candidate.is_file() {
return Ok(candidate);
}
}
}
}

Err("Failed to find tsgolint executable".to_string())
}

Expand Down
Loading