Commit Graph

8 Commits

Author SHA1 Message Date
Sysix 9cee146886 fix(oxlint/lsp): don't try to parse fix message, always fallback (#26204)
We had at the beginning some rules' diagnostics like `<rule-name>: diagnostic message`, from that message we did create a code action `Fix this <rule-name> problem`, but this is buggy.
I searched in `crates/oxc_linter` for `OxcDiagnostic::\w+\(".*:` and found only `no-invalid-regexp` to be a useful case.
For other rules this could be wrong like:
- Unexpected `javascript:` url
- `<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: https:/..`
- Always prefer `const x: T = { ... }`.
2026-09-02 19:28:32 +00:00
Norcleeh a92c5410a1 fix(linter): preserve source text for JS plugin ignore fixes (#25280)
Closes #25278

## Overview

This PR resolves an oxlint language server crash that could occur when
requesting code actions for diagnostics reported by JS plugins,
particularly when the diagnostic appears after the beginning of a file.

JS plugin diagnostics can now safely provide regular fixes as well as
line-level and file-level disable actions.

## Root cause

1. In `run_external_rules()`, the `semantic` is being taken to run the
external JS plugin rules, leaving the former `semantic` inside the
context host empty:

https://github.com/oxc-project/oxc/blob/e23dccf338d568ac0c2be3b1223f213c797923f7/crates/oxc_linter/src/lib.rs#L539
2. The language server enables `with_ignore_fixes` to generate ignore
fixes, but inside the `add_ignore_fix()`, it doesn't check the
`section_source_text`.
3. The context host with the empty `semantic` passes the empty source
text to the `add_ignore_fix()` as `section_source_text`, and the empty
string just causes the crash.

https://github.com/oxc-project/oxc/blob/e23dccf338d568ac0c2be3b1223f213c797923f7/crates/oxc_linter/src/context/host.rs#L329-L334

## What changed

A new property `source_text` is added to the context sub host, which
stores a reference to the real source text string. Even if the
`semantic` is taken and becomes empty, the reference can still get the
real string and make things work.

```diff
pub struct ContextSubHost<'a> {
    /// Semantic information about the file being linted, which includes scopes, symbols and AST nodes.
    /// See [`Semantic`].
    pub(super) semantic: Semantic<'a>,
    // ...
+   /// Stable source text for this script section
+   /// which remains available even after `semantic` is taken while running JS plugins.
+   pub(super) source_text: &'a str,
    /// The source text offset of the sub host
    pub(super) source_text_offset: u32,
}
```

And I added a new utility method to get the `source_text` from the
context sub host.
```rs
#[inline]
pub fn source_text(&self) -> &'a str {
    self.current_sub_host().source_text()
}
```

When passing source text to `add_ignore_fix()`, just use the new
`source_text()` method.
```diff
if self.with_ignore_fixes {
-   let source_text = self.semantic().source_text();
+   let source_text = self.source_text();
    for diagnostic in &mut diagnostics {
        diagnostic.add_ignore_fix(self.current_sub_host().source_text_offset, source_text);
    }
}
// (the same as other occurs
```

Also, I added the necessary check for the `section_source_text` in
`add_ignore_fix()`.

## Notes

This is my first contribution to oxc project. Thanks for reviewing!
2026-08-09 14:42:57 +01:00
Sysix 00ce51276b fix(oxlint/lsp)!: don't fix suggestions on fixAll code actions & command (#22195)
Our LSP integration has a "big" problem with the suggestions. `no-console` is a suggestion and should not be fixed on `source.fixAll.*` auto save fix.

This will align how ESLint LSP is working in VS Code, suggestions are only displayed in the quick fix menu, but not automatically applied.

- closes https://github.com/oxc-project/oxc/issues/22191
- closes https://github.com/oxc-project/oxc/issues/22174

<img width="786" height="115" alt="https://eslint.org/docs/latest/rules/no-console" src="https://github.com/user-attachments/assets/acef08d5-0222-448a-8474-feae9704ed09" />

_https://eslint.org/docs/latest/rules/no-console_
2026-05-09 10:35:53 +00:00
Sysix 080d90ed6a fix(linter): move no-debugger fix to suggestion (#22256)
`console.log` and `debugger;` are utils while developing.
`console.log` is already a suggestion (aligned with ESLint), but `no-debugger` would be autofixed too.
ESLint does not have a fixer for his rule, but we do.

This is a part of #22195, where do not autofix suggestions on the editor side, aligning with ESLint.
`debugger;` should not be autofixed on save.
2026-05-09 10:20:33 +00:00
Sysix 5a4414d0fa feat(oxlint/lsp): support rulesCustomization lsp option (#21858)
> Adds support for an LSP workspace option (`rulesCustomization`) that lets clients customize rule severity and control whether specific rules participate in “fix all” code actions.

related https://github.com/oxc-project/oxc-vscode/issues/22
closes https://github.com/oxc-project/oxc/issues/21538
2026-05-05 09:57:06 +00:00
Sysix c731a8b769 test(oxlint/lsp): add tests for code action "only" context (#21958) 2026-04-29 20:41:28 +00:00
Sysix 22ce6aff68 feat(oxlint/lsp)!: show/fix safe suggestions by default (#19816)
ESLint shows by default suggestions in the editor. We did not have the right architecture to difference between safe or dangerous fix / suggestions. With https://github.com/oxc-project/oxc/pull/19113 we know now what kind of fix this is.
This allows us now to align more with the ESLint editor experience. The last found tech dep was https://github.com/oxc-project/oxc/pull/19795.
This will not apply for editors which manage its own configurations like VS Code editor and IntelliJ Plugin (cc @nrayburn-tech). These editors need their own default value changed.

When using auto save `source.fixAll.oxc` or `source.fixAll` code action, or the `oxc.fixAll` command, the suggestions will be applied too. Because this is always in a context of one file only, I guess this is safe. Or we can change the line for this: https://github.com/oxc-project/oxc/blob/a45b9f4f808e4761ee615c31ea32bccfad322602/apps/oxlint/src/lsp/code_actions.rs#L96-L100
2026-03-30 19:06:36 +00:00
Sysix 87a6724f16 test(oxlint/lsp): add simple code actions tests (#19010) 2026-02-11 23:21:18 +00:00