Skip to content
Merged
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: 8 additions & 26 deletions crates/oxc_linter/src/rules/typescript/prefer_function_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use oxc_ast::{
AstKind, CommentKind,
AstKind,
ast::{ExportDefaultDeclarationKind, Expression, TSInterfaceDeclaration, TSSignature, TSType},
};
use oxc_diagnostics::OxcDiagnostic;
Expand Down Expand Up @@ -157,32 +157,14 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
node_end = export_name_decl.span.end;
}

let has_comments = ctx.has_comments_between(interface_decl.span);

if has_comments {
let comments = ctx
.comments_range(node_start..node_end)
.map(|comment| (*comment, comment.content_span()));

let comments_text = {
let mut comments_vec: Vec<String> = vec![];
comments.for_each(|(comment_interface, span)| {
let comment = span.source_text(source_code);

match comment_interface.kind {
CommentKind::Line => {
let single_line_comment: String = format!("//{comment}\n");
comments_vec.push(single_line_comment);
}
CommentKind::SingleLineBlock | CommentKind::MultiLineBlock => {
let multi_line_comment: String = format!("/*{comment}*/\n");
comments_vec.push(multi_line_comment);
}
}
});
let mut comments = ctx.comments_range(node_start..node_end).peekable();
if comments.peek().is_some() {
let mut comments_text = String::new();

comments_vec.join("")
};
for comment in comments {
comments_text.push_str(comment.span.source_text(source_code));
comments_text.push('\n');
}

return Fix::new(
format!(
Expand Down
Loading