Skip to content

Commit c4f2aa5

Browse files
committed
refactor(comment): Improve logic readability
1 parent d377a92 commit c4f2aa5

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

Diff for: src/comment.rs

+28-18
Original file line numberDiff line numberDiff line change
@@ -364,24 +364,34 @@ fn identify_comment(
364364
let (first_group, rest) = orig.split_at(first_group_ending);
365365

366366
let is_doc_comment_with_our_determination = is_doc_comment || style.is_doc_comment();
367-
let rewritten_first_group =
368-
if !config.normalize_comments() && has_bare_lines && style.is_block_comment() {
369-
trim_left_preserve_layout(first_group, shape.indent, config)?
370-
} else if !config.normalize_comments()
371-
&& !config.wrap_comments()
372-
&& (!config.format_code_in_doc_comments() || !is_doc_comment_with_our_determination)
373-
{
374-
light_rewrite_comment(first_group, shape.indent, config, is_doc_comment)
375-
} else {
376-
rewrite_comment_inner(
377-
first_group,
378-
block_style,
379-
style,
380-
shape,
381-
config,
382-
is_doc_comment_with_our_determination,
383-
)?
384-
};
367+
368+
let should_trim_left_preserve_layout =
369+
{ !config.normalize_comments() && has_bare_lines && style.is_block_comment() };
370+
371+
let should_not_just_lightly_rewrite_comment = {
372+
config.normalize_comments()
373+
|| config.wrap_comments()
374+
|| (
375+
// `format_code_in_doc_comments` should only take effect on doc comments,
376+
// so we only consider it when this comment block is a doc comment block.
377+
is_doc_comment_with_our_determination && config.format_code_in_doc_comments()
378+
)
379+
};
380+
381+
let rewritten_first_group = if should_trim_left_preserve_layout {
382+
trim_left_preserve_layout(first_group, shape.indent, config)?
383+
} else if !should_not_just_lightly_rewrite_comment {
384+
light_rewrite_comment(first_group, shape.indent, config, is_doc_comment)
385+
} else {
386+
rewrite_comment_inner(
387+
first_group,
388+
block_style,
389+
style,
390+
shape,
391+
config,
392+
is_doc_comment_with_our_determination,
393+
)?
394+
};
385395
if rest.is_empty() {
386396
Some(rewritten_first_group)
387397
} else {

0 commit comments

Comments
 (0)