This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] do not break before @tags in JS comments
ClosedPublic

Authored by krasimir on Nov 9 2020, 6:57 AM.

Details

Summary

In JavaScript breaking before a @tag in a comment puts it on a new line, and
machinery that parses these comments will fail to understand such comments.

This adapts clang-format to not break before @. Similar functionality exists
for not breaking before {.

Diff Detail

Event Timeline

krasimir created this revision.Nov 9 2020, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2020, 6:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
krasimir requested review of this revision.Nov 9 2020, 6:57 AM
krasimir added inline comments.Nov 9 2020, 6:59 AM
clang/unittests/Format/FormatTestJS.cpp
194

this actually demonstrates a bug fixed by this patch: with 20 column limit, the comment should be split. The new behavior makes the test with a column limit of 25 redundant, so folded the two of them.

205

this is an exact duplicate as the check on old line 190; removed

krasimir added a project: Restricted Project.

See my comment on the upstream bug, let's chat a bit about whether we need this.

mprobst accepted this revision.Nov 10 2020, 12:28 AM
This revision is now accepted and ready to land.Nov 10 2020, 12:28 AM

For posterity: there was a question whether this is legal syntax in JSDoc in the first place (e.g. whether it should be escaped). That remains unclear - Closure Compiler parser however does ignore JSDoc tags if the line does not start with an @ tag. So the safe thing is to do what this revision does, avoid wrapping.

This revision was landed with ongoing or failed builds.Nov 11 2020, 3:31 AM
This revision was automatically updated to reflect the committed changes.