[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 20 09:44:10 PDT 2017


krasimir marked 2 inline comments as done.
krasimir added inline comments.


================
Comment at: lib/Format/BreakableToken.cpp:435
+  // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+    if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
----------------
mprobst wrote:
> I think I'd also enable this for at least Java. But tentatively I wonder - wouldn't just about every language do it like this for `/**` comments?
I agree for Java, but otherwise not. C++ is crazy with strange styles.


================
Comment at: lib/Format/BreakableToken.cpp:436
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+    if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
+      // This is a multiline jsdoc comment.
----------------
mprobst wrote:
> mprobst wrote:
> > Wouldn't we also want to do this for `/**blah`, i.e. no whitespace after `*`?
> Would we also want to do this for simple block comments, e.g. `/*blah*/`?  That's a bit more tricky as they can be used inline, not sure about the corner cases there.
I explicitly check for a whitespace after the `*` to take care of strange stuff that is not javadoc, like ASCII art or lines like:
```
/********
 * #yolo
 */
```
I think we can decide for simple block comments later and leave them as-is for now.


================
Comment at: lib/Format/BreakableToken.cpp:606
+    if (DelimitersOnNewline) {
+        size_t BreakLength = Lines[0].substr(1).find_first_not_of(Blanks);
+        if (BreakLength != StringRef::npos) {
----------------
mprobst wrote:
> isn't this BreakPosition rather than length?
It's both the BreakPosition and the BreakLength, because we're breaking starting from index 1.
Added a comment line (pun intended).


https://reviews.llvm.org/D35683





More information about the cfe-commits mailing list