Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
faultyserver committed Nov 19, 2023
1 parent c4c905c commit ffa37b8
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions crates/biome_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,16 @@ pub const fn space() -> Space {
/// use biome_formatter::prelude::*;
///
/// # fn main() -> FormatResult<()> {
/// let elements = format!(SimpleFormatContext::default(), [text("a"), conditional_space(true), text("b")])?;
/// let nospace = format!(SimpleFormatContext::default(), [text("a"), conditional_space(false), text("b")])?;
/// let elements = format!(SimpleFormatContext::default(), [text("a"), maybe_space(true), text("b")])?;
/// let nospace = format!(SimpleFormatContext::default(), [text("a"), maybe_space(false), text("b")])?;
///
/// assert_eq!("a b", elements.print()?.as_code());
/// assert_eq!("ab", nospace.print()?.as_code());
/// # Ok(())
/// # }
/// ```
#[inline]
pub fn conditional_space(should_insert: bool) -> Option<Space> {
pub fn maybe_space(should_insert: bool) -> Option<Space> {
if should_insert {
Some(Space)
} else {
Expand Down Expand Up @@ -1094,7 +1094,7 @@ pub fn soft_block_indent<Context>(content: &impl Format<Context>) -> BlockIndent
/// let elements = format!(context, [
/// group(&format_args![
/// text("{"),
/// soft_block_indent_with_conditional_space(&format_args![
/// soft_block_indent_with_maybe_space(&format_args![
/// text("aPropertyThatExceeds"),
/// text(":"),
/// space(),
Expand Down Expand Up @@ -1122,7 +1122,7 @@ pub fn soft_block_indent<Context>(content: &impl Format<Context>) -> BlockIndent
/// let elements = format!(SimpleFormatContext::default(), [
/// group(&format_args![
/// text("{"),
/// soft_block_indent_with_conditional_space(&format_args![
/// soft_block_indent_with_maybe_space(&format_args![
/// text("a"),
/// text(":"),
/// space(),
Expand All @@ -1149,7 +1149,7 @@ pub fn soft_block_indent<Context>(content: &impl Format<Context>) -> BlockIndent
/// let elements = format!(SimpleFormatContext::default(), [
/// group(&format_args![
/// text("{"),
/// soft_block_indent_with_conditional_space(&format_args![
/// soft_block_indent_with_maybe_space(&format_args![
/// text("a"),
/// text(":"),
/// space(),
Expand All @@ -1166,7 +1166,7 @@ pub fn soft_block_indent<Context>(content: &impl Format<Context>) -> BlockIndent
/// # Ok(())
/// # }
/// ```
pub fn soft_block_indent_with_conditional_space<Context>(
pub fn soft_block_indent_with_maybe_space<Context>(
content: &impl Format<Context>,
should_add_space: bool,
) -> BlockIndent<Context> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl FormatNodeRule<JsExportNamedClause> for FormatJsExportNamedClause {
let should_insert_space_around_brackets = f.options().bracket_spacing().value();
write!(
f,
[group(&soft_block_indent_with_conditional_space(
[group(&soft_block_indent_with_maybe_space(
&specifiers.format(),
should_insert_space_around_brackets
),)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl FormatNodeRule<JsExportNamedFromClause> for FormatJsExportNamedFromClause {
write!(
f,
[
conditional_space(should_insert_space_around_brackets),
maybe_space(should_insert_space_around_brackets),
node.format()
]
)?;
Expand All @@ -46,15 +46,15 @@ impl FormatNodeRule<JsExportNamedFromClause> for FormatJsExportNamedFromClause {
write!(f, [format_removed(&separator)])?;
}

write!(f, [conditional_space(should_insert_space_around_brackets)])?;
write!(f, [maybe_space(should_insert_space_around_brackets)])?;
}
_ => {
if specifiers.syntax().has_leading_newline() {
write!(f, [block_indent(&specifiers.format()),])?;
} else {
write!(
f,
[group(&soft_block_indent_with_conditional_space(
[group(&soft_block_indent_with_maybe_space(
&specifiers.format(),
should_insert_space_around_brackets
)),]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl FormatNodeRule<JsImportAssertion> for FormatJsImportAssertion {
assertion_kind.format(),
space(),
l_curly_token.format(),
group(&soft_block_indent_with_conditional_space(
group(&soft_block_indent_with_maybe_space(
&assertions.format(),
should_insert_space_around_brackets
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl FormatNodeRule<JsImportNamedClause> for FormatJsImportNamedClause {
f,
[
l_curly_token.format(),
conditional_space(should_insert_space_around_brackets),
maybe_space(should_insert_space_around_brackets),
specifier.format(),
]
)?;
Expand All @@ -91,7 +91,7 @@ impl FormatNodeRule<JsImportNamedClause> for FormatJsImportNamedClause {
write!(
f,
[
conditional_space(should_insert_space_around_brackets),
maybe_space(should_insert_space_around_brackets),
r_curly_token.format()
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl FormatNodeRule<JsNamedImportSpecifiers> for FormatJsNamedImportSpecifiers {
let should_insert_space_around_brackets = f.options().bracket_spacing().value();
write!(
f,
[group(&soft_block_indent_with_conditional_space(
[group(&soft_block_indent_with_maybe_space(
&specifiers.format(),
should_insert_space_around_brackets
))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl FormatNodeRule<TsPropertySignatureTypeMember> for FormatTsPropertySignature
f,
[
readonly_token.format(),
conditional_space(readonly_token.is_some()),
maybe_space(readonly_token.is_some()),
name.format(),
optional_token.format(),
type_annotation.format(),
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_formatter/src/ts/types/mapped_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl FormatNodeRule<TsMappedType> for FormatTsMappedType {
f,
[
&l_curly_token.format(),
group(&soft_block_indent_with_conditional_space(
group(&soft_block_indent_with_maybe_space(
&format_inner,
should_insert_space_around_brackets
))
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_formatter/src/utils/object_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Format<JsFormatContext> for JsObjectLike {
let should_expand = self.members_have_leading_newline();
write!(
f,
[group(&soft_block_indent_with_conditional_space(
[group(&soft_block_indent_with_maybe_space(
&members,
should_insert_space_around_brackets
))
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_formatter/src/utils/object_pattern_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Format<JsFormatContext> for JsObjectPatternLike {
let format_properties = format_with(|f| {
write!(
f,
[soft_block_indent_with_conditional_space(
[soft_block_indent_with_maybe_space(
&format_with(|f| self.write_properties(f)),
should_insert_space_around_brackets
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct JavascriptFormatter {
#[serde(skip_serializing_if = "Option::is_none")]
pub arrow_parentheses: Option<ArrowParentheses>,
/// Whether to insert spaces around brackets in object literals. Defaults to true.
#[bpaf(long("bracket-spacing"), argument("BOOLEAN"), optional)]
#[bpaf(long("bracket-spacing"), argument("true|false"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
pub bracket_spacing: Option<bool>,

Expand Down

0 comments on commit ffa37b8

Please sign in to comment.