[NFC][clangd] cleanup llvm-else-after-return findings
Cleanup of clang-tidy findings: removing "else" after a return statement
to improve readability of the code.
This patch was created by applying the clang-tidy fixes automatically.
Differential Revision: https://reviews.llvm.org/D113892
GitOrigin-RevId: ec4a2c956591e97904eae5102022f343dadfb8f1
diff --git a/clangd/ClangdLSPServer.cpp b/clangd/ClangdLSPServer.cpp
index c01a428..6c000d3 100644
--- a/clangd/ClangdLSPServer.cpp
+++ b/clangd/ClangdLSPServer.cpp
@@ -929,8 +929,7 @@
adjustSymbolKinds(*Items, SupportedSymbolKinds);
if (SupportsHierarchicalDocumentSymbol)
return Reply(std::move(*Items));
- else
- return Reply(flattenSymbolHierarchy(*Items, FileURI));
+ return Reply(flattenSymbolHierarchy(*Items, FileURI));
});
}
diff --git a/clangd/FuzzyMatch.cpp b/clangd/FuzzyMatch.cpp
index 57f9554..2a908fd 100644
--- a/clangd/FuzzyMatch.cpp
+++ b/clangd/FuzzyMatch.cpp
@@ -320,8 +320,9 @@
if (!WordContainsPattern) {
OS << "Substring check failed.\n";
return Result;
- } else if (isAwful(std::max(Scores[PatN][WordN][Match].Score,
- Scores[PatN][WordN][Miss].Score))) {
+ }
+ if (isAwful(std::max(Scores[PatN][WordN][Match].Score,
+ Scores[PatN][WordN][Miss].Score))) {
OS << "Substring check passed, but all matches are forbidden\n";
}
if (!(PatTypeSet & 1 << Upper))
diff --git a/clangd/Hover.cpp b/clangd/Hover.cpp
index 4285b35..faea812 100644
--- a/clangd/Hover.cpp
+++ b/clangd/Hover.cpp
@@ -74,7 +74,7 @@
// - Classes, categories, and protocols: "MyClass(Category)"
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
return printObjCMethod(*MD);
- else if (const ObjCContainerDecl *CD = dyn_cast<ObjCContainerDecl>(DC))
+ if (const ObjCContainerDecl *CD = dyn_cast<ObjCContainerDecl>(DC))
return printObjCContainer(*CD);
auto GetName = [](const TypeDecl *D) {
diff --git a/clangd/JSONTransport.cpp b/clangd/JSONTransport.cpp
index fd405c1..ecf6c67 100644
--- a/clangd/JSONTransport.cpp
+++ b/clangd/JSONTransport.cpp
@@ -194,8 +194,7 @@
if (ID)
return Handler.onCall(*Method, std::move(Params), std::move(*ID));
- else
- return Handler.onNotify(*Method, std::move(Params));
+ return Handler.onNotify(*Method, std::move(Params));
}
// Tries to read a line up to and including \n.
@@ -254,14 +253,14 @@
}
llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
continue;
- } else if (!LineRef.trim().empty()) {
- // It's another header, ignore it.
- continue;
- } else {
- // An empty line indicates the end of headers.
- // Go ahead and read the JSON.
- break;
}
+
+ // An empty line indicates the end of headers.
+ // Go ahead and read the JSON.
+ if (LineRef.trim().empty())
+ break;
+
+ // It's another header, ignore it.
}
// The fuzzer likes crashing us by sending "Content-Length: 9999999999999999"
diff --git a/clangd/PathMapping.cpp b/clangd/PathMapping.cpp
index cc98025..882e3fb 100644
--- a/clangd/PathMapping.cpp
+++ b/clangd/PathMapping.cpp
@@ -151,7 +151,8 @@
namespace path = llvm::sys::path;
if (path::is_absolute(Path, path::Style::posix)) {
return std::string(Path);
- } else if (path::is_absolute(Path, path::Style::windows)) {
+ }
+ if (path::is_absolute(Path, path::Style::windows)) {
std::string Converted = path::convert_to_slash(Path, path::Style::windows);
if (Converted.front() != '/')
Converted = "/" + Converted;
diff --git a/clangd/Protocol.cpp b/clangd/Protocol.cpp
index 5fa2d21..0cfc7ff 100644
--- a/clangd/Protocol.cpp
+++ b/clangd/Protocol.cpp
@@ -695,7 +695,8 @@
if (ArgsArray->size() > 1) {
P.field("arguments").report("Command should have 0 or 1 argument");
return false;
- } else if (ArgsArray->size() == 1) {
+ }
+ if (ArgsArray->size() == 1) {
R.argument = ArgsArray->front();
}
return true;
diff --git a/clangd/Selection.cpp b/clangd/Selection.cpp
index 88ab1c5..e945f5d 100644
--- a/clangd/Selection.cpp
+++ b/clangd/Selection.cpp
@@ -346,7 +346,7 @@
SM.getTopMacroCallerLoc(Batch.back().location());
return testTokenRange(SM.getFileOffset(ArgStart),
SM.getFileOffset(ArgEnd));
- } else {
+ } else { // NOLINT(llvm-else-after-return)
/* fall through and treat as part of the macro body */
}
}
@@ -357,8 +357,7 @@
if (Expansion.first == SelFile)
// FIXME: also check ( and ) for function-like macros?
return testToken(Expansion.second);
- else
- return NoTokens;
+ return NoTokens;
}
// Is the closed token range [Begin, End] selected?
diff --git a/clangd/TUScheduler.cpp b/clangd/TUScheduler.cpp
index afaf6ed..e758673 100644
--- a/clangd/TUScheduler.cpp
+++ b/clangd/TUScheduler.cpp
@@ -1282,8 +1282,8 @@
if (Done) {
if (Requests.empty())
return;
- else // Even though Done is set, finish pending requests.
- break; // However, skip delays to shutdown fast.
+ // Even though Done is set, finish pending requests.
+ break; // However, skip delays to shutdown fast.
}
// Tracing: we have a next request, attribute this sleep to it.
diff --git a/clangd/XRefs.cpp b/clangd/XRefs.cpp
index b29d29e..452067a 100644
--- a/clangd/XRefs.cpp
+++ b/clangd/XRefs.cpp
@@ -826,10 +826,9 @@
log("Found definition heuristically using nearby identifier {0}",
NearbyIdent->text(SM));
return ASTResults;
- } else {
- vlog("No definition found using nearby identifier {0} at {1}",
- Word->Text, Word->Location.printToString(SM));
}
+ vlog("No definition found using nearby identifier {0} at {1}", Word->Text,
+ Word->Location.printToString(SM));
}
// No nearby word, or it didn't refer to anything either. Try the index.
auto TextualResults =
diff --git a/clangd/index/Serialization.cpp b/clangd/index/Serialization.cpp
index 3f29cb8..f488220 100644
--- a/clangd/index/Serialization.cpp
+++ b/clangd/index/Serialization.cpp
@@ -687,7 +687,8 @@
llvm::Expected<IndexFileIn> readIndexFile(llvm::StringRef Data) {
if (Data.startswith("RIFF")) {
return readRIFF(Data);
- } else if (auto YAMLContents = readYAML(Data)) {
+ }
+ if (auto YAMLContents = readYAML(Data)) {
return std::move(*YAMLContents);
} else {
return error("Not a RIFF file and failed to parse as YAML: {0}",
diff --git a/clangd/refactor/tweaks/AddUsing.cpp b/clangd/refactor/tweaks/AddUsing.cpp
index c87b886..eee64d8 100644
--- a/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clangd/refactor/tweaks/AddUsing.cpp
@@ -250,7 +250,8 @@
for (; Node->Parent; Node = Node->Parent) {
if (Node->ASTNode.get<NestedNameSpecifierLoc>()) {
continue;
- } else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
+ }
+ if (auto *T = Node->ASTNode.get<TypeLoc>()) {
if (T->getAs<ElaboratedTypeLoc>()) {
break;
} else if (Node->Parent->ASTNode.get<TypeLoc>() ||
diff --git a/clangd/refactor/tweaks/ExtractFunction.cpp b/clangd/refactor/tweaks/ExtractFunction.cpp
index da67c7e..a3e20d6 100644
--- a/clangd/refactor/tweaks/ExtractFunction.cpp
+++ b/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -223,8 +223,7 @@
while (const auto *CS = llvm::dyn_cast<CompoundStmt>(Last)) {
if (CS->body_empty())
return false;
- else
- Last = CS->body_back();
+ Last = CS->body_back();
}
return llvm::isa<ReturnStmt>(Last);
}