diff --git a/apps/oxlint/src/lsp/isolated_lint_handler.rs b/apps/oxlint/src/lsp/isolated_lint_handler.rs index 9456c2833d84a..3e66a075a5cc5 100644 --- a/apps/oxlint/src/lsp/isolated_lint_handler.rs +++ b/apps/oxlint/src/lsp/isolated_lint_handler.rs @@ -153,6 +153,10 @@ impl IsolatedLintHandler { ); } + // Clear any stale directives because they are no longer needed. + // This prevents using outdated directive spans if the new linting run fails. + self.runner.directives_coordinator().remove(path); + Ok(messages) } diff --git a/crates/oxc_linter/src/lint_runner.rs b/crates/oxc_linter/src/lint_runner.rs index 35a6f7f1d8b12..9b454daa0b6ec 100644 --- a/crates/oxc_linter/src/lint_runner.rs +++ b/crates/oxc_linter/src/lint_runner.rs @@ -114,6 +114,18 @@ impl DirectivesStore { pub fn clear(&self) { self.map.lock().expect("DirectivesStore mutex poisoned in clear").clear(); } + + /// Remove disable directives for a specific file + /// + /// This should be called before re-linting a file to ensure stale directives + /// from previous linting runs are not used if the new linting run fails to + /// produce directives (e.g., due to parse errors). + /// + /// # Panics + /// Panics if the mutex is poisoned. + pub fn remove(&self, path: &Path) { + self.map.lock().expect("DirectivesStore mutex poisoned in remove").remove(path); + } } impl Default for DirectivesStore {