Skip to content

Commit

Permalink
clang-format: [JS] do not wrap @see tags.
Browse files Browse the repository at this point in the history
Summary:
@see is special among JSDoc tags in that it is commonly followed by URLs. The JSDoc spec suggests that users should wrap URLs in an additional {@link url...} tag (@see http://usejsdoc.org/tags-see.html), but this is very commonly violated, with @see being followed by a "naked" URL.

This change special cases all JSDoc lines that contain an @see not to be wrapped to account for that.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D30883

llvm-svn: 297607
  • Loading branch information
mprobst committed Mar 13, 2017
1 parent 22b8d26 commit b4cdb65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,9 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
GoogleStyle.BreakBeforeTernaryOperators = false;
// taze:, and @tag followed by { for a lot of JSDoc tags.
GoogleStyle.CommentPragmas = "(taze:|(@[A-Za-z_0-9-]+[ \\t]*{))";
// taze:, @tag followed by { for a lot of JSDoc tags, and @see, which is
// commonly followed by overlong URLs.
GoogleStyle.CommentPragmas = "(taze:|(@[A-Za-z_0-9-]+[ \\t]*{)|@see)";
GoogleStyle.MaxEmptyLinesToKeep = 3;
GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
GoogleStyle.SpacesInContainerLiterals = false;
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,13 @@ TEST_F(FormatTestJS, JSDocAnnotations) {
" * @param {this.is.a.long.path.to.a.Type}\n"
" */",
getGoogleJSStyleWithColumns(20));
verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n"
" */",
"/**\n"
" * @see http://very/very/long/url/is/long\n"
" */",
getGoogleJSStyleWithColumns(20));
verifyFormat(
"/**\n"
" * @param This is a\n"
Expand Down

0 comments on commit b4cdb65

Please sign in to comment.