Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Sep 25, 2024
1 parent 3052029 commit 0afb1a2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions crates/oxc_prettier/src/format/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use oxc_span::GetSpan;

use super::assignment::AssignmentLikeNode;
use crate::{
array, doc::{Doc, DocBuilder, Group, IfBreak, Line}, format::{assignment, Separator}, group, hardline, if_break, indent, indent_if_break, line, softline, space, ss, Format, Prettier,
array,
doc::{Doc, DocBuilder, Group, IfBreak, Line},
format::{assignment, Separator},
group, hardline, if_break, indent, indent_if_break, line, softline, space, ss, Format,
Prettier,
};

pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a> {
Expand All @@ -15,9 +19,10 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a

// Keep old behaviour of extends in same line
// If there is only on extends and there are not comments
// ToDo: implement comment checks
// ToDo: implement comment checks
// @link https://github.com/prettier/prettier/blob/aa3853b7765645b3f3d8a76e41cf6d70b93c01fd/src/language-js/print/class.js#L62
let group_mode = class.super_class.is_some() || class.implements.as_ref().map(|v| !v.is_empty()).unwrap_or(false);
let group_mode = class.super_class.is_some()
|| class.implements.as_ref().map(|v| !v.is_empty()).unwrap_or(false);

if let Some(params) = &class.type_parameters {
group_parts.push(params.format(p));
Expand All @@ -33,7 +38,7 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a
if let Some(super_type_parameters) = &class.super_type_parameters {
extend_parts.push(super_type_parameters.format(p));
}

if group_mode {
heritage_clauses_parts.push(group!(p, softline!(), Doc::Array(extend_parts)))
} else {
Expand Down Expand Up @@ -61,12 +66,12 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a
}

parts.push(ss!("class "));

if let Some(id) = &class.id {
parts.push(id.format(p));
parts.push(space!());
}

if group_mode {
let printend_parts_group = if should_indent_only_heritage_clauses(class) {
array!(p, Doc::Array(group_parts), indent!(p, Doc::Array(heritage_clauses_parts)))
Expand Down Expand Up @@ -382,17 +387,17 @@ fn print_heritage_clauses_implements<'a>(p: &mut Prettier<'a>, class: &Class<'a>
}

if should_indent_only_heritage_clauses(class) {
parts.push(Doc::IfBreak(IfBreak{
parts.push(Doc::IfBreak(IfBreak {
break_contents: p.boxed(ss!("")),
flat_content: p.boxed(softline!()),
group_id: None // ToDo - how to attach group id
group_id: None, // ToDo - how to attach group id
}));
} else {
parts.extend(hardline!());
}

parts.push(ss!("implements "));

let implements_docs = implements.iter().map(|v| v.format(p)).collect();

parts.push(indent!(p, group!(p, Doc::Array(p.join(Separator::CommaLine, implements_docs)))));
Expand Down

0 comments on commit 0afb1a2

Please sign in to comment.