Skip to content

Commit 2652def

Browse files
committed
feat(linter): add fixer for
@typescript-eslint/consistent-type-imports
1 parent c3f08ce commit 2652def

File tree

2 files changed

+1810
-1086
lines changed

2 files changed

+1810
-1086
lines changed

crates/oxc_linter/src/fixer.rs

+34
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,40 @@ impl<'c, 'a: 'c> RuleFixer<'c, 'a> {
148148
Fix::new(replacement, target)
149149
}
150150

151+
/// Creates a fix command that inserts text before the given node.
152+
pub fn insert_text_before<T: GetSpan, S: Into<Cow<'a, str>>>(
153+
self,
154+
target: &T,
155+
text: S,
156+
) -> Fix<'a> {
157+
self.insert_text_before_range(target.span(), text)
158+
}
159+
160+
/// Creates a fix command that inserts text before the specified range in the source text.
161+
pub fn insert_text_before_range<S: Into<Cow<'a, str>>>(self, span: Span, text: S) -> Fix<'a> {
162+
self.insert_text_at(span.start, text)
163+
}
164+
165+
/// Creates a fix command that inserts text after the given node.
166+
pub fn insert_text_after<T: GetSpan, S: Into<Cow<'a, str>>>(
167+
self,
168+
target: &T,
169+
text: S,
170+
) -> Fix<'a> {
171+
self.insert_text_after_range(target.span(), text)
172+
}
173+
174+
/// Creates a fix command that inserts text after the specified range in the source text.
175+
pub fn insert_text_after_range<S: Into<Cow<'a, str>>>(self, span: Span, text: S) -> Fix<'a> {
176+
self.insert_text_at(span.end, text)
177+
}
178+
179+
/// Creates a fix command that inserts text at the specified index in the source text.
180+
#[allow(clippy::unused_self)]
181+
fn insert_text_at<S: Into<Cow<'a, str>>>(self, index: u32, text: S) -> Fix<'a> {
182+
Fix::new(text, Span::new(index, index))
183+
}
184+
151185
#[allow(clippy::unused_self)]
152186
pub fn codegen(self) -> Codegen<'a, false> {
153187
Codegen::<false>::new()

0 commit comments

Comments
 (0)