From 6b5ac5c7659e39717a525c3858f269875ab98665 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Mon, 13 Mar 2017 07:10:18 +0000 Subject: [PATCH] clang-format: [JS] do not wrap after interface and type. Summary: `interface` and `type` are pseudo keywords and cause automatic semicolon insertion when followed by a line break: interface // gets parsed as a long variable access to "interface" VeryLongInterfaceName { } With this change, clang-format not longer wraps after `interface` or `type`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30874 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297605 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 9 ++++----- unittests/Format/FormatTestJS.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c529f1e4a6..0111aea52e 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2526,11 +2526,10 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { const FormatToken *NonComment = Right.getPreviousNonComment(); - if (Left.isOneOf(tok::kw_return, tok::kw_continue, tok::kw_break, - tok::kw_throw) || - (NonComment && - NonComment->isOneOf(tok::kw_return, tok::kw_continue, tok::kw_break, - tok::kw_throw))) + if (NonComment && + NonComment->isOneOf(tok::kw_return, tok::kw_continue, tok::kw_break, + tok::kw_throw, Keywords.kw_interface, + Keywords.kw_type)) return false; // Otherwise a semicolon is inserted. if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace)) return false; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 23253cc2d6..f08446734c 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1228,6 +1228,20 @@ TEST_F(FormatTestJS, TypeAliases) { "class C {}"); } +TEST_F(FormatTestJS, TypeInterfaceLineWrapping) { + const FormatStyle &Style = getGoogleJSStyleWithColumns(20); + verifyFormat("type LongTypeIsReallyUnreasonablyLong =\n" + " string;\n", + "type LongTypeIsReallyUnreasonablyLong = string;\n", + Style); + verifyFormat( + "interface AbstractStrategyFactoryProvider {\n" + " a: number\n" + "}\n", + "interface AbstractStrategyFactoryProvider { a: number }\n", + Style); +} + TEST_F(FormatTestJS, Modules) { verifyFormat("import SomeThing from 'some/module.js';"); verifyFormat("import {X, Y} from 'some/module.js';"); -- 2.40.0