Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2005,6 +2005,11 @@ if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || (Right.is(TT_TemplateString) && Right.TokenText.startswith("}"))) return 100; + // Prefer breaking call chains (".foo") over empty "{}", "[]" or "()". + if ((Left.is(tok::l_brace) && Right.is(tok::r_brace)) || + (Left.is(tok::l_square) && Right.is(tok::r_square)) || + (Left.is(tok::l_paren) && Right.is(tok::r_paren))) + return 200; } if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral)) Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -832,6 +832,15 @@ } +TEST_F(FormatTestJS, DontWrapEmptyLiterals) { + verifyFormat("(aaaaaaaaaaaaaaaaaaaaa.getData as jasmine.Spy)\n" + " .and.returnValue(Observable.of([]));"); + verifyFormat("(aaaaaaaaaaaaaaaaaaaaa.getData as jasmine.Spy)\n" + " .and.returnValue(Observable.of({}));"); + verifyFormat("(aaaaaaaaaaaaaaaaaaaaa.getData as jasmine.Spy)\n" + " .and.returnValue(Observable.of(()));"); +} + TEST_F(FormatTestJS, InliningFunctionLiterals) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;