Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ linter:
- prefer_conditional_assignment
- prefer_contains
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
Expand Down
2 changes: 1 addition & 1 deletion app/lib/account/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class AccountBackend {
/// Uses in-memory cache to store entries locally for up to 10 minutes.
Future<List<String?>> getEmailsOfUserIds(List<String> userIds) async {
final result = <String?>[];
for (String userId in userIds) {
for (final userId in userIds) {
result.add(await getEmailOfUserId(userId));
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/account/consent_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ConsentBackend {
Future<void> deleteObsoleteConsents() async {
final query = _db.query<Consent>()
..filter('expires <', clock.now().toUtc());
await for (var entry in query.run()) {
await for (final entry in query.run()) {
try {
await _delete(entry, (a) => a.onExpire(entry));
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/tools/delete_all_staging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Future<void> _batchedQuery<T extends Model>(
budget = _defaultBudget;
}

await for (Model m in query.run()) {
await for (final m in query.run()) {
final size = _estimateSize(m);
if (size * 4 >= _defaultBudget) {
flush();
Expand Down
4 changes: 2 additions & 2 deletions app/lib/frontend/static_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class StaticFileCache {
'/static/css/style.css',
'/static/js/script.dart.js',
};
for (String path in paths) {
for (final path in paths) {
final file = StaticFile(path, 'text/mock', [], clock.now(),
'mocked_hash_${path.hashCode.abs()}');
cache.addFile(file);
Expand Down Expand Up @@ -279,7 +279,7 @@ class StaticUrls {

Future<DateTime> _detectLastModified(Directory dir) async {
DateTime? lastModified;
await for (FileSystemEntity fse in dir.list(recursive: true)) {
await for (final fse in dir.list(recursive: true)) {
if (fse is File) {
final lm = await fse.lastModified();
if (lastModified == null || lastModified.isBefore(lm)) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/frontend/templates/detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ d.Node renderDetailPage({
d.Node? footerNode,
}) {
// active: the first one with content
for (Tab tab in tabs) {
for (final tab in tabs) {
if (tab.contentNode != null) {
tab.isActive = true;
break;
Expand Down
6 changes: 3 additions & 3 deletions app/lib/frontend/templates/views/pkg/info_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ d.Node packageInfoBoxNode({
if (screenshots != null && screenshots.isNotEmpty) {
thumbnailUrl = imageStorage.getImageUrl(
package.name!, version.version!, screenshots.first.webp190Thumbnail);
for (ProcessedScreenshot s in screenshots) {
for (final screenshot in screenshots) {
screenshotUrls.add(imageStorage.getImageUrl(
package.name!, version.version!, s.webpImage));
screenshotDescriptions.add(s.description);
package.name!, version.version!, screenshot.webpImage));
screenshotDescriptions.add(screenshot.description);
}
}
return d.fragment([
Expand Down
7 changes: 3 additions & 4 deletions app/lib/frontend/templates/views/pkg/package_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:_pub_shared/format/x_ago_format.dart';
import 'package:_pub_shared/search/search_form.dart';
import 'package:_pub_shared/search/tags.dart';
import 'package:clock/clock.dart';
import 'package:pana/pana.dart';

import '../../../../package/models.dart';
import '../../../../package/screenshots/backend.dart';
Expand Down Expand Up @@ -148,10 +147,10 @@ d.Node _packageItem(
thumbnailUrl = imageStorage.getImageUrl(
view.name, releases.stable.version, screenshots.first.webp100Thumbnail);

for (ProcessedScreenshot s in screenshots) {
for (final screenshot in screenshots) {
screenshotUrls.add(imageStorage.getImageUrl(
view.name, releases.stable.version, s.webpImage));
screenshotDescriptions.add(s.description);
view.name, releases.stable.version, screenshot.webpImage));
screenshotDescriptions.add(screenshot.description);
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/lib/search/mem_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class InMemoryPackageIndex {
_descrIndex.add(doc.package, doc.description);
_readmeIndex.add(doc.package, doc.readme);

for (ApiDocPage page in doc.apiDocPages ?? const []) {
for (final ApiDocPage page in doc.apiDocPages ?? const []) {
final pageId = _apiDocPageId(doc.package, page);
if (page.symbols != null && page.symbols!.isNotEmpty) {
_apiSymbolIndex.add(pageId, page.symbols!.join(' '));
Expand Down Expand Up @@ -108,10 +108,10 @@ class InMemoryPackageIndex {
packages.removeWhere((package) {
final doc = _packages[package]!;
if (doc.dependencies.isEmpty) return true;
for (String dependency in query.parsedQuery.allDependencies) {
for (final dependency in query.parsedQuery.allDependencies) {
if (!doc.dependencies.containsKey(dependency)) return true;
}
for (String dependency in query.parsedQuery.refDependencies) {
for (final dependency in query.parsedQuery.refDependencies) {
final type = doc.dependencies[dependency];
if (type == null || type == DependencyTypes.transitive) return true;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ class InMemoryPackageIndex {
final phrases = extractExactPhrases(text);
if (!aborted && phrases.isNotEmpty) {
final matched = <String, double>{};
for (String package in score.getKeys()) {
for (final package in score.getKeys()) {
final doc = _packages[package]!;
final bool matchedAllPhrases = phrases.every((phrase) =>
doc.package.contains(phrase) ||
Expand Down
2 changes: 1 addition & 1 deletion app/lib/search/text_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Map<String, double>? tokenize(String? originalText, {bool isSplit = false}) {
final tokens = <String, double>{};

final words = isSplit ? [originalText] : splitForIndexing(originalText);
for (String word in words) {
for (final word in words) {
if (word.length > _maxWordLength) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions app/lib/search/token_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class TokenIndex {
if (tokens == null || tokens.isEmpty) {
return;
}
for (String token in tokens.keys) {
for (final token in tokens.keys) {
final Map<String, double> weights =
_inverseIds.putIfAbsent(token, () => <String, double>{});
weights[id] = math.max(weights[id] ?? 0.0, tokens[token]!);
Expand Down Expand Up @@ -219,8 +219,8 @@ class TokenIndex {
Map<String, double> _scoreDocs(TokenMatch tokenMatch,
{double weight = 1.0, int wordCount = 1, Set<String>? limitToIds}) {
// Summarize the scores for the documents.
final Map<String, double> docScores = <String, double>{};
for (String token in tokenMatch.tokens) {
final docScores = <String, double>{};
for (final token in tokenMatch.tokens) {
final docWeights = _inverseIds[token]!;
for (final e in docWeights.entries) {
if (limitToIds != null && !limitToIds.contains(e.key)) continue;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/shared/datastore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension DatastoreDBExt on DatastoreDB {
final deletes = <T>[];
var found = 0;
var deleted = 0;
await for (T model in query.run()) {
await for (final model in query.run()) {
found++;
if (where == null || await where(model)) {
deletes.add(model);
Expand Down
6 changes: 3 additions & 3 deletions app/lib/shared/integrity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class IntegrityChecker {
}
}

await for (PackageVersionInfo pvi in pviQuery.run()) {
await for (final pvi in pviQuery.run()) {
final key = pvi.qualifiedVersionKey;
pviKeys.add(key);
yield* checkPackageVersionKey('PackageVersionInfo', key);
Expand All @@ -465,7 +465,7 @@ class IntegrityChecker {
referencedAssetIds.add(key.assetId(kind));
}
}
for (QualifiedVersionKey key in qualifiedVersionKeys) {
for (final key in qualifiedVersionKeys) {
if (!pviKeys.contains(key)) {
yield 'PackageVersion "$key" has no PackageVersionInfo.';
}
Expand All @@ -475,7 +475,7 @@ class IntegrityChecker {
final pvaQuery = _db.query<PackageVersionAsset>()
..filter('package =', p.name);
final foundAssetIds = <String?>{};
await for (PackageVersionAsset pva in pvaQuery.run()) {
await for (final pva in pvaQuery.run()) {
final key = pva.qualifiedVersionKey;
if (pva.id !=
Uri(pathSegments: [pva.package!, pva.version!, pva.kind!]).path) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/shared/model_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CompatibleListProperty<T> extends Property {
bool validate(ModelDB db, Object? value) {
if (!super.validate(db, value) || value is! List) return false;

for (var entry in value) {
for (final entry in value) {
if (!subProperty.validate(db, entry)) return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/shared/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class VersionedJsonStorage {
Future<DeleteCounts> deleteOldData({Duration? minAgeThreshold}) async {
var found = 0;
var deleted = 0;
await for (BucketEntry entry in _bucket.list(prefix: _prefix)) {
await for (final entry in _bucket.list(prefix: _prefix)) {
if (entry.isDirectory) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/shared/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ String? getRepositoryUrl(
String branch = 'master',
}) {
if (repository == null || repository.isEmpty) return null;
for (var key in _repositoryReplacePrefixes.keys) {
for (final key in _repositoryReplacePrefixes.keys) {
if (repository!.startsWith(key)) {
repository =
repository.replaceFirst(key, _repositoryReplacePrefixes[key]!);
Expand Down
4 changes: 2 additions & 2 deletions app/test/frontend/handlers/_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ Future<String> expectHtmlResponse(
parseAndValidateHtml(content);
expect(content, contains('<!DOCTYPE html>'));
expect(content, contains('</html>'));
for (Pattern p in present) {
for (final p in present) {
if (p.allMatches(content).isEmpty) {
print(content);
throw Exception('$p is missing from the content.');
}
}
for (Pattern p in absent) {
for (final p in absent) {
if (p.allMatches(content).isNotEmpty) {
throw Exception('$p is present in the content.');
}
Expand Down
2 changes: 1 addition & 1 deletion app/test/frontend/static_files_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void main() {
'/static/material/bundle/script.min.js',
];

for (String file in files) {
for (final file in files) {
final f = cache.getFile(file)!;
expect(f, isNotNull, reason: file);
expect(f.etag.contains('mocked_hash_'), isFalse, reason: file);
Expand Down
2 changes: 1 addition & 1 deletion app/test/search/token_index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void main() {
'location_picker',
'background_location_updates',
];
for (String name in names) {
for (final name in names) {
index.add(name, name);
}
final match = index.search('location');
Expand Down
4 changes: 2 additions & 2 deletions pkg/_pub_shared/lib/validation/html/html_validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void validateHtml(Node root) {

// All <a target="_blank"> links must have rel="noopener"
final links = querySelectorAll('a');
for (Element elem in links) {
for (final elem in links) {
if (elem.attributes['target'] == '_blank') {
if (!elem.attributes.containsKey('rel')) {
throw AssertionError(
Expand Down Expand Up @@ -117,7 +117,7 @@ void validateHtml(Node root) {

// No inline script tag.
final scripts = querySelectorAll('script');
for (Element elem in scripts) {
for (final elem in scripts) {
if (elem.attributes['type'] == 'application/ld+json') {
if (elem.attributes.length != 1) {
throw AssertionError(
Expand Down
2 changes: 1 addition & 1 deletion pkg/_pub_shared/test/search/search_form_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void main() {

group('SearchOrder enum', () {
test('serialization', () {
for (var value in SearchOrder.values) {
for (final value in SearchOrder.values) {
final serialized = value.name;
expect(serialized, isNotEmpty);
final SearchOrder? deserialized = parseSearchOrder(serialized);
Expand Down
6 changes: 3 additions & 3 deletions pkg/code_coverage/lib/format_lcov.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Future main() async {
.where((f) => f is File)
.cast<File>()
.toList();
for (File file in files) {
for (final file in files) {
final coverage = await file.readAsString();
if (coverage.isEmpty) {
print('${file.path} is empty.');
Expand All @@ -35,7 +35,7 @@ Future main() async {
}
}

for (String path in _lineExecCounts.keys) {
for (final path in _lineExecCounts.keys) {
final counts = _lineExecCounts[path];
final total = counts!.length;
final covered = counts.values.where((i) => i > 0).length;
Expand Down Expand Up @@ -66,7 +66,7 @@ Future main() async {
].join(', '));

final keys = _tree.keys.toList()..sort();
for (String key in keys) {
for (final key in keys) {
final entry = _tree[key];
final pctStr = entry!.percentAsString;
final sb = StringBuffer();
Expand Down
2 changes: 1 addition & 1 deletion pkg/code_coverage/lib/generate_all_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ String _generateTestContent(List<String> files) {
final imports = <String>[];
final calls = <String>[];

for (String file in files) {
for (final file in files) {
final alias = file.substring(0, file.length - 10).replaceAll('/', '_');
imports.add("import '$file' as $alias;");
calls.add(" group('$file', $alias.main);");
Expand Down
2 changes: 1 addition & 1 deletion pkg/fake_gcloud/lib/mem_datastore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class MemDatastore implements Datastore {
).toList();
if (query.orders != null && query.orders!.isNotEmpty) {
items.sort((a, b) {
for (Order o in query.orders!) {
for (final o in query.orders!) {
if (a.unIndexedProperties.contains(o.propertyName) ||
b.unIndexedProperties.contains(o.propertyName)) {
throw DatastoreError(
Expand Down
4 changes: 2 additions & 2 deletions pkg/fake_gcloud/lib/mem_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MemStorage implements Storage {

@override
Stream<String> listBucketNames() async* {
for (String name in _buckets.keys) {
for (final name in _buckets.keys) {
yield name;
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ class _Bucket implements Bucket {
final isDirPrefix =
prefix.isEmpty || (delimiter.isNotEmpty && prefix.endsWith(delimiter));
final segments = <String>{};
for (String name in _files.keys) {
for (final name in _files.keys) {
bool matchesPrefix() {
// without prefix, return everything
if (prefix!.isEmpty) return true;
Expand Down
4 changes: 2 additions & 2 deletions pkg/pub_integration/lib/script/dev_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ class DevVersionScript {
{List<Pattern>? present, List<Pattern>? absent}) {
// removing title attributes to keep patterns simple
content = content!.replaceAll(RegExp(' title=".*?"'), '');
for (Pattern p in present ?? []) {
for (final p in present ?? const <Pattern>[]) {
if (p.allMatches(content).isEmpty) {
throw Exception('$p is missing from the content.');
}
}
for (Pattern p in absent ?? []) {
for (final p in absent ?? const <Pattern>[]) {
if (p.allMatches(content).isNotEmpty) {
throw Exception('$p is present in the content.');
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pub_integration/lib/src/test_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TestBrowser {
final binaries = [
'/usr/bin/google-chrome',
];
for (String binary in binaries) {
for (final binary in binaries) {
if (File(binary).existsSync()) return binary;
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/pub_integration/lib/src/test_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Future _copy(String fromDir, String toDir) async {
.where((fse) => fse is File)
.cast<File>()
.toList();
for (File file in files) {
for (final file in files) {
final relativePath = p.relative(file.path, from: fromDir);
final newPath = p.join(toDir, relativePath);
final newFile = File(newPath);
Expand Down
2 changes: 1 addition & 1 deletion pkg/web_app/lib/src/hoverable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Element? _activeHover;
/// Their `:hover` and `.hover` style must match to have the same effect.
void _setEventForHoverable() {
document.body!.onClick.listen(deactivateHover);
for (Element h in document.querySelectorAll('.hoverable')) {
for (final h in document.querySelectorAll('.hoverable')) {
registerHoverable(h);
}
}
Expand Down
Loading
Loading