Skip to content

Commit 4e88f02

Browse files
authored
Remove or simplify usages of late (#8142)
* Remove or simplify usages of late * Add back accidentally removed lint
1 parent 8b58627 commit 4e88f02

File tree

20 files changed

+25
-26
lines changed

20 files changed

+25
-26
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ linter:
7373
- unnecessary_brace_in_string_interps
7474
- unnecessary_const
7575
- unnecessary_getters_setters
76+
- unnecessary_late
7677
- unnecessary_library_name
7778
- unnecessary_library_directive
7879
- unnecessary_new

app/lib/account/consent_backend.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ConsentBackend {
6161
final c = await _lookupAndCheck(consentId, user);
6262
final action = _actions[c.kind]!;
6363
final fromAgent = c.fromAgent!;
64-
late String invitingUserEmail;
64+
final String invitingUserEmail;
6565
if (looksLikeUserId(fromAgent)) {
6666
invitingUserEmail = (await accountBackend.getEmailOfUserId(fromAgent))!;
6767
} else {

app/lib/account/models.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class User extends db.ExpandoModel<String> {
7575
}
7676

7777
late final isVisible = !isBlocked && !isModerated && !isDeleted;
78-
late final isNotVisible = !isVisible;
78+
bool get isNotVisible => !isVisible;
7979

8080
void updateIsModerated({
8181
required bool isModerated,

app/lib/account/session_cookie.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@ class ClientSessionCookieStatus {
101101
required this.isStrict,
102102
});
103103

104-
late final isPresent = sessionId != null && sessionId!.isNotEmpty;
104+
bool get isPresent => sessionId?.isNotEmpty ?? false;
105105
}

app/lib/admin/tools/set_user_blocked.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Future<String> executeSetUserBlocked(List<String> args) async {
1818
final valueAsString = args.length == 2 ? args[1] : null;
1919
final blockedStatus = _parseValue(valueAsString);
2020

21-
late List<User> users;
21+
final List<User> users;
2222
if (isValidEmail(idOrEmail)) {
2323
users = await accountBackend.lookupUsersByEmail(idOrEmail);
2424
} else {

app/lib/fake/backend/fake_auth_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class FakeAuthProvider extends BaseAuthProvider {
101101

102102
@override
103103
Future<AuthResult?> tryAuthenticateAsUser(String input) async {
104-
late String jwtTokenValue;
105104
var accessToken = input;
106105
// TODO: migrate all test to use base64-encoded token
107106
try {
@@ -110,6 +109,7 @@ class FakeAuthProvider extends BaseAuthProvider {
110109
// ignored
111110
}
112111

112+
final String jwtTokenValue;
113113
if (accessToken.contains('-at-') &&
114114
!JsonWebToken.looksLikeJWT(accessToken)) {
115115
final uri = Uri.tryParse(accessToken);

app/lib/fake/backend/fake_pub_worker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Future<void> _fakeAnalysis(Payload payload) async {
113113
total: 20,
114114
);
115115

116-
late Summary summary;
116+
final Summary summary;
117117
if (packageStatus.isObsolete || packageStatus.isLegacy) {
118118
summary = _emptySummary(payload.package, v.version);
119119
dartdocFiles.clear();

app/lib/frontend/handlers/misc.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Future<shelf.Response> readinessCheckHandler(shelf.Request request) async {
7272

7373
/// Handles requests for /topics
7474
Future<shelf.Response> topicsPageHandler(shelf.Request request) async {
75-
late Map<String, int> topics;
75+
Map<String, int>? topics;
7676
try {
7777
final data = await cache.topicsPageData().get(() async {
7878
return await storageService
@@ -83,16 +83,14 @@ Future<shelf.Response> topicsPageHandler(shelf.Request request) async {
8383
topics = (utf8JsonDecoder.convert(data!) as Map<String, dynamic>)
8484
.cast<String, int>();
8585
} on FormatException catch (e, st) {
86-
topics = {};
8786
_log.shout('Error loading topics, error:', e, st);
8887
} on DetailedApiRequestError catch (e, st) {
89-
topics = {};
9088
if (e.status != 404) {
9189
_log.severe('Failed to load topics.json, error : ', e, st);
9290
}
9391
}
9492

95-
return htmlResponse(renderTopicsPage(topics));
93+
return htmlResponse(renderTopicsPage(topics ?? {}));
9694
}
9795

9896
/// Handles requests for /robots.txt

app/lib/frontend/handlers/package.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Future<shelf.Response> _handlePackagePage({
296296
}
297297
}
298298
final serviceSw = Stopwatch()..start();
299-
late PackagePageData data;
299+
final PackagePageData data;
300300
try {
301301
data = await loadPackagePageData(package, versionName, assetKind);
302302
} on ModeratedException {

app/lib/frontend/request_context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class RequestContext {
6262
clientSessionCookieStatus ?? ClientSessionCookieStatus.missing();
6363

6464
late final _isAuthenticated = sessionData?.isAuthenticated ?? false;
65-
late final isNotAuthenticated = !_isAuthenticated;
65+
bool get isNotAuthenticated => !_isAuthenticated;
6666
late final authenticatedUserId =
6767
_isAuthenticated ? sessionData?.userId : null;
6868
}

0 commit comments

Comments
 (0)