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

Commit 7dd092d

Browse files
authored
Enable more linting (#20187)
1 parent d986b8d commit 7dd092d

13 files changed

+158
-121
lines changed

ci/bin/lint.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void main(List<String> arguments) async {
241241
final ProcessPool pool = ProcessPool();
242242

243243
await for (final WorkerJob job in pool.startWorkers(jobs)) {
244-
if (job.result.stdout.isEmpty) {
244+
if (job.result?.stdout.isEmpty ?? true) {
245245
continue;
246246
}
247247
print('❌ Failures for ${job.name}:');

ci/lint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fi
4242

4343
cd "$CI_DIR"
4444
pub get && dart \
45+
--disable-dart-dev \
4546
bin/lint.dart \
4647
--compile-commands="$COMPILE_COMMANDS" \
4748
--repo="$SRC_DIR/flutter" \

runtime/dart_isolate.cc

+10-5
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/runtime/dart_isolate.h"
76

@@ -44,7 +43,7 @@ class DartErrorString {
4443
}
4544
char** error() { return &str_; }
4645
const char* str() const { return str_; }
47-
operator bool() const { return str_ != nullptr; }
46+
explicit operator bool() const { return str_ != nullptr; }
4847

4948
private:
5049
FML_DISALLOW_COPY_AND_ASSIGN(DartErrorString);
@@ -385,7 +384,7 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
385384
if (GetIsolateGroupData().GetChildIsolatePreparer() == nullptr) {
386385
GetIsolateGroupData().SetChildIsolatePreparer(
387386
[buffers = kernel_buffers_](DartIsolate* isolate) {
388-
for (unsigned long i = 0; i < buffers.size(); i++) {
387+
for (uint64_t i = 0; i < buffers.size(); i++) {
389388
bool last_piece = i + 1 == buffers.size();
390389
const std::shared_ptr<const fml::Mapping>& buffer = buffers.at(i);
391390
if (!isolate->PrepareForRunningFromKernel(buffer, last_piece)) {
@@ -676,6 +675,10 @@ Dart_Isolate DartIsolate::DartIsolateGroupCreateCallback(
676675
);
677676
}
678677

678+
if (!parent_isolate_data) {
679+
return nullptr;
680+
}
681+
679682
DartIsolateGroupData& parent_group_data =
680683
(*parent_isolate_data)->GetIsolateGroupData();
681684

@@ -690,7 +693,8 @@ Dart_Isolate DartIsolate::DartIsolateGroupCreateCallback(
690693
parent_group_data.GetIsolateShutdownCallback())));
691694

692695
TaskRunners null_task_runners(advisory_script_uri,
693-
/* platform= */ nullptr, /* raster= */ nullptr,
696+
/* platform= */ nullptr,
697+
/* raster= */ nullptr,
694698
/* ui= */ nullptr,
695699
/* io= */ nullptr);
696700

@@ -732,7 +736,8 @@ bool DartIsolate::DartIsolateInitializeCallback(void** child_callback_data,
732736
Dart_CurrentIsolateGroupData());
733737

734738
TaskRunners null_task_runners((*isolate_group_data)->GetAdvisoryScriptURI(),
735-
/* platform= */ nullptr, /* raster= */ nullptr,
739+
/* platform= */ nullptr,
740+
/* raster= */ nullptr,
736741
/* ui= */ nullptr,
737742
/* io= */ nullptr);
738743

runtime/dart_isolate_unittests.cc

+59-30
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/mapping.h"
76
#include "flutter/fml/synchronization/count_down_latch.h"
@@ -19,7 +18,19 @@
1918
namespace flutter {
2019
namespace testing {
2120

22-
using DartIsolateTest = FixtureTest;
21+
class DartIsolateTest : public FixtureTest {
22+
public:
23+
DartIsolateTest() {}
24+
25+
void Wait() { latch_.Wait(); }
26+
27+
void Signal() { latch_.Signal(); }
28+
29+
private:
30+
fml::AutoResetWaitableEvent latch_;
31+
32+
FML_DISALLOW_COPY_AND_ASSIGN(DartIsolateTest);
33+
};
2334

2435
TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
2536
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
@@ -153,11 +164,10 @@ TEST_F(DartIsolateTest, CanRunDartCodeCodeSynchronously) {
153164

154165
TEST_F(DartIsolateTest, CanRegisterNativeCallback) {
155166
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
156-
fml::AutoResetWaitableEvent latch;
157167
AddNativeCallback("NotifyNative",
158-
CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
168+
CREATE_NATIVE_ENTRY(([this](Dart_NativeArguments args) {
159169
FML_LOG(ERROR) << "Hello from Dart!";
160-
latch.Signal();
170+
Signal();
161171
})));
162172
const auto settings = CreateSettingsForFixture();
163173
auto vm_ref = DartVMRef::Create(settings);
@@ -173,7 +183,7 @@ TEST_F(DartIsolateTest, CanRegisterNativeCallback) {
173183
"canRegisterNativeCallback", {}, GetFixturesPath());
174184
ASSERT_TRUE(isolate);
175185
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
176-
latch.Wait();
186+
Wait();
177187
}
178188

179189
TEST_F(DartIsolateTest, CanSaveCompilationTrace) {
@@ -182,12 +192,11 @@ TEST_F(DartIsolateTest, CanSaveCompilationTrace) {
182192
GTEST_SKIP();
183193
return;
184194
}
185-
fml::AutoResetWaitableEvent latch;
186195
AddNativeCallback("NotifyNative",
187-
CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
196+
CREATE_NATIVE_ENTRY(([this](Dart_NativeArguments args) {
188197
ASSERT_TRUE(tonic::DartConverter<bool>::FromDart(
189198
Dart_GetNativeArgument(args, 0)));
190-
latch.Signal();
199+
Signal();
191200
})));
192201

193202
const auto settings = CreateSettingsForFixture();
@@ -205,31 +214,52 @@ TEST_F(DartIsolateTest, CanSaveCompilationTrace) {
205214
ASSERT_TRUE(isolate);
206215
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
207216

208-
latch.Wait();
217+
Wait();
209218
}
210219

211-
TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) {
212-
fml::CountDownLatch latch(3);
213-
fml::AutoResetWaitableEvent child_shutdown_latch;
214-
fml::AutoResetWaitableEvent root_isolate_shutdown_latch;
220+
class DartSecondaryIsolateTest : public FixtureTest {
221+
public:
222+
DartSecondaryIsolateTest() : latch_(3) {}
223+
224+
void LatchCountDown() { latch_.CountDown(); }
225+
226+
void LatchWait() { latch_.Wait(); }
227+
228+
void ChildShutdownSignal() { child_shutdown_latch_.Signal(); }
229+
230+
void ChildShutdownWait() { child_shutdown_latch_.Wait(); }
231+
232+
void RootIsolateShutdownSignal() { root_isolate_shutdown_latch_.Signal(); }
233+
234+
bool RootIsolateIsSignaled() {
235+
return root_isolate_shutdown_latch_.IsSignaledForTest();
236+
}
237+
238+
private:
239+
fml::CountDownLatch latch_;
240+
fml::AutoResetWaitableEvent child_shutdown_latch_;
241+
fml::AutoResetWaitableEvent root_isolate_shutdown_latch_;
242+
243+
FML_DISALLOW_COPY_AND_ASSIGN(DartSecondaryIsolateTest);
244+
};
245+
246+
TEST_F(DartSecondaryIsolateTest, CanLaunchSecondaryIsolates) {
215247
AddNativeCallback("NotifyNative",
216-
CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
217-
latch.CountDown();
248+
CREATE_NATIVE_ENTRY(([this](Dart_NativeArguments args) {
249+
LatchCountDown();
218250
})));
219251
AddNativeCallback(
220-
"PassMessage", CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
252+
"PassMessage", CREATE_NATIVE_ENTRY(([this](Dart_NativeArguments args) {
221253
auto message = tonic::DartConverter<std::string>::FromDart(
222254
Dart_GetNativeArgument(args, 0));
223255
ASSERT_EQ("Hello from code is secondary isolate.", message);
224-
latch.CountDown();
256+
LatchCountDown();
225257
})));
226258
auto settings = CreateSettingsForFixture();
227-
settings.root_isolate_shutdown_callback = [&root_isolate_shutdown_latch]() {
228-
root_isolate_shutdown_latch.Signal();
229-
};
230-
settings.isolate_shutdown_callback = [&child_shutdown_latch]() {
231-
child_shutdown_latch.Signal();
259+
settings.root_isolate_shutdown_callback = [this]() {
260+
RootIsolateShutdownSignal();
232261
};
262+
settings.isolate_shutdown_callback = [this]() { ChildShutdownSignal(); };
233263
auto vm_ref = DartVMRef::Create(settings);
234264
auto thread = CreateNewThread();
235265
TaskRunners task_runners(GetCurrentTestName(), //
@@ -243,19 +273,18 @@ TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) {
243273
GetFixturesPath());
244274
ASSERT_TRUE(isolate);
245275
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
246-
child_shutdown_latch.Wait(); // wait for child isolate to shutdown first
247-
ASSERT_FALSE(root_isolate_shutdown_latch.IsSignaledForTest());
248-
latch.Wait(); // wait for last NotifyNative called by main isolate
276+
ChildShutdownWait(); // wait for child isolate to shutdown first
277+
ASSERT_FALSE(RootIsolateIsSignaled());
278+
LatchWait(); // wait for last NotifyNative called by main isolate
249279
// root isolate will be auto-shutdown
250280
}
251281

252282
TEST_F(DartIsolateTest, CanRecieveArguments) {
253-
fml::AutoResetWaitableEvent latch;
254283
AddNativeCallback("NotifyNative",
255-
CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
284+
CREATE_NATIVE_ENTRY(([this](Dart_NativeArguments args) {
256285
ASSERT_TRUE(tonic::DartConverter<bool>::FromDart(
257286
Dart_GetNativeArgument(args, 0)));
258-
latch.Signal();
287+
Signal();
259288
})));
260289

261290
const auto settings = CreateSettingsForFixture();
@@ -273,7 +302,7 @@ TEST_F(DartIsolateTest, CanRecieveArguments) {
273302
ASSERT_TRUE(isolate);
274303
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
275304

276-
latch.Wait();
305+
Wait();
277306
}
278307

279308
} // namespace testing

runtime/dart_service_isolate.cc

+1-1
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/runtime/dart_service_isolate.h"
76

@@ -202,6 +201,7 @@ bool DartServiceIsolate::Startup(std::string server_ip,
202201
result = Dart_SetField(
203202
library, Dart_NewStringFromCString("_enableServicePortFallback"),
204203
Dart_NewBoolean(enable_service_port_fallback));
204+
SHUTDOWN_ON_ERROR(result);
205205
return true;
206206
}
207207

runtime/dart_vm.cc

+6-4
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/runtime/dart_vm.h"
76

@@ -129,13 +128,15 @@ bool DartFileModifiedCallback(const char* source_url, int64_t since_ms) {
129128

130129
const char* path = source_url + kFileUriPrefixLength;
131130
struct stat info;
132-
if (stat(path, &info) < 0)
131+
if (stat(path, &info) < 0) {
133132
return true;
133+
}
134134

135135
// If st_mtime is zero, it's more likely that the file system doesn't support
136136
// mtime than that the file was actually modified in the 1970s.
137-
if (!info.st_mtime)
137+
if (!info.st_mtime) {
138138
return true;
139+
}
139140

140141
// It's very unclear what time bases we're with here. The Dart API doesn't
141142
// document the time base for since_ms. Reading the code, the value varies by
@@ -383,8 +384,9 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
383384
PushBackAll(&args, kDartTraceStreamsArgs, fml::size(kDartTraceStreamsArgs));
384385
#endif
385386

386-
for (size_t i = 0; i < settings_.dart_flags.size(); i++)
387+
for (size_t i = 0; i < settings_.dart_flags.size(); i++) {
387388
args.push_back(settings_.dart_flags[i].c_str());
389+
}
388390

389391
char* flags_error = Dart_SetVMFlags(args.size(), args.data());
390392
if (flags_error) {

0 commit comments

Comments
 (0)