Skip to content

Commit ec4a2c9

Browse files
[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
1 parent 4ea066a commit ec4a2c9

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,7 @@ void ClangdLSPServer::onDocumentSymbol(const DocumentSymbolParams &Params,
929929
adjustSymbolKinds(*Items, SupportedSymbolKinds);
930930
if (SupportsHierarchicalDocumentSymbol)
931931
return Reply(std::move(*Items));
932-
else
933-
return Reply(flattenSymbolHierarchy(*Items, FileURI));
932+
return Reply(flattenSymbolHierarchy(*Items, FileURI));
934933
});
935934
}
936935

clang-tools-extra/clangd/FuzzyMatch.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,9 @@ llvm::SmallString<256> FuzzyMatcher::dumpLast(llvm::raw_ostream &OS) const {
320320
if (!WordContainsPattern) {
321321
OS << "Substring check failed.\n";
322322
return Result;
323-
} else if (isAwful(std::max(Scores[PatN][WordN][Match].Score,
324-
Scores[PatN][WordN][Miss].Score))) {
323+
}
324+
if (isAwful(std::max(Scores[PatN][WordN][Match].Score,
325+
Scores[PatN][WordN][Miss].Score))) {
325326
OS << "Substring check passed, but all matches are forbidden\n";
326327
}
327328
if (!(PatTypeSet & 1 << Upper))

clang-tools-extra/clangd/Hover.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ std::string getLocalScope(const Decl *D) {
7474
// - Classes, categories, and protocols: "MyClass(Category)"
7575
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
7676
return printObjCMethod(*MD);
77-
else if (const ObjCContainerDecl *CD = dyn_cast<ObjCContainerDecl>(DC))
77+
if (const ObjCContainerDecl *CD = dyn_cast<ObjCContainerDecl>(DC))
7878
return printObjCContainer(*CD);
7979

8080
auto GetName = [](const TypeDecl *D) {

clang-tools-extra/clangd/JSONTransport.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ bool JSONTransport::handleMessage(llvm::json::Value Message,
194194

195195
if (ID)
196196
return Handler.onCall(*Method, std::move(Params), std::move(*ID));
197-
else
198-
return Handler.onNotify(*Method, std::move(Params));
197+
return Handler.onNotify(*Method, std::move(Params));
199198
}
200199

201200
// Tries to read a line up to and including \n.
@@ -254,14 +253,14 @@ bool JSONTransport::readStandardMessage(std::string &JSON) {
254253
}
255254
llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
256255
continue;
257-
} else if (!LineRef.trim().empty()) {
258-
// It's another header, ignore it.
259-
continue;
260-
} else {
261-
// An empty line indicates the end of headers.
262-
// Go ahead and read the JSON.
263-
break;
264256
}
257+
258+
// An empty line indicates the end of headers.
259+
// Go ahead and read the JSON.
260+
if (LineRef.trim().empty())
261+
break;
262+
263+
// It's another header, ignore it.
265264
}
266265

267266
// The fuzzer likes crashing us by sending "Content-Length: 9999999999999999"

clang-tools-extra/clangd/PathMapping.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ llvm::Expected<std::string> parsePath(llvm::StringRef Path) {
151151
namespace path = llvm::sys::path;
152152
if (path::is_absolute(Path, path::Style::posix)) {
153153
return std::string(Path);
154-
} else if (path::is_absolute(Path, path::Style::windows)) {
154+
}
155+
if (path::is_absolute(Path, path::Style::windows)) {
155156
std::string Converted = path::convert_to_slash(Path, path::Style::windows);
156157
if (Converted.front() != '/')
157158
Converted = "/" + Converted;

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ bool fromJSON(const llvm::json::Value &Params, ExecuteCommandParams &R,
695695
if (ArgsArray->size() > 1) {
696696
P.field("arguments").report("Command should have 0 or 1 argument");
697697
return false;
698-
} else if (ArgsArray->size() == 1) {
698+
}
699+
if (ArgsArray->size() == 1) {
699700
R.argument = ArgsArray->front();
700701
}
701702
return true;

clang-tools-extra/clangd/Selection.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class SelectionTester {
346346
SM.getTopMacroCallerLoc(Batch.back().location());
347347
return testTokenRange(SM.getFileOffset(ArgStart),
348348
SM.getFileOffset(ArgEnd));
349-
} else {
349+
} else { // NOLINT(llvm-else-after-return)
350350
/* fall through and treat as part of the macro body */
351351
}
352352
}
@@ -357,8 +357,7 @@ class SelectionTester {
357357
if (Expansion.first == SelFile)
358358
// FIXME: also check ( and ) for function-like macros?
359359
return testToken(Expansion.second);
360-
else
361-
return NoTokens;
360+
return NoTokens;
362361
}
363362

364363
// Is the closed token range [Begin, End] selected?

clang-tools-extra/clangd/TUScheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,8 @@ void ASTWorker::run() {
12821282
if (Done) {
12831283
if (Requests.empty())
12841284
return;
1285-
else // Even though Done is set, finish pending requests.
1286-
break; // However, skip delays to shutdown fast.
1285+
// Even though Done is set, finish pending requests.
1286+
break; // However, skip delays to shutdown fast.
12871287
}
12881288

12891289
// Tracing: we have a next request, attribute this sleep to it.

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,9 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
826826
log("Found definition heuristically using nearby identifier {0}",
827827
NearbyIdent->text(SM));
828828
return ASTResults;
829-
} else {
830-
vlog("No definition found using nearby identifier {0} at {1}",
831-
Word->Text, Word->Location.printToString(SM));
832829
}
830+
vlog("No definition found using nearby identifier {0} at {1}", Word->Text,
831+
Word->Location.printToString(SM));
833832
}
834833
// No nearby word, or it didn't refer to anything either. Try the index.
835834
auto TextualResults =

clang-tools-extra/clangd/index/Serialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const IndexFileOut &O) {
687687
llvm::Expected<IndexFileIn> readIndexFile(llvm::StringRef Data) {
688688
if (Data.startswith("RIFF")) {
689689
return readRIFF(Data);
690-
} else if (auto YAMLContents = readYAML(Data)) {
690+
}
691+
if (auto YAMLContents = readYAML(Data)) {
691692
return std::move(*YAMLContents);
692693
} else {
693694
return error("Not a RIFF file and failed to parse as YAML: {0}",

clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ bool AddUsing::prepare(const Selection &Inputs) {
250250
for (; Node->Parent; Node = Node->Parent) {
251251
if (Node->ASTNode.get<NestedNameSpecifierLoc>()) {
252252
continue;
253-
} else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
253+
}
254+
if (auto *T = Node->ASTNode.get<TypeLoc>()) {
254255
if (T->getAs<ElaboratedTypeLoc>()) {
255256
break;
256257
} else if (Node->Parent->ASTNode.get<TypeLoc>() ||

clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ bool alwaysReturns(const ExtractionZone &EZ) {
223223
while (const auto *CS = llvm::dyn_cast<CompoundStmt>(Last)) {
224224
if (CS->body_empty())
225225
return false;
226-
else
227-
Last = CS->body_back();
226+
Last = CS->body_back();
228227
}
229228
return llvm::isa<ReturnStmt>(Last);
230229
}

0 commit comments

Comments
 (0)