Skip to content

Commit 22ce6af

Browse files
committed
feat(oxlint/lsp)!: show/fix safe suggestions by default (oxc-project#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 oxc-project#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 oxc-project#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
1 parent 0f01fbd commit 22ce6af

7 files changed

Lines changed: 292 additions & 13 deletions

apps/oxlint/src/lsp/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub struct LintOptions {
3838
#[derive(Debug, Default, Serialize, PartialEq, Eq, Deserialize, Clone)]
3939
#[serde(rename_all = "snake_case")]
4040
pub enum LintFixKindFlag {
41-
#[default]
4241
SafeFix,
42+
#[default]
4343
SafeFixOrSuggestion,
4444
DangerousFix,
4545
DangerousFixOrSuggestion,
@@ -173,7 +173,7 @@ mod test {
173173
assert_eq!(options.unused_disable_directives, None);
174174
assert_eq!(options.type_aware, None);
175175
assert!(!options.disable_nested_config);
176-
assert_eq!(options.fix_kind, super::LintFixKindFlag::SafeFix);
176+
assert_eq!(options.fix_kind, super::LintFixKindFlag::SafeFixOrSuggestion);
177177
}
178178

179179
#[test]

apps/oxlint/src/lsp/snapshots/fixtures_lsp_deny_no_console@hello_world.js.snap

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ source: Some("oxc")
1919
tags: None
2020

2121
########### Code Actions/Commands
22+
CodeAction:
23+
Title: Delete this code.
24+
Is Preferred: Some(true)
25+
TextEdit: TextEdit {
26+
range: Range {
27+
start: Position {
28+
line: 0,
29+
character: 0,
30+
},
31+
end: Position {
32+
line: 0,
33+
character: 29,
34+
},
35+
},
36+
new_text: "",
37+
}
38+
39+
2240
CodeAction:
2341
Title: Disable no-console for this line
2442
Is Preferred: Some(false)
@@ -56,4 +74,19 @@ TextEdit: TextEdit {
5674

5775

5876
########### Fix All Action
59-
None
77+
CodeAction:
78+
Title: fix all safe fixable oxlint issues
79+
Is Preferred: Some(true)
80+
TextEdit: TextEdit {
81+
range: Range {
82+
start: Position {
83+
line: 0,
84+
character: 0,
85+
},
86+
end: Position {
87+
line: 0,
88+
character: 29,
89+
},
90+
},
91+
new_text: "",
92+
}

apps/oxlint/src/lsp/snapshots/fixtures_lsp_issue_9958@issue.ts.snap

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ source: Some("oxc")
4444
tags: None
4545

4646
########### Code Actions/Commands
47+
CodeAction:
48+
Title: Replace `!!x` with `x`.
49+
Is Preferred: Some(true)
50+
TextEdit: TextEdit {
51+
range: Range {
52+
start: Position {
53+
line: 3,
54+
character: 14,
55+
},
56+
end: Position {
57+
line: 3,
58+
character: 17,
59+
},
60+
},
61+
new_text: "x",
62+
}
63+
64+
4765
CodeAction:
4866
Title: Disable no-extra-boolean-cast for this line
4967
Is Preferred: Some(false)
@@ -80,6 +98,24 @@ TextEdit: TextEdit {
8098
}
8199

82100

101+
CodeAction:
102+
Title: Delete this code.
103+
Is Preferred: Some(true)
104+
TextEdit: TextEdit {
105+
range: Range {
106+
start: Position {
107+
line: 11,
108+
character: 21,
109+
},
110+
end: Position {
111+
line: 11,
112+
character: 22,
113+
},
114+
},
115+
new_text: "",
116+
}
117+
118+
83119
CodeAction:
84120
Title: Disable typescript/no-non-null-asserted-optional-chain for this line
85121
Is Preferred: Some(false)
@@ -117,4 +153,32 @@ TextEdit: TextEdit {
117153

118154

119155
########### Fix All Action
120-
None
156+
CodeAction:
157+
Title: fix all safe fixable oxlint issues
158+
Is Preferred: Some(true)
159+
TextEdit: TextEdit {
160+
range: Range {
161+
start: Position {
162+
line: 3,
163+
character: 14,
164+
},
165+
end: Position {
166+
line: 3,
167+
character: 17,
168+
},
169+
},
170+
new_text: "x",
171+
}
172+
TextEdit: TextEdit {
173+
range: Range {
174+
start: Position {
175+
line: 11,
176+
character: 21,
177+
},
178+
end: Position {
179+
line: 11,
180+
character: 22,
181+
},
182+
},
183+
new_text: "",
184+
}

apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint_type_aware_config@test.ts.snap

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,42 @@ TextEdit: TextEdit {
6666
}
6767

6868

69+
CodeAction:
70+
Title: Add void operator to ignore.
71+
Is Preferred: Some(true)
72+
TextEdit: TextEdit {
73+
range: Range {
74+
start: Position {
75+
line: 1,
76+
character: 0,
77+
},
78+
end: Position {
79+
line: 1,
80+
character: 0,
81+
},
82+
},
83+
new_text: "void ",
84+
}
85+
86+
87+
CodeAction:
88+
Title: Add await operator.
89+
Is Preferred: Some(false)
90+
TextEdit: TextEdit {
91+
range: Range {
92+
start: Position {
93+
line: 1,
94+
character: 0,
95+
},
96+
end: Position {
97+
line: 1,
98+
character: 0,
99+
},
100+
},
101+
new_text: "await ",
102+
}
103+
104+
69105
CodeAction:
70106
Title: Disable typescript/no-floating-promises for this line
71107
Is Preferred: Some(false)
@@ -103,4 +139,19 @@ TextEdit: TextEdit {
103139

104140

105141
########### Fix All Action
106-
None
142+
CodeAction:
143+
Title: fix all safe fixable oxlint issues
144+
Is Preferred: Some(true)
145+
TextEdit: TextEdit {
146+
range: Range {
147+
start: Position {
148+
line: 1,
149+
character: 0,
150+
},
151+
end: Position {
152+
line: 1,
153+
character: 0,
154+
},
155+
},
156+
new_text: "void ",
157+
}

apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint_unused_disabled_directives@test.ts.snap

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ source: Some("oxc")
3030
tags: None
3131

3232
########### Code Actions/Commands
33+
CodeAction:
34+
Title: Add void operator to ignore.
35+
Is Preferred: Some(true)
36+
TextEdit: TextEdit {
37+
range: Range {
38+
start: Position {
39+
line: 18,
40+
character: 0,
41+
},
42+
end: Position {
43+
line: 18,
44+
character: 0,
45+
},
46+
},
47+
new_text: "void ",
48+
}
49+
50+
51+
CodeAction:
52+
Title: Add await operator.
53+
Is Preferred: Some(false)
54+
TextEdit: TextEdit {
55+
range: Range {
56+
start: Position {
57+
line: 18,
58+
character: 0,
59+
},
60+
end: Position {
61+
line: 18,
62+
character: 0,
63+
},
64+
},
65+
new_text: "await ",
66+
}
67+
68+
3369
CodeAction:
3470
Title: Disable typescript/no-floating-promises for this line
3571
Is Preferred: Some(false)
@@ -66,6 +102,42 @@ TextEdit: TextEdit {
66102
}
67103

68104

105+
CodeAction:
106+
Title: Add void operator to ignore.
107+
Is Preferred: Some(true)
108+
TextEdit: TextEdit {
109+
range: Range {
110+
start: Position {
111+
line: 38,
112+
character: 0,
113+
},
114+
end: Position {
115+
line: 38,
116+
character: 0,
117+
},
118+
},
119+
new_text: "void ",
120+
}
121+
122+
123+
CodeAction:
124+
Title: Add await operator.
125+
Is Preferred: Some(false)
126+
TextEdit: TextEdit {
127+
range: Range {
128+
start: Position {
129+
line: 38,
130+
character: 0,
131+
},
132+
end: Position {
133+
line: 38,
134+
character: 0,
135+
},
136+
},
137+
new_text: "await ",
138+
}
139+
140+
69141
CodeAction:
70142
Title: Disable typescript/no-floating-promises for this line
71143
Is Preferred: Some(false)
@@ -103,4 +175,32 @@ TextEdit: TextEdit {
103175

104176

105177
########### Fix All Action
106-
None
178+
CodeAction:
179+
Title: fix all safe fixable oxlint issues
180+
Is Preferred: Some(true)
181+
TextEdit: TextEdit {
182+
range: Range {
183+
start: Position {
184+
line: 18,
185+
character: 0,
186+
},
187+
end: Position {
188+
line: 18,
189+
character: 0,
190+
},
191+
},
192+
new_text: "void ",
193+
}
194+
TextEdit: TextEdit {
195+
range: Range {
196+
start: Position {
197+
line: 38,
198+
character: 0,
199+
},
200+
end: Position {
201+
line: 38,
202+
character: 0,
203+
},
204+
},
205+
new_text: "void ",
206+
}

apps/oxlint/src/lsp/snapshots/fixtures_lsp_unused_disabled_directives@test.js.snap

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ source: Some("oxc")
5757
tags: None
5858

5959
########### Code Actions/Commands
60+
CodeAction:
61+
Title: Delete this code.
62+
Is Preferred: Some(true)
63+
TextEdit: TextEdit {
64+
range: Range {
65+
start: Position {
66+
line: 9,
67+
character: 0,
68+
},
69+
end: Position {
70+
line: 9,
71+
character: 29,
72+
},
73+
},
74+
new_text: "",
75+
}
76+
77+
6078
CodeAction:
6179
Title: Disable no-console for this line
6280
Is Preferred: Some(false)
@@ -205,6 +223,19 @@ TextEdit: TextEdit {
205223
CodeAction:
206224
Title: fix all safe fixable oxlint issues
207225
Is Preferred: Some(true)
226+
TextEdit: TextEdit {
227+
range: Range {
228+
start: Position {
229+
line: 9,
230+
character: 0,
231+
},
232+
end: Position {
233+
line: 9,
234+
character: 29,
235+
},
236+
},
237+
new_text: "",
238+
}
208239
TextEdit: TextEdit {
209240
range: Range {
210241
start: Position {

0 commit comments

Comments
 (0)