diff options
author | Martin Probst <martin@probst.io> | 2016-09-02 14:01:17 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2016-09-02 14:01:17 +0000 |
commit | b480ffbcef2e0833b471d304861e20c2d6d9e963 (patch) | |
tree | 706f188e9e0fef68aad2ecdcbd5cf05f8250257b /clang/lib/Format/SortJavaScriptImports.cpp | |
parent | 7a78e5113a2334dbadd45f0c800312402d737b8b (diff) | |
download | bcm5719-llvm-b480ffbcef2e0833b471d304861e20c2d6d9e963.tar.gz bcm5719-llvm-b480ffbcef2e0833b471d304861e20c2d6d9e963.zip |
clang-format: [JS] Sort all JavaScript imports if any changed.
Summary:
User feedback is that they expect *all* imports to be sorted if any import was
affected by a change, not just imports up to the first non-affected line, as
clang-format currently does.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D23972
llvm-svn: 280485
Diffstat (limited to 'clang/lib/Format/SortJavaScriptImports.cpp')
-rw-r--r-- | clang/lib/Format/SortJavaScriptImports.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index e800007f79d..72da52bf16b 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -284,14 +284,8 @@ private: SourceLocation Start; bool FoundLines = false; AnnotatedLine *FirstNonImportLine = nullptr; + bool AnyImportAffected = false; for (auto Line : AnnotatedLines) { - if (!Line->Affected) { - // Only sort the first contiguous block of affected lines. - if (FoundLines) - break; - else - continue; - } Current = Line->First; LineEnd = Line->Last; skipComments(); @@ -309,6 +303,7 @@ private: FirstNonImportLine = Line; break; } + AnyImportAffected = AnyImportAffected || Line->Affected; Reference.Range.setEnd(LineEnd->Tok.getEndLoc()); DEBUG({ llvm::dbgs() << "JsModuleReference: {" @@ -325,6 +320,9 @@ private: References.push_back(Reference); Start = SourceLocation(); } + // Sort imports if any import line was affected. + if (!AnyImportAffected) + References.clear(); return std::make_pair(References, FirstNonImportLine); } |