Skip to content

Commit 8459a12

Browse files
committed
refactor(linter): pass paths to TsGoLintState.lint method (#13131)
The language server does need to hold all paths. It will lint when the client is requesting a file
1 parent 0dd7908 commit 8459a12

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

apps/oxlint/src/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ impl LintRunner {
304304
// Run type-aware linting through tsgolint
305305
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
306306
if self.options.type_aware {
307-
if let Err(err) = TsGoLintState::new(options.cwd(), config_store.clone(), &paths)
308-
.lint(tx_error.clone())
307+
if let Err(err) = TsGoLintState::new(options.cwd(), config_store.clone())
308+
.lint(&paths, tx_error.clone())
309309
{
310310
print_and_flush_stdout(stdout, &err);
311311
return CliRunResult::TsGoLintError;

crates/oxc_linter/src/tsgolint.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@ use super::{AllowWarnDeny, ConfigStore, ResolvedLinterState, read_to_string};
1515

1616
/// State required to initialize the `tsgolint` linter.
1717
#[derive(Debug, Clone)]
18-
pub struct TsGoLintState<'a> {
18+
pub struct TsGoLintState {
1919
/// The path to the `tsgolint` executable (at least our our best guess at it).
2020
executable_path: PathBuf,
2121
/// Current working directory, used for rendering paths in diagnostics.
2222
cwd: PathBuf,
23-
/// The paths of files to lint
24-
paths: &'a Vec<Arc<OsStr>>,
2523
/// The configuration store for `tsgolint` (used to resolve configurations outside of `oxc_linter`)
2624
config_store: ConfigStore,
2725
}
2826

29-
impl<'a> TsGoLintState<'a> {
30-
pub fn new(cwd: &Path, config_store: ConfigStore, paths: &'a Vec<Arc<OsStr>>) -> Self {
27+
impl TsGoLintState {
28+
pub fn new(cwd: &Path, config_store: ConfigStore) -> Self {
3129
TsGoLintState {
3230
config_store,
3331
executable_path: try_find_tsgolint_executable(cwd).unwrap_or(PathBuf::from("tsgolint")),
3432
cwd: cwd.to_path_buf(),
35-
paths,
3633
}
3734
}
3835

@@ -43,14 +40,14 @@ impl<'a> TsGoLintState<'a> {
4340
///
4441
/// # Errors
4542
/// A human-readable error message indicating why the linting failed.
46-
pub fn lint(self, error_sender: DiagnosticSender) -> Result<(), String> {
47-
if self.paths.is_empty() {
43+
pub fn lint(self, paths: &[Arc<OsStr>], error_sender: DiagnosticSender) -> Result<(), String> {
44+
if paths.is_empty() {
4845
return Ok(());
4946
}
5047

5148
let mut resolved_configs: FxHashMap<PathBuf, ResolvedLinterState> = FxHashMap::default();
5249

53-
let json_input = self.json_input(&mut resolved_configs);
50+
let json_input = self.json_input(paths, &mut resolved_configs);
5451

5552
let handler = std::thread::spawn(move || {
5653
let child = std::process::Command::new(&self.executable_path)
@@ -226,11 +223,11 @@ impl<'a> TsGoLintState<'a> {
226223
#[inline]
227224
fn json_input(
228225
&self,
226+
paths: &[Arc<OsStr>],
229227
resolved_configs: &mut FxHashMap<PathBuf, ResolvedLinterState>,
230228
) -> TsGoLintInput {
231229
TsGoLintInput {
232-
files: self
233-
.paths
230+
files: paths
234231
.iter()
235232
.filter(|path| SourceType::from_path(Path::new(path)).is_ok())
236233
.map(|path| TsGoLintInputFile {

0 commit comments

Comments
 (0)