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

This rule's fixer is complicated, I do line by line copy as possible.

7b13dae347/packages/eslint-plugin/src/rules/consistent-type-imports.ts
This commit is contained in:
mysteryven 2024-07-11 04:48:04 +00:00
parent c8184723f4
commit 6c49007b27
2 changed files with 1810 additions and 1086 deletions

View file

@ -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()