Skip to content

Commit 6d4ea94

Browse files
huntiefacebook-github-bot
authored andcommitted
Address lint warnings (#52702)
Summary: Pull Request resolved: #52702 Quick pass over some of the main files in `jsinspector-modern` now that C++ lint warnings have become more prevalent / auto-fixable. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D78490415 fbshipit-source-id: 32debcf5f217e847d326498709d50f695902bb5c
1 parent 8488eae commit 6d4ea94

8 files changed

Lines changed: 22 additions & 28 deletions

File tree

packages/react-native/ReactCommon/jsinspector-modern/ExecutionContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "UniqueMonostate.h"
1111

12-
#include <cinttypes>
1312
#include <optional>
1413
#include <string>
1514
#include <unordered_set>
@@ -19,7 +18,7 @@ namespace facebook::react::jsinspector_modern {
1918

2019
struct ExecutionContextDescription {
2120
int32_t id{};
22-
std::string origin{""};
21+
std::string origin;
2322
std::string name{"<anonymous>"};
2423
std::optional<std::string> uniqueId;
2524
};

packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace facebook::react::jsinspector_modern {
3636
class HostAgent::Impl final {
3737
public:
3838
explicit Impl(
39-
HostAgent& hostAgent,
40-
FrontendChannel frontendChannel,
39+
HostAgent& /*hostAgent*/,
40+
const FrontendChannel& frontendChannel,
4141
HostTargetController& targetController,
4242
HostTargetMetadata hostMetadata,
4343
SessionState& sessionState,
@@ -126,11 +126,11 @@ class HostAgent::Impl final {
126126
else if (req.method == "Page.reload") {
127127
targetController_.getDelegate().onReload({
128128
.ignoreCache =
129-
req.params.isObject() && req.params.count("ignoreCache")
129+
req.params.isObject() && (req.params.count("ignoreCache") != 0u)
130130
? std::optional(req.params.at("ignoreCache").asBool())
131131
: std::nullopt,
132132
.scriptToEvaluateOnLoad = req.params.isObject() &&
133-
req.params.count("scriptToEvaluateOnLoad")
133+
(req.params.count("scriptToEvaluateOnLoad") != 0u)
134134
? std::optional(
135135
req.params.at("scriptToEvaluateOnLoad").asString())
136136
: std::nullopt,
@@ -139,7 +139,8 @@ class HostAgent::Impl final {
139139
shouldSendOKResponse = true;
140140
isFinishedHandlingRequest = true;
141141
} else if (req.method == "Overlay.setPausedInDebuggerMessage") {
142-
auto message = req.params.isObject() && req.params.count("message")
142+
auto message =
143+
req.params.isObject() && (req.params.count("message") != 0u)
143144
? std::optional(req.params.at("message").asString())
144145
: std::nullopt;
145146
if (!isPausedInDebuggerOverlayVisible_ && message.has_value()) {

packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ class HostTargetSession {
4545
targetController,
4646
std::move(hostMetadata),
4747
state_,
48-
executor) {}
48+
std::move(executor)) {}
4949

5050
/**
5151
* Called by CallbackLocalConnection to send a message to this Session's
5252
* Agent.
5353
*/
54-
void operator()(std::string message) {
54+
void operator()(const std::string& message) {
5555
cdp::PreparsedRequest request;
5656
// Messages may be invalid JSON, or have unexpected types.
5757
try {
@@ -91,7 +91,7 @@ class HostTargetSession {
9191
* there's no current instance.
9292
*/
9393
void setCurrentInstance(InstanceTarget* instance) {
94-
if (instance) {
94+
if (instance != nullptr) {
9595
hostAgent_.setCurrentInstanceAgent(
9696
instance->createAgent(frontendChannel_, state_));
9797
} else {
@@ -148,7 +148,7 @@ std::shared_ptr<HostTarget> HostTarget::create(
148148
HostTargetDelegate& delegate,
149149
VoidExecutor executor) {
150150
std::shared_ptr<HostTarget> hostTarget{new HostTarget(delegate)};
151-
hostTarget->setExecutor(executor);
151+
hostTarget->setExecutor(std::move(executor));
152152
return hostTarget;
153153
}
154154

@@ -166,7 +166,7 @@ std::unique_ptr<ILocalConnection> HostTarget::connect(
166166
session->setCurrentInstance(currentInstance_.get());
167167
sessions_.insert(std::weak_ptr(session));
168168
return std::make_unique<CallbackLocalConnection>(
169-
[session](std::string message) { (*session)(message); });
169+
[session](const std::string& message) { (*session)(message); });
170170
}
171171

172172
HostTarget::~HostTarget() {
@@ -228,10 +228,7 @@ void HostTargetController::incrementPauseOverlayCounter() {
228228

229229
bool HostTargetController::decrementPauseOverlayCounter() {
230230
assert(pauseOverlayCounter_ > 0 && "Pause overlay counter underflow");
231-
if (--pauseOverlayCounter_ == 0) {
232-
return false;
233-
}
234-
return true;
231+
return --pauseOverlayCounter_ != 0;
235232
}
236233

237234
namespace {

packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <cassert>
1111
#include <list>
1212
#include <mutex>
13-
#include <tuple>
14-
#include <unordered_map>
1513

1614
namespace facebook::react::jsinspector_modern {
1715

@@ -24,7 +22,7 @@ IRemoteConnection::~IRemoteConnection() {}
2422
IInspector::~IInspector() {}
2523
IPageStatusListener::~IPageStatusListener() {}
2624

27-
const folly::dynamic targetCapabilitiesToDynamic(
25+
folly::dynamic targetCapabilitiesToDynamic(
2826
const InspectorTargetCapabilities& capabilities) {
2927
return folly::dynamic::object(
3028
"nativePageReloads", capabilities.nativePageReloads)(
@@ -56,7 +54,7 @@ class InspectorImpl : public IInspector {
5654
public:
5755
Page(
5856
int id,
59-
const std::string& title,
57+
const std::string& description,
6058
const std::string& vm,
6159
ConnectFunc connectFunc,
6260
InspectorTargetCapabilities capabilities);
@@ -87,7 +85,7 @@ InspectorImpl::Page::Page(
8785
description_(description),
8886
vm_(vm),
8987
connectFunc_(std::move(connectFunc)),
90-
capabilities_(std::move(capabilities)) {}
88+
capabilities_(capabilities) {}
9189

9290
InspectorImpl::Page::operator InspectorPageDescription() const {
9391
return InspectorPageDescription{
@@ -124,7 +122,7 @@ void InspectorImpl::removePage(int pageId) {
124122
std::scoped_lock lock(mutex_);
125123

126124
if (pages_.erase(pageId) != 0) {
127-
for (auto listenerWeak : listeners_) {
125+
for (auto& listenerWeak : listeners_) {
128126
if (auto listener = listenerWeak.lock()) {
129127
listener->onPageRemoved(pageId);
130128
}
@@ -138,6 +136,7 @@ std::vector<InspectorPageDescription> InspectorImpl::getPages() const {
138136
std::vector<InspectorPageDescription> inspectorPages;
139137
// pages_ is a std::map keyed on an incremental id, so this is insertion
140138
// ordered.
139+
inspectorPages.reserve(pages_.size());
141140
for (auto& it : pages_) {
142141
inspectorPages.push_back(InspectorPageDescription(it.second));
143142
}

packages/react-native/ReactCommon/jsinspector-modern/InspectorInterfaces.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct InspectorTargetCapabilities {
3939
bool prefersFuseboxFrontend = false;
4040
};
4141

42-
const folly::dynamic targetCapabilitiesToDynamic(
42+
folly::dynamic targetCapabilitiesToDynamic(
4343
const InspectorTargetCapabilities& capabilities);
4444

4545
struct InspectorPageDescription {

packages/react-native/ReactCommon/jsinspector-modern/InstanceAgent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ InstanceAgent::InstanceAgent(
1616
FrontendChannel frontendChannel,
1717
InstanceTarget& target,
1818
SessionState& sessionState)
19-
: frontendChannel_(frontendChannel),
19+
: frontendChannel_(std::move(frontendChannel)),
2020
target_(target),
2121
sessionState_(sessionState) {
2222
(void)target_;
@@ -36,7 +36,7 @@ bool InstanceAgent::handleRequest(const cdp::PreparsedRequest& req) {
3636

3737
void InstanceAgent::setCurrentRuntime(RuntimeTarget* runtimeTarget) {
3838
auto previousRuntimeAgent = std::move(runtimeAgent_);
39-
if (runtimeTarget) {
39+
if (runtimeTarget != nullptr) {
4040
runtimeAgent_ = runtimeTarget->createAgent(frontendChannel_, sessionState_);
4141
} else {
4242
runtimeAgent_.reset();

packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ std::shared_ptr<InstanceTarget> InstanceTarget::create(
1818
VoidExecutor executor) {
1919
std::shared_ptr<InstanceTarget> instanceTarget{
2020
new InstanceTarget(executionContextManager, delegate)};
21-
instanceTarget->setExecutor(executor);
21+
instanceTarget->setExecutor(std::move(executor));
2222
return instanceTarget;
2323
}
2424

packages/react-native/ReactCommon/jsinspector-modern/InstanceTarget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
#include <jsinspector-modern/InspectorInterfaces.h>
1717
#include <jsinspector-modern/RuntimeAgent.h>
1818

19-
#include <list>
2019
#include <memory>
21-
#include <optional>
2220

2321
namespace facebook::react::jsinspector_modern {
2422

0 commit comments

Comments
 (0)