From 3523e5db0f1d3fe941f9d4a042c1db5e78891d3a Mon Sep 17 00:00:00 2001 From: Declan Vong Date: Thu, 7 Oct 2021 20:23:05 +1100 Subject: [PATCH] update to dprint-core supporting rewrapping --- src/parsing/parser.rs | 9 ++----- .../class/ClassDeclaration_Header.txt | 7 +++--- .../ClassDeclaration_PreferHanging_True.txt | 9 ++++--- ...nterfaceDeclaration_PreferHanging_True.txt | 3 +-- .../ConditionalExpression_All.txt | 4 +--- tests/specs/issues/issue0052.txt | 24 +++++++++++++++++++ tests/specs/issues/old-repo/issue035.txt | 7 +++--- .../old-repo/issue035_PreferSingleLine.txt | 7 +++--- .../ArrayPattern_PreferHanging_True.txt | 9 +++---- ...ayPattern_TrailingCommas_OnlyMultiLine.txt | 10 ++++---- 10 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 tests/specs/issues/issue0052.txt diff --git a/src/parsing/parser.rs b/src/parsing/parser.rs index b6280e0a..3590cfc6 100644 --- a/src/parsing/parser.rs +++ b/src/parsing/parser.rs @@ -6918,13 +6918,8 @@ fn parse_extends_or_implements<'a>(opts: ParseExtendsOrImplementsOptions<'a>, co return items; } - items.push_condition(conditions::new_line_if_hanging_space_otherwise( - conditions::NewLineIfHangingSpaceOtherwiseOptions { - start_info: opts.start_header_info, - end_info: None, - space_char: Some(conditions::if_above_width_or(context.config.indent_width, Signal::SpaceOrNewLine.into(), " ".into()).into()), - }, - )); + items.push_signal(Signal::PossibleNewLine); + items.push_condition(conditions::space_if_not_start_of_line(Some(" ".into()))); // the newline group will force it to put the extends or implements on a new line items.push_condition(conditions::indent_if_start_of_line(parser_helpers::new_line_group({ let mut items = PrintItems::new(); diff --git a/tests/specs/declarations/class/ClassDeclaration_Header.txt b/tests/specs/declarations/class/ClassDeclaration_Header.txt index ac7a5c3c..335abf6f 100644 --- a/tests/specs/declarations/class/ClassDeclaration_Header.txt +++ b/tests/specs/declarations/class/ClassDeclaration_Header.txt @@ -102,10 +102,9 @@ export class Test implements Testing, ThisOutABitHere +export class Test implements + Testing, + ThisOutABitHere { } diff --git a/tests/specs/declarations/class/ClassDeclaration_PreferHanging_True.txt b/tests/specs/declarations/class/ClassDeclaration_PreferHanging_True.txt index ae8578f0..7779d8bc 100644 --- a/tests/specs/declarations/class/ClassDeclaration_PreferHanging_True.txt +++ b/tests/specs/declarations/class/ClassDeclaration_PreferHanging_True.txt @@ -27,8 +27,7 @@ export class Test extends Test [expect] export class Test - extends Test - implements Other + extends Test implements Other { } @@ -63,9 +62,9 @@ export class Test implements Testing, ThisOutABitHere +export class Test implements + Testing, + ThisOutABitHere { } diff --git a/tests/specs/declarations/interface/InterfaceDeclaration_PreferHanging_True.txt b/tests/specs/declarations/interface/InterfaceDeclaration_PreferHanging_True.txt index 17a21a94..146fb8e2 100644 --- a/tests/specs/declarations/interface/InterfaceDeclaration_PreferHanging_True.txt +++ b/tests/specs/declarations/interface/InterfaceDeclaration_PreferHanging_True.txt @@ -44,8 +44,7 @@ export interface Test extends T [expect] export interface Test - extends Test + TypeParameterList> extends Test { } diff --git a/tests/specs/expressions/ConditionalExpression/ConditionalExpression_All.txt b/tests/specs/expressions/ConditionalExpression/ConditionalExpression_All.txt index c81f6733..97a2fa12 100644 --- a/tests/specs/expressions/ConditionalExpression/ConditionalExpression_All.txt +++ b/tests/specs/expressions/ConditionalExpression/ConditionalExpression_All.txt @@ -59,9 +59,7 @@ test test ? 1 : test ? 3 : 466666666666666666666; [expect] -test - ? 1 - : test +test ? 1 : test ? 3 : 466666666666666666666; diff --git a/tests/specs/issues/issue0052.txt b/tests/specs/issues/issue0052.txt new file mode 100644 index 00000000..d236e51f --- /dev/null +++ b/tests/specs/issues/issue0052.txt @@ -0,0 +1,24 @@ +~~ lineWidth: 40 ~~ +== avoids orphaning "extends" on its own line == +export interface Preview extends Pick { + approximate_member_count: number; + approximate_presence_count: number; +} + +[expect] +export interface Preview extends + Pick< + BaseGuild, + | "id" + | "name" + | "icon" + | "splash" + | "discovery_splash" + | "emojis" + | "features" + | "description" + > +{ + approximate_member_count: number; + approximate_presence_count: number; +} diff --git a/tests/specs/issues/old-repo/issue035.txt b/tests/specs/issues/old-repo/issue035.txt index 3bc0c318..23905d31 100644 --- a/tests/specs/issues/old-repo/issue035.txt +++ b/tests/specs/issues/old-repo/issue035.txt @@ -5,7 +5,6 @@ t(u, tbdstdddddbbSftt ? dddddmdd : testt); [expect] // skip format twice because preferSingleLine is false -t(u, - tbdstdddddbbSftt - ? dddddmdd - : testt); +t(u, tbdstdddddbbSftt + ? dddddmdd + : testt); diff --git a/tests/specs/issues/old-repo/issue035_PreferSingleLine.txt b/tests/specs/issues/old-repo/issue035_PreferSingleLine.txt index c3c65c14..34c25eb7 100644 --- a/tests/specs/issues/old-repo/issue035_PreferSingleLine.txt +++ b/tests/specs/issues/old-repo/issue035_PreferSingleLine.txt @@ -3,7 +3,6 @@ t(u, tbdstdddddbbSftt ? dddddmdd : testt); [expect] -t(u, - tbdstdddddbbSftt - ? dddddmdd - : testt); +t(u, tbdstdddddbbSftt + ? dddddmdd + : testt); diff --git a/tests/specs/patterns/ArrayPattern/ArrayPattern_PreferHanging_True.txt b/tests/specs/patterns/ArrayPattern/ArrayPattern_PreferHanging_True.txt index b173302f..ea7aa466 100644 --- a/tests/specs/patterns/ArrayPattern/ArrayPattern_PreferHanging_True.txt +++ b/tests/specs/patterns/ArrayPattern/ArrayPattern_PreferHanging_True.txt @@ -4,8 +4,9 @@ function t([testing, thisOutWhere, itGoesOverTheLineWidth]) { } [expect] -function t( - [testing, thisOutWhere, - itGoesOverTheLineWidth], -) { +function t([ + testing, + thisOutWhere, + itGoesOverTheLineWidth, +]) { } diff --git a/tests/specs/patterns/ArrayPattern/ArrayPattern_TrailingCommas_OnlyMultiLine.txt b/tests/specs/patterns/ArrayPattern/ArrayPattern_TrailingCommas_OnlyMultiLine.txt index 55063b80..01095695 100644 --- a/tests/specs/patterns/ArrayPattern/ArrayPattern_TrailingCommas_OnlyMultiLine.txt +++ b/tests/specs/patterns/ArrayPattern/ArrayPattern_TrailingCommas_OnlyMultiLine.txt @@ -26,10 +26,8 @@ function test([testingThisOut, withSomeTextThatWillMakeIt]) { } [expect] -function test( - [ - testingThisOut, - withSomeTextThatWillMakeIt, - ], -) { +function test([ + testingThisOut, + withSomeTextThatWillMakeIt, +]) { }