This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] Sort imported symbols.
ClosedPublic

Authored by mprobst on May 30 2016, 12:20 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

mprobst updated this revision to Diff 58984.May 30 2016, 12:20 PM
mprobst retitled this revision from to clang-format: [JS] Sort imported symbols..
mprobst updated this object.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
mprobst updated this revision to Diff 59001.May 30 2016, 2:11 PM
  • extract method for readability
djasper edited edge metadata.May 31 2016, 7:18 AM

In general, this is lacking test cases for imports that are wrapped over multiple lines to start with. Should probably add those both for the old and for the new behavior.

lib/Format/Format.cpp
1229 ↗(On Diff #59001)

I think it's not even worth storing this variable now.

lib/Format/SortJavaScriptImports.cpp
46 ↗(On Diff #59001)

Maybe add a comment on why you are ignoring 'Range' for comparison.

168 ↗(On Diff #59001)

nit: no braces

232 ↗(On Diff #59001)

I think it's safe to pass the symbols as const reference here.

mprobst marked 4 inline comments as done.May 31 2016, 8:00 AM

Done regarding the tests. We do have an unrelated issue with formatting import {x as foo}, will send a fix later.

mprobst updated this revision to Diff 59070.May 31 2016, 8:00 AM
mprobst edited edge metadata.
  • multiline tests, review comments

Done regarding the tests. We do have an unrelated issue with formatting import {x as foo}, will send a fix later.

djasper accepted this revision.May 31 2016, 10:26 PM
djasper edited edge metadata.
djasper added inline comments.
lib/Format/SortJavaScriptImports.cpp
248 ↗(On Diff #59070)

It's an implementation detail that the iterator of a SmallVector is a JsImportedSymbol*. Use auto. Also, I find this more readable:

for (auto I = Symbols.begin(), E = Symbols.end(); I != E; ++I) {
  if (I != Symbols.begin())
    Buffer += ",";
  Buffer += getSourceText(I->Range);
}
This revision is now accepted and ready to land.May 31 2016, 10:26 PM
mprobst marked an inline comment as done.Jun 1 2016, 8:23 AM
This revision was automatically updated to reflect the committed changes.