mprobst created this revision. mprobst added reviewers: djasper, klimek, cfe-commits. Herald added a subscriber: klimek.
`import ... from ...; // from //foo:bar` serves as the equivalent if an IWYU pragma. This change matches `// from //.*` style comments and never allows them to wrap, just like IWYU pragmas for C++. For the time being, it does not seem worth turning this into a configurable option. http://reviews.llvm.org/D18283 Files: lib/Format/ContinuationIndenter.cpp unittests/Format/FormatTestJS.cpp Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1188,5 +1188,15 @@ verifyFormat("var x = 'foo';", LeaveQuotes); } + +TEST_F(FormatTestJS, LocationComment) { + verifyFormat("import {\n" + " x\n" + "} from\n" + " 'asd'; // from //some/really/long/path/here", + "import {x} from 'asd'; // from //some/really/long/path/here", + getGoogleJSStyleWithColumns(25)); +} + } // end namespace tooling } // end namespace clang Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -1059,6 +1059,8 @@ return 0; } +static llvm::Regex JSImportLocationCommentRegex("^//[ \n\t]*from[ \n\t]+//"); + unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, LineState &State, bool DryRun) { @@ -1137,6 +1139,10 @@ if (!Style.ReflowComments || CommentPragmasRegex.match(Current.TokenText.substr(2))) return 0; + if (Style.Language == FormatStyle::LK_JavaScript && + JSImportLocationCommentRegex.match(Current.TokenText)) + return 0; + Token.reset(new BreakableLineComment(Current, State.Line->Level, StartColumn, /*InPPDirective=*/false, Encoding, Style));
Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1188,5 +1188,15 @@ verifyFormat("var x = 'foo';", LeaveQuotes); } + +TEST_F(FormatTestJS, LocationComment) { + verifyFormat("import {\n" + " x\n" + "} from\n" + " 'asd'; // from //some/really/long/path/here", + "import {x} from 'asd'; // from //some/really/long/path/here", + getGoogleJSStyleWithColumns(25)); +} + } // end namespace tooling } // end namespace clang Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -1059,6 +1059,8 @@ return 0; } +static llvm::Regex JSImportLocationCommentRegex("^//[ \n\t]*from[ \n\t]+//"); + unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, LineState &State, bool DryRun) { @@ -1137,6 +1139,10 @@ if (!Style.ReflowComments || CommentPragmasRegex.match(Current.TokenText.substr(2))) return 0; + if (Style.Language == FormatStyle::LK_JavaScript && + JSImportLocationCommentRegex.match(Current.TokenText)) + return 0; + Token.reset(new BreakableLineComment(Current, State.Line->Level, StartColumn, /*InPPDirective=*/false, Encoding, Style));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits