Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b1edb3d

Browse files
committed
Lint fixes for fml, tools
1 parent 5498add commit b1edb3d

18 files changed

+101
-78
lines changed

fml/ascii_trie.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
4+
55
#include "flutter/fml/ascii_trie.h"
66
#include "flutter/fml/logging.h"
77

@@ -38,7 +38,7 @@ bool AsciiTrie::Query(TrieNode* trie, const char* query) {
3838
FML_DCHECK(trie);
3939
const char* char_position = query;
4040
TrieNode* trie_position = trie;
41-
TrieNode* child;
41+
TrieNode* child = nullptr;
4242
int ch;
4343
while ((ch = *char_position) && (child = trie_position->children[ch].get())) {
4444
char_position++;

fml/command_line.cc

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include "flutter/fml/command_line.h"
76

@@ -27,8 +26,9 @@ CommandLine::CommandLine(const std::string& argv0,
2726
argv0_(argv0),
2827
options_(options),
2928
positional_args_(positional_args) {
30-
for (size_t i = 0; i < options_.size(); i++)
29+
for (size_t i = 0; i < options_.size(); i++) {
3130
option_index_[options_[i].name] = i;
31+
}
3232
}
3333

3434
CommandLine::~CommandLine() = default;
@@ -39,18 +39,21 @@ CommandLine& CommandLine::operator=(CommandLine&& from) = default;
3939

4040
bool CommandLine::HasOption(std::string_view name, size_t* index) const {
4141
auto it = option_index_.find(name.data());
42-
if (it == option_index_.end())
42+
if (it == option_index_.end()) {
4343
return false;
44-
if (index)
44+
}
45+
if (index) {
4546
*index = it->second;
47+
}
4648
return true;
4749
}
4850

4951
bool CommandLine::GetOptionValue(std::string_view name,
5052
std::string* value) const {
5153
size_t index;
52-
if (!HasOption(name, &index))
54+
if (!HasOption(name, &index)) {
5355
return false;
56+
}
5457
*value = options_[index].value;
5558
return true;
5659
}
@@ -59,8 +62,9 @@ std::vector<std::string_view> CommandLine::GetOptionValues(
5962
std::string_view name) const {
6063
std::vector<std::string_view> ret;
6164
for (const auto& option : options_) {
62-
if (option.name == name)
65+
if (option.name == name) {
6366
ret.push_back(option.value);
67+
}
6468
}
6569
return ret;
6670
}
@@ -69,8 +73,9 @@ std::string CommandLine::GetOptionValueWithDefault(
6973
std::string_view name,
7074
std::string_view default_value) const {
7175
size_t index;
72-
if (!HasOption(name, &index))
76+
if (!HasOption(name, &index)) {
7377
return {default_value.data(), default_value.size()};
78+
}
7479
return options_[index].value;
7580
}
7681

@@ -125,16 +130,18 @@ bool CommandLineBuilder::ProcessArg(const std::string& arg) {
125130
}
126131

127132
CommandLine CommandLineBuilder::Build() const {
128-
if (!has_argv0_)
133+
if (!has_argv0_) {
129134
return CommandLine();
135+
}
130136
return CommandLine(argv0_, options_, positional_args_);
131137
}
132138

133139
} // namespace internal
134140

135141
std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
136-
if (!command_line.has_argv0())
142+
if (!command_line.has_argv0()) {
137143
return std::vector<std::string>();
144+
}
138145

139146
std::vector<std::string> argv;
140147
const std::vector<CommandLine::Option>& options = command_line.options();
@@ -146,17 +153,19 @@ std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
146153

147154
argv.push_back(command_line.argv0());
148155
for (const auto& option : options) {
149-
if (option.value.empty())
156+
if (option.value.empty()) {
150157
argv.push_back("--" + option.name);
151-
else
158+
} else {
152159
argv.push_back("--" + option.name + "=" + option.value);
160+
}
153161
}
154162

155163
if (!positional_args.empty()) {
156164
// Insert a "--" if necessary.
157165
if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
158-
positional_args[0][1] == '-')
166+
positional_args[0][1] == '-') {
159167
argv.push_back("--");
168+
}
160169

161170
argv.insert(argv.end(), positional_args.begin(), positional_args.end());
162171
}

fml/icu_util.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include "flutter/fml/icu_util.h"
76

@@ -20,11 +19,12 @@ namespace icu {
2019

2120
class ICUContext {
2221
public:
23-
ICUContext(const std::string& icu_data_path) : valid_(false) {
22+
explicit ICUContext(const std::string& icu_data_path) : valid_(false) {
2423
valid_ = SetupMapping(icu_data_path) && SetupICU();
2524
}
2625

27-
ICUContext(std::unique_ptr<Mapping> mapping) : mapping_(std::move(mapping)) {
26+
explicit ICUContext(std::unique_ptr<Mapping> mapping)
27+
: mapping_(std::move(mapping)) {
2828
valid_ = SetupICU();
2929
}
3030

fml/logging.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include <algorithm>
76
#include <iostream>
@@ -23,23 +22,26 @@ const char* const kLogSeverityNames[LOG_NUM_SEVERITIES] = {"INFO", "WARNING",
2322
"ERROR", "FATAL"};
2423

2524
const char* GetNameForLogSeverity(LogSeverity severity) {
26-
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES)
25+
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) {
2726
return kLogSeverityNames[severity];
27+
}
2828
return "UNKNOWN";
2929
}
3030

3131
const char* StripDots(const char* path) {
32-
while (strncmp(path, "../", 3) == 0)
32+
while (strncmp(path, "../", 3) == 0) {
3333
path += 3;
34+
}
3435
return path;
3536
}
3637

3738
const char* StripPath(const char* path) {
3839
auto* p = strrchr(path, '/');
39-
if (p)
40+
if (p) {
4041
return p + 1;
41-
else
42+
} else {
4243
return path;
44+
}
4345
}
4446

4547
} // namespace
@@ -50,15 +52,17 @@ LogMessage::LogMessage(LogSeverity severity,
5052
const char* condition)
5153
: severity_(severity), file_(file), line_(line) {
5254
stream_ << "[";
53-
if (severity >= LOG_INFO)
55+
if (severity >= LOG_INFO) {
5456
stream_ << GetNameForLogSeverity(severity);
55-
else
57+
} else {
5658
stream_ << "VERBOSE" << -severity;
59+
}
5760
stream_ << ":" << (severity > LOG_INFO ? StripDots(file_) : StripPath(file_))
5861
<< "(" << line_ << ")] ";
5962

60-
if (condition)
63+
if (condition) {
6164
stream_ << "Check failed: " << condition << ". ";
65+
}
6266
}
6367

6468
LogMessage::~LogMessage() {

fml/memory/ref_counted_unittest.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
// This file tests both ref_counted.h and ref_ptr.h (which the former includes).
76
// TODO(vtl): Possibly we could separate these tests out better, since a lot of
@@ -47,12 +46,14 @@ class MyClass : public RefCountedThreadSafe<MyClass> {
4746
protected:
4847
MyClass(MyClass** created, bool* was_destroyed)
4948
: was_destroyed_(was_destroyed) {
50-
if (created)
49+
if (created) {
5150
*created = this;
51+
}
5252
}
5353
virtual ~MyClass() {
54-
if (was_destroyed_)
54+
if (was_destroyed_) {
5555
*was_destroyed_ = true;
56+
}
5657
}
5758

5859
private:
@@ -71,8 +72,9 @@ class MySubclass final : public MyClass {
7172

7273
MySubclass(MySubclass** created, bool* was_destroyed)
7374
: MyClass(nullptr, was_destroyed) {
74-
if (created)
75+
if (created) {
7576
*created = this;
77+
}
7678
}
7779
~MySubclass() override {}
7880

fml/memory/weak_ptr_unittest.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#define FML_USED_ON_EMBEDDER
76

@@ -39,7 +38,7 @@ TEST(WeakPtrTest, MoveConstruction) {
3938
WeakPtrFactory<int> factory(&data);
4039
WeakPtr<int> ptr = factory.GetWeakPtr();
4140
WeakPtr<int> ptr2(std::move(ptr));
42-
EXPECT_EQ(nullptr, ptr.get());
41+
EXPECT_EQ(nullptr, ptr.get()); // NOLINT
4342
EXPECT_EQ(&data, ptr2.get());
4443
}
4544

@@ -61,7 +60,7 @@ TEST(WeakPtrTest, MoveAssignment) {
6160
WeakPtr<int> ptr2;
6261
EXPECT_EQ(nullptr, ptr2.get());
6362
ptr2 = std::move(ptr);
64-
EXPECT_EQ(nullptr, ptr.get());
63+
EXPECT_EQ(nullptr, ptr.get()); // NOLINT
6564
EXPECT_EQ(&data, ptr2.get());
6665
}
6766

fml/message_loop_task_queues_benchmark.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include <cassert>
76
#include <string>
@@ -14,7 +13,7 @@
1413
namespace fml {
1514
namespace benchmarking {
1615

17-
static void BM_RegisterAndGetTasks(benchmark::State& state) {
16+
static void BM_RegisterAndGetTasks(benchmark::State& state) { // NOLINT
1817
while (state.KeepRunning()) {
1918
auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
2019

fml/message_loop_task_queues_merge_unmerge_unittests.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#define FML_USED_ON_EMBEDDER
76

@@ -16,7 +15,7 @@ class TestWakeable : public fml::Wakeable {
1615
public:
1716
using WakeUpCall = std::function<void(const fml::TimePoint)>;
1817

19-
TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
18+
explicit TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
2019

2120
void WakeUp(fml::TimePoint time_point) override { wake_up_call_(time_point); }
2221

fml/message_loop_task_queues_unittests.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#define FML_USED_ON_EMBEDDER
76

@@ -16,7 +15,7 @@ class TestWakeable : public fml::Wakeable {
1615
public:
1716
using WakeUpCall = std::function<void(const fml::TimePoint)>;
1817

19-
TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
18+
explicit TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
2019

2120
void WakeUp(fml::TimePoint time_point) override { wake_up_call_(time_point); }
2221

fml/message_loop_unittests.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#define FML_USED_ON_EMBEDDER
76

@@ -16,7 +15,7 @@
1615
#include "flutter/fml/task_runner.h"
1716
#include "gtest/gtest.h"
1817

19-
#define TIME_SENSITIVE(x) TimeSensitiveTest_##x
18+
#define TIMESENSITIVE(x) TimeSensitiveTest_##x
2019
#if OS_WIN
2120
#define PLATFORM_SPECIFIC_CAPTURE(...) [ __VA_ARGS__, count ]
2221
#else
@@ -154,7 +153,7 @@ TEST(MessageLoop, CheckRunsTaskOnCurrentThread) {
154153
thread.join();
155154
}
156155

157-
TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) {
156+
TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskByDelta)) {
158157
bool checked = false;
159158
std::thread thread([&checked]() {
160159
fml::MessageLoop::EnsureInitializedForCurrentThread();
@@ -176,7 +175,7 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) {
176175
ASSERT_TRUE(checked);
177176
}
178177

179-
TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) {
178+
TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskForTime)) {
180179
bool checked = false;
181180
std::thread thread([&checked]() {
182181
fml::MessageLoop::EnsureInitializedForCurrentThread();
@@ -198,7 +197,7 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) {
198197
ASSERT_TRUE(checked);
199198
}
200199

201-
TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
200+
TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
202201
const auto count = 10;
203202
int checked = false;
204203
std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() {
@@ -225,7 +224,7 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
225224
ASSERT_EQ(checked, count);
226225
}
227226

228-
TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
227+
TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
229228
const auto count = 10;
230229
int checked = false;
231230
std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() {

0 commit comments

Comments
 (0)