Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linter): add fixer for @typescript-eslint/consistent-type-imports #3984

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions crates/oxc_linter/src/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ impl<'c, 'a: 'c> RuleFixer<'c, 'a> {
Fix::new(replacement, target)
}

/// Creates a fix command that inserts text before the given node.
pub fn insert_text_before<T: GetSpan, S: Into<Cow<'a, str>>>(
self,
target: &T,
text: S,
) -> Fix<'a> {
self.insert_text_before_range(target.span(), text)
}

/// Creates a fix command that inserts text before the specified range in the source text.
pub fn insert_text_before_range<S: Into<Cow<'a, str>>>(self, span: Span, text: S) -> Fix<'a> {
self.insert_text_at(span.start, text)
}

/// Creates a fix command that inserts text after the given node.
pub fn insert_text_after<T: GetSpan, S: Into<Cow<'a, str>>>(
self,
target: &T,
text: S,
) -> Fix<'a> {
self.insert_text_after_range(target.span(), text)
}

/// Creates a fix command that inserts text after the specified range in the source text.
pub fn insert_text_after_range<S: Into<Cow<'a, str>>>(self, span: Span, text: S) -> Fix<'a> {
self.insert_text_at(span.end, text)
}

/// Creates a fix command that inserts text at the specified index in the source text.
#[allow(clippy::unused_self)]
fn insert_text_at<S: Into<Cow<'a, str>>>(self, index: u32, text: S) -> Fix<'a> {
Fix::new(text, Span::new(index, index))
}

#[allow(clippy::unused_self)]
pub fn codegen(self) -> Codegen<'a, false> {
Codegen::<false>::new()
Expand Down
Loading
Loading