enable lint prefer_final_in_for_each (#47724)

This commit is contained in:
Alexandre Ardhuin
2020-01-07 16:32:04 +01:00
committed by GitHub
parent fa337f5922
commit 4f9b6cf017
369 changed files with 1219 additions and 1220 deletions

View File

@@ -57,7 +57,7 @@ Future<void> main(List<String> arguments) async {
// https://github.com/dart-lang/dartdoc/issues/1982
buf.writeln('version: 0.0.0');
buf.writeln('dependencies:');
for (String package in findPackageNames()) {
for (final String package in findPackageNames()) {
buf.writeln(' $package:');
buf.writeln(' sdk: flutter');
}
@@ -72,7 +72,7 @@ Future<void> main(List<String> arguments) async {
libDir.createSync();
final StringBuffer contents = StringBuffer('library temp_doc;\n\n');
for (String libraryRef in libraryRefs()) {
for (final String libraryRef in libraryRefs()) {
contents.writeln('import \'package:$libraryRef\';');
}
File('$kDocsRoot/lib/temp_doc.dart').writeAsStringSync(contents.toString());
@@ -313,7 +313,7 @@ void copyDirectorySync(Directory srcDir, Directory destDir, [void onFileCopied(F
if (!destDir.existsSync())
destDir.createSync(recursive: true);
for (FileSystemEntity entity in srcDir.listSync()) {
for (final FileSystemEntity entity in srcDir.listSync()) {
final String newPath = path.join(destDir.path, path.basename(entity.path));
if (entity is File) {
final File newFile = File(newPath);
@@ -361,7 +361,7 @@ void sanityCheckDocs() {
'$kPublishRoot/api/material/Tooltip-class.html',
'$kPublishRoot/api/widgets/Widget-class.html',
];
for (String canary in canaries) {
for (final String canary in canaries) {
if (!File(canary).existsSync())
throw Exception('Missing "$canary", which probably means the documentation failed to build correctly.');
}
@@ -470,9 +470,9 @@ List<Directory> findPackages() {
/// Returns import or on-disk paths for all libraries in the Flutter SDK.
Iterable<String> libraryRefs() sync* {
for (Directory dir in findPackages()) {
for (final Directory dir in findPackages()) {
final String dirName = path.basename(dir.path);
for (FileSystemEntity file in Directory('${dir.path}/lib').listSync()) {
for (final FileSystemEntity file in Directory('${dir.path}/lib').listSync()) {
if (file is File && file.path.endsWith('.dart')) {
yield '$dirName/${path.basename(file.path)}';
}

View File

@@ -20,7 +20,7 @@ class CodeGenerator {
final StringBuffer result = StringBuffer();
final List<String> words = input.split(RegExp(r'\s+'));
String currentLine = words.removeAt(0);
for (String word in words) {
for (final String word in words) {
if ((currentLine.length + word.length) < wrapWidth) {
currentLine += ' $word';
} else {
@@ -37,7 +37,7 @@ class CodeGenerator {
/// Gets the generated definitions of PhysicalKeyboardKeys.
String get physicalDefinitions {
final StringBuffer definitions = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
final String firstComment = wrapString('Represents the location of the '
'"${entry.commentName}" key on a generalized keyboard.');
final String otherComments = wrapString('See the function '
@@ -73,7 +73,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
}
}
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
printKey(
entry.flutterId,
entry.keyLabel,
@@ -81,7 +81,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
entry.commentName,
);
}
for (String name in Key.synonyms.keys) {
for (final String name in Key.synonyms.keys) {
// Use the first item in the synonyms as a template for the ID to use.
// It won't end up being the same value because it'll be in the pseudo-key
// plane.
@@ -99,8 +99,8 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
String get logicalSynonyms {
final StringBuffer synonyms = StringBuffer();
for (String name in Key.synonyms.keys) {
for (String synonym in Key.synonyms[name].cast<String>()) {
for (final String name in Key.synonyms.keys) {
for (final String synonym in Key.synonyms[name].cast<String>()) {
final String keyName = upperCamelToLowerCamel(synonym);
synonyms.writeln(' $keyName: $name,');
}
@@ -124,7 +124,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of USB HID codes to physical keys.
String get predefinedHidCodeMap {
final StringBuffer scanCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
scanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: ${entry.constantName},');
}
return scanCodeMap.toString().trimRight();
@@ -133,10 +133,10 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// THis generates the map of Flutter key codes to logical keys.
String get predefinedKeyCodeMap {
final StringBuffer keyCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
keyCodeMap.writeln(' ${toHex(entry.flutterId, digits: 10)}: ${entry.constantName},');
}
for (String entry in Key.synonyms.keys) {
for (final String entry in Key.synonyms.keys) {
// Use the first item in the synonyms as a template for the ID to use.
// It won't end up being the same value because it'll be in the pseudo-key
// plane.
@@ -152,9 +152,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of GLFW number pad key codes to logical keys.
String get glfwNumpadMap {
final StringBuffer glfwNumpadMap = StringBuffer();
for (Key entry in numpadKeyData) {
for (final Key entry in numpadKeyData) {
if (entry.glfwKeyCodes != null) {
for (int code in entry.glfwKeyCodes.cast<int>()) {
for (final int code in entry.glfwKeyCodes.cast<int>()) {
glfwNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
}
}
@@ -165,9 +165,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of GLFW key codes to logical keys.
String get glfwKeyCodeMap {
final StringBuffer glfwKeyCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.glfwKeyCodes != null) {
for (int code in entry.glfwKeyCodes.cast<int>()) {
for (final int code in entry.glfwKeyCodes.cast<int>()) {
glfwKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
}
}
@@ -178,7 +178,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of XKB USB HID codes to physical keys.
String get xkbScanCodeMap {
final StringBuffer xkbScanCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.xKbScanCode != null) {
xkbScanCodeMap.writeln(' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
}
@@ -189,9 +189,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Android key codes to logical keys.
String get androidKeyCodeMap {
final StringBuffer androidKeyCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.androidKeyCodes != null) {
for (int code in entry.androidKeyCodes.cast<int>()) {
for (final int code in entry.androidKeyCodes.cast<int>()) {
androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
}
}
@@ -202,9 +202,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Android number pad key codes to logical keys.
String get androidNumpadMap {
final StringBuffer androidKeyCodeMap = StringBuffer();
for (Key entry in numpadKeyData) {
for (final Key entry in numpadKeyData) {
if (entry.androidKeyCodes != null) {
for (int code in entry.androidKeyCodes.cast<int>()) {
for (final int code in entry.androidKeyCodes.cast<int>()) {
androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
}
}
@@ -215,9 +215,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Android scan codes to physical keys.
String get androidScanCodeMap {
final StringBuffer androidScanCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.androidScanCodes != null) {
for (int code in entry.androidScanCodes.cast<int>()) {
for (final int code in entry.androidScanCodes.cast<int>()) {
androidScanCodeMap.writeln(' $code: PhysicalKeyboardKey.${entry.constantName},');
}
}
@@ -228,7 +228,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of macOS key codes to physical keys.
String get macOsScanCodeMap {
final StringBuffer macOsScanCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.macOsScanCode != null) {
macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
}
@@ -239,7 +239,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of macOS number pad key codes to logical keys.
String get macOsNumpadMap {
final StringBuffer macOsNumPadMap = StringBuffer();
for (Key entry in numpadKeyData) {
for (final Key entry in numpadKeyData) {
if (entry.macOsScanCode != null) {
macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},');
}
@@ -249,7 +249,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
String get macOsFunctionKeyMap {
final StringBuffer macOsFunctionKeyMap = StringBuffer();
for (Key entry in functionKeyData) {
for (final Key entry in functionKeyData) {
if (entry.macOsScanCode != null) {
macOsFunctionKeyMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},');
}
@@ -260,7 +260,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Fuchsia key codes to logical keys.
String get fuchsiaKeyCodeMap {
final StringBuffer fuchsiaKeyCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.usbHidCode != null) {
fuchsiaKeyCodeMap.writeln(' ${toHex(entry.flutterId)}: LogicalKeyboardKey.${entry.constantName},');
}
@@ -271,7 +271,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Fuchsia USB HID codes to physical keys.
String get fuchsiaHidCodeMap {
final StringBuffer fuchsiaScanCodeMap = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.usbHidCode != null) {
fuchsiaScanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: PhysicalKeyboardKey.${entry.constantName},');
}
@@ -282,7 +282,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Web KeyboardEvent codes to logical keys.
String get webLogicalKeyMap {
final StringBuffer result = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.name != null) {
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
}
@@ -293,7 +293,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Web KeyboardEvent codes to physical keys.
String get webPhysicalKeyMap {
final StringBuffer result = StringBuffer();
for (Key entry in keyData.data) {
for (final Key entry in keyData.data) {
if (entry.name != null) {
result.writeln(" '${entry.name}': PhysicalKeyboardKey.${entry.constantName},");
}
@@ -304,7 +304,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
/// This generates the map of Web number pad codes to logical keys.
String get webNumpadMap {
final StringBuffer result = StringBuffer();
for (Key entry in numpadKeyData) {
for (final Key entry in numpadKeyData) {
if (entry.name != null) {
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
}
@@ -359,7 +359,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
static String _injectDictionary(String template, Map<String, String> dictionary) {
String result = template;
for (String key in dictionary.keys) {
for (final String key in dictionary.keys) {
result = result.replaceAll('@@@$key@@@', dictionary[key]);
}
return result;

View File

@@ -53,18 +53,18 @@ class KeyData {
/// Parses the given JSON data and populates the data structure from it.
KeyData.fromJson(Map<String, dynamic> contentMap) {
data = <Key>[
for (String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key] as Map<String, List<dynamic>>),
for (final String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key] as Map<String, List<dynamic>>),
];
}
/// Converts the data structure into a JSON structure that can be parsed by
/// [KeyData.fromJson].
Map<String, dynamic> toJson() {
for (Key entry in data) {
for (final Key entry in data) {
// Android Key names
entry.androidKeyNames = _nameToAndroidName[entry.constantName]?.cast<String>();
if (entry.androidKeyNames != null && entry.androidKeyNames.isNotEmpty) {
for (String androidKeyName in entry.androidKeyNames) {
for (final String androidKeyName in entry.androidKeyNames) {
if (_nameToAndroidKeyCode[androidKeyName] != null) {
entry.androidKeyCodes ??= <int>[];
entry.androidKeyCodes.add(_nameToAndroidKeyCode[androidKeyName]);
@@ -79,7 +79,7 @@ class KeyData {
// GLFW key names
entry.glfwKeyNames = _nameToGlfwName[entry.constantName]?.cast<String>();
if (entry.glfwKeyNames != null && entry.glfwKeyNames.isNotEmpty) {
for (String glfwKeyName in entry.glfwKeyNames) {
for (final String glfwKeyName in entry.glfwKeyNames) {
if (_nameToGlfwKeyCode[glfwKeyName] != null) {
entry.glfwKeyCodes ??= <int>[];
entry.glfwKeyCodes.add(_nameToGlfwKeyCode[glfwKeyName]);
@@ -89,7 +89,7 @@ class KeyData {
}
final Map<String, dynamic> outputMap = <String, dynamic>{};
for (Key entry in data) {
for (final Key entry in data) {
outputMap[entry.constantName] = entry.toJson();
}
return outputMap;
@@ -178,7 +178,7 @@ class KeyData {
headerFile = headerFile.replaceAllMapped(enumBlock, (Match match) => match.group(1));
final RegExp enumEntry = RegExp(r'''AKEYCODE_([A-Z0-9_]+)\s*=\s*([0-9]+),?''');
final Map<String, int> result = <String, int>{};
for (Match match in enumEntry.allMatches(headerFile)) {
for (final Match match in enumEntry.allMatches(headerFile)) {
result[match.group(1)] = int.parse(match.group(2));
}
return result;
@@ -193,7 +193,7 @@ class KeyData {
// Only get the KEY definitions, ignore the rest (mouse, joystick, etc).
final RegExp enumEntry = RegExp(r'''define GLFW_KEY_([A-Z0-9_]+)\s*([A-Z0-9_]+),?''');
final Map<String, dynamic> replaced = <String, dynamic>{};
for (Match match in enumEntry.allMatches(headerFile)) {
for (final Match match in enumEntry.allMatches(headerFile)) {
replaced[match.group(1)] = int.tryParse(match.group(2)) ?? match.group(2).replaceAll('GLFW_KEY_', '');
}
final Map<String, int> result = <String, int>{};

View File

@@ -56,7 +56,7 @@ Future<void> generateDocs(String url, String docName, String checkFile) async {
print('Extracting $docName to ${output.path}');
output.createSync(recursive: true);
for (ArchiveFile af in archive) {
for (final ArchiveFile af in archive) {
if (!af.name.endsWith('/')) {
final File file = File('${output.path}/${af.name}');
file.createSync(recursive: true);

View File

@@ -36,7 +36,7 @@ Map<String, dynamic> loadBundle(File file) {
}
void encodeBundleTranslations(Map<String, dynamic> bundle) {
for (String key in bundle.keys) {
for (final String key in bundle.keys) {
// The ARB file resource "attributes" for foo are called @foo. Don't need
// to encode them.
if (key.startsWith('@'))
@@ -54,7 +54,7 @@ void encodeBundleTranslations(Map<String, dynamic> bundle) {
void checkEncodedTranslations(Map<String, dynamic> encodedBundle, Map<String, dynamic> bundle) {
bool errorFound = false;
const JsonDecoder decoder = JsonDecoder();
for (String key in bundle.keys) {
for (final String key in bundle.keys) {
if (decoder.convert('"${encodedBundle[key]}"') != bundle[key]) {
stderr.writeln(' encodedTranslation for $key does not match original value "${bundle[key]}"');
errorFound = true;
@@ -67,7 +67,7 @@ void checkEncodedTranslations(Map<String, dynamic> encodedBundle, Map<String, dy
void rewriteBundle(File file, Map<String, dynamic> bundle) {
final StringBuffer contents = StringBuffer();
contents.writeln('{');
for (String key in bundle.keys) {
for (final String key in bundle.keys) {
contents.writeln(' "$key": "${bundle[key]}"${key == bundle.keys.last ? '' : ','}');
}
contents.writeln('}');

View File

@@ -167,7 +167,7 @@ Set<String> _supportedLocales() {
final Set<String> supportedLocales = <String>{};
final RegExp filenameRE = RegExp(r'(?:material|cupertino)_(\w+)\.arb$');
final Directory supportedLocalesDirectory = Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
for (FileSystemEntity entity in supportedLocalesDirectory.listSync()) {
for (final FileSystemEntity entity in supportedLocalesDirectory.listSync()) {
final String filePath = entity.path;
if (FileSystemEntity.isFileSync(filePath) && filenameRE.hasMatch(filePath))
supportedLocales.add(filenameRE.firstMatch(filePath)[1]);
@@ -181,7 +181,7 @@ Map<String, File> _listIntlData(Directory directory) {
.listSync()
.whereType<File>()
.where((File file) => file.path.endsWith('.json'));
for (File file in files) {
for (final File file in files) {
final String locale = path.basenameWithoutExtension(file.path);
localeFiles[locale] = file;
}

View File

@@ -87,7 +87,7 @@ String generateArbBasedLocalizationSubclasses({
// Used to calculate if there are any corresponding countries for a given language and script.
final Map<LocaleInfo, Set<String>> languageAndScriptToCountryCodes = <LocaleInfo, Set<String>>{};
final Set<String> allResourceIdentifiers = <String>{};
for (LocaleInfo locale in localeToResources.keys.toList()..sort()) {
for (final LocaleInfo locale in localeToResources.keys.toList()..sort()) {
if (locale.scriptCode != null) {
languageToScriptCodes[locale.languageCode] ??= <String>{};
languageToScriptCodes[locale.languageCode].add(locale.scriptCode);
@@ -129,13 +129,13 @@ String generateArbBasedLocalizationSubclasses({
final List<String> allKeys = allResourceIdentifiers.toList()..sort();
final List<String> languageCodes = languageToLocales.keys.toList()..sort();
final LocaleInfo canonicalLocale = LocaleInfo.fromString('en');
for (String languageName in languageCodes) {
for (final String languageName in languageCodes) {
final LocaleInfo languageLocale = LocaleInfo.fromString(languageName);
output.writeln(generateClassDeclaration(languageLocale, generatedClassPrefix, baseClass));
output.writeln(generateConstructor(languageLocale));
final Map<String, String> languageResources = localeToResources[languageLocale];
for (String key in allKeys) {
for (final String key in allKeys) {
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
output.writeln(generateGetter(key, languageResources[key], attributes, languageLocale));
}
@@ -146,7 +146,7 @@ String generateArbBasedLocalizationSubclasses({
scriptCodeCount = languageToScriptCodes[languageName].length;
// Language has scriptCodes, so we need to properly fallback countries to corresponding
// script default values before language default values.
for (String scriptCode in languageToScriptCodes[languageName]) {
for (final String scriptCode in languageToScriptCodes[languageName]) {
final LocaleInfo scriptBaseLocale = LocaleInfo.fromString(languageName + '_' + scriptCode);
output.writeln(generateClassDeclaration(
scriptBaseLocale,
@@ -155,7 +155,7 @@ String generateArbBasedLocalizationSubclasses({
));
output.writeln(generateConstructor(scriptBaseLocale));
final Map<String, String> scriptResources = localeToResources[scriptBaseLocale];
for (String key in scriptResources.keys.toList()..sort()) {
for (final String key in scriptResources.keys.toList()..sort()) {
if (languageResources[key] == scriptResources[key])
continue;
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
@@ -164,7 +164,7 @@ String generateArbBasedLocalizationSubclasses({
output.writeln('}');
final List<LocaleInfo> localeCodes = languageToLocales[languageName]..sort();
for (LocaleInfo locale in localeCodes) {
for (final LocaleInfo locale in localeCodes) {
if (locale.originalString == languageName)
continue;
if (locale.originalString == languageName + '_' + scriptCode)
@@ -179,7 +179,7 @@ String generateArbBasedLocalizationSubclasses({
));
output.writeln(generateConstructor(locale));
final Map<String, String> localeResources = localeToResources[locale];
for (String key in localeResources.keys) {
for (final String key in localeResources.keys) {
// When script fallback contains the key, we compare to it instead of language fallback.
if (scriptResources.containsKey(key) ? scriptResources[key] == localeResources[key] : languageResources[key] == localeResources[key])
continue;
@@ -193,7 +193,7 @@ String generateArbBasedLocalizationSubclasses({
// No scriptCode. Here, we do not compare against script default (because it
// doesn't exist).
final List<LocaleInfo> localeCodes = languageToLocales[languageName]..sort();
for (LocaleInfo locale in localeCodes) {
for (final LocaleInfo locale in localeCodes) {
if (locale.originalString == languageName)
continue;
countryCodeCount += 1;
@@ -204,7 +204,7 @@ String generateArbBasedLocalizationSubclasses({
'$generatedClassPrefix${camelCase(languageLocale)}',
));
output.writeln(generateConstructor(locale));
for (String key in localeResources.keys) {
for (final String key in localeResources.keys) {
if (languageResources[key] == localeResources[key])
continue;
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
@@ -262,7 +262,7 @@ $supportedLocales/// {@endtemplate}
/// [$baseClass.delegate].
$factoryDeclaration
switch (locale.languageCode) {''');
for (String language in languageToLocales.keys) {
for (final String language in languageToLocales.keys) {
// Only one instance of the language.
if (languageToLocales[language].length == 1) {
output.writeln('''
@@ -272,7 +272,7 @@ $factoryDeclaration
output.writeln('''
case '$language': {
switch (locale.countryCode) {''');
for (LocaleInfo locale in languageToLocales[language]) {
for (final LocaleInfo locale in languageToLocales[language]) {
if (locale.originalString == language)
continue;
assert(locale.length > 1);
@@ -290,14 +290,14 @@ $factoryDeclaration
output.writeln('''
case '$language': {
switch (locale.scriptCode) {''');
for (String scriptCode in languageToScriptCodes[language]) {
for (final String scriptCode in languageToScriptCodes[language]) {
final LocaleInfo scriptLocale = LocaleInfo.fromString(language + '_' + scriptCode);
output.writeln('''
case '$scriptCode': {''');
if (languageAndScriptToCountryCodes.containsKey(scriptLocale)) {
output.writeln('''
switch (locale.countryCode) {''');
for (LocaleInfo locale in languageToLocales[language]) {
for (final LocaleInfo locale in languageToLocales[language]) {
if (locale.countryCode == null)
continue;
else
@@ -326,7 +326,7 @@ $factoryDeclaration
} else {
// Not Explicitly defined, fallback to first locale with the same language and
// script:
for (LocaleInfo locale in languageToLocales[language]) {
for (final LocaleInfo locale in languageToLocales[language]) {
if (locale.scriptCode != scriptCode)
continue;
if (languageAndScriptToCountryCodes.containsKey(scriptLocale)) {
@@ -345,7 +345,7 @@ $factoryDeclaration
if (hasCountryCode) {
output.writeln('''
switch (locale.countryCode) {''');
for (LocaleInfo locale in languageToLocales[language]) {
for (final LocaleInfo locale in languageToLocales[language]) {
if (locale.originalString == language)
continue;
assert(locale.length > 1);

View File

@@ -270,7 +270,7 @@ String generateDateFormattingLogic(Map<String, dynamic> bundle, String key) {
final Map<String, dynamic> attributesMap = bundle['@$key'] as Map<String, dynamic>;
if (attributesMap != null && attributesMap.containsKey('placeholders')) {
final Map<String, dynamic> placeholders = attributesMap['placeholders'] as Map<String, dynamic>;
for (String placeholder in placeholders.keys) {
for (final String placeholder in placeholders.keys) {
final dynamic value = placeholders[placeholder];
if (
value is Map<String, dynamic> &&
@@ -302,7 +302,7 @@ List<String> genIntlMethodArgs(Map<String, dynamic> bundle, String key) {
final Map<String, dynamic> placeholders = attributesMap['placeholders'] as Map<String, dynamic>;
if (placeholders.isNotEmpty) {
final List<String> argumentList = <String>[];
for (String placeholder in placeholders.keys) {
for (final String placeholder in placeholders.keys) {
final dynamic value = placeholders[placeholder];
if (
value is Map<String, dynamic> &&
@@ -328,7 +328,7 @@ String genSimpleMethod(Map<String, dynamic> bundle, String key) {
String message = bundle[key] as String;
final Map<String, dynamic> attributesMap = bundle['@$key'] as Map<String, dynamic>;
final Map<String, dynamic> placeholders = attributesMap['placeholders'] as Map<String, dynamic>;
for (String placeholder in placeholders.keys) {
for (final String placeholder in placeholders.keys) {
final dynamic value = placeholders[placeholder];
if (value is Map<String, dynamic> && _isDateParameter(value)) {
message = message.replaceAll('{$placeholder}', '\$${placeholder}String');
@@ -388,7 +388,7 @@ String genPluralMethod(Map<String, dynamic> arbBundle, String resourceId) {
// To make it easier to parse the plurals message, temporarily replace each
// "{placeholder}" parameter with "#placeholder#".
String message = arbBundle[resourceId] as String;
for (String placeholder in placeholders)
for (final String placeholder in placeholders)
message = message.replaceAll('{$placeholder}', '#$placeholder#');
final Map<String, String> pluralIds = <String, String>{
@@ -406,12 +406,12 @@ String genPluralMethod(Map<String, dynamic> arbBundle, String resourceId) {
...genIntlMethodArgs(arbBundle, resourceId),
];
for (String pluralKey in pluralIds.keys) {
for (final String pluralKey in pluralIds.keys) {
final RegExp expRE = RegExp('($pluralKey){([^}]+)}');
final RegExpMatch match = expRE.firstMatch(message);
if (match != null && match.groupCount == 2) {
String argValue = match.group(2);
for (String placeholder in placeholders) {
for (final String placeholder in placeholders) {
final dynamic value = placeholdersMap[placeholder];
if (value is Map<String, dynamic> && _isDateParameter(value)) {
argValue = argValue.replaceAll('#$placeholder#', '\$${placeholder}String');
@@ -435,7 +435,7 @@ String genSupportedLocaleProperty(Set<LocaleInfo> supportedLocales) {
const String suffix = '),\n ];';
String resultingProperty = prefix;
for (LocaleInfo locale in supportedLocales) {
for (final LocaleInfo locale in supportedLocales) {
final String languageCode = locale.languageCode;
final String countryCode = locale.countryCode;
@@ -668,7 +668,7 @@ class LocalizationsGenerator {
.toList();
final List<LocaleInfo> localeInfoList = <LocaleInfo>[];
for (File file in fileSystemEntityList) {
for (final File file in fileSystemEntityList) {
final String filePath = file.path;
if (arbFilenameRE.hasMatch(filePath)) {
final Map<String, dynamic> arbContents = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
@@ -705,7 +705,7 @@ class LocalizationsGenerator {
}));
if (preferredSupportedLocales != null) {
for (LocaleInfo preferredLocale in preferredSupportedLocales) {
for (final LocaleInfo preferredLocale in preferredSupportedLocales) {
if (!localeInfoList.contains(preferredLocale)) {
throw L10nException(
'The preferred supported locale, \'$preferredLocale\', cannot be '
@@ -750,7 +750,7 @@ class LocalizationsGenerator {
}
final List<String> sortedArbKeys = bundle.keys.toList()..sort();
for (String key in sortedArbKeys) {
for (final String key in sortedArbKeys) {
if (key.startsWith('@'))
continue;
if (!_isValidGetterAndMethodName(key))

View File

@@ -155,7 +155,7 @@ void loadMatchingArbsIntoBundleMaps({
/// overwrite the existing assumed data.
final Set<LocaleInfo> assumedLocales = <LocaleInfo>{};
for (FileSystemEntity entity in directory.listSync().toList()..sort(sortFilesByPath)) {
for (final FileSystemEntity entity in directory.listSync().toList()..sort(sortFilesByPath)) {
final String entityPath = entity.path;
if (FileSystemEntity.isFileSync(entityPath) && filenamePattern.hasMatch(entityPath)) {
final String localeString = filenamePattern.firstMatch(entityPath)[1];
@@ -166,7 +166,7 @@ void loadMatchingArbsIntoBundleMaps({
final Map<String, String> resources = localeToResources[locale];
final Map<String, dynamic> attributes = localeToResourceAttributes[locale];
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
for (String key in bundle.keys) {
for (final String key in bundle.keys) {
// The ARB file resource "attributes" for foo are called @foo.
if (key.startsWith('@'))
attributes[key.substring(1)] = bundle[key];
@@ -270,7 +270,7 @@ const String registry = 'https://www.iana.org/assignments/language-subtag-regist
Map<String, List<String>> _parseSection(String section) {
final Map<String, List<String>> result = <String, List<String>>{};
List<String> lastHeading;
for (String line in section.split('\n')) {
for (final String line in section.split('\n')) {
if (line == '')
continue;
if (line.startsWith(' ')) {
@@ -304,7 +304,7 @@ Future<void> precacheLanguageAndRegionTags() async {
final String body = (await response.cast<List<int>>().transform<String>(utf8.decoder).toList()).join('');
client.close(force: true);
final List<Map<String, List<String>>> sections = body.split('%%').skip(1).map<Map<String, List<String>>>(_parseSection).toList();
for (Map<String, List<String>> section in sections) {
for (final Map<String, List<String>> section in sections) {
assert(section.containsKey('Type'), section.toString());
final String type = section['Type'].single;
if (type == 'language' || type == 'region' || type == 'script') {

View File

@@ -38,7 +38,7 @@ void validateEnglishLocalizations(File file) {
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
for (String resourceId in bundle.keys) {
for (final String resourceId in bundle.keys) {
if (resourceId.startsWith('@'))
continue;
@@ -55,7 +55,7 @@ void validateEnglishLocalizations(File file) {
errorMessages.writeln('A value was not specified for @$resourceId');
}
for (String atResourceId in bundle.keys) {
for (final String atResourceId in bundle.keys) {
if (!atResourceId.startsWith('@'))
continue;

View File

@@ -134,7 +134,7 @@ void _copy(Directory source, Directory target) {
if (!target.existsSync())
target.createSync(recursive: true);
for (FileSystemEntity entity in source.listSync(followLinks: false)) {
for (final FileSystemEntity entity in source.listSync(followLinks: false)) {
final String name = path.basename(entity.path);
if (entity is Directory) {
@@ -165,7 +165,7 @@ class SourceStats {
SourceStats getStatsFor(Directory dir, [SourceStats stats]) {
stats ??= SourceStats();
for (FileSystemEntity entity in dir.listSync(recursive: false, followLinks: false)) {
for (final FileSystemEntity entity in dir.listSync(recursive: false, followLinks: false)) {
final String name = path.basename(entity.path);
if (entity is File && name.endsWith('.dart')) {
stats.files += 1;

View File

@@ -182,7 +182,7 @@ void main(List<String> args) {
String regenerateIconsFile(String iconData, String codepointData) {
final StringBuffer buf = StringBuffer();
bool generating = false;
for (String line in LineSplitter.split(iconData)) {
for (final String line in LineSplitter.split(iconData)) {
if (!generating)
buf.writeln(line);
if (line.contains(kBeginGeneratedMark)) {

View File

@@ -65,7 +65,7 @@ void main(List<String> args) {
}
final List<FrameData> frames = <FrameData>[
for (String filePath in argResults.rest) interpretSvg(filePath),
for (final String filePath in argResults.rest) interpretSvg(filePath),
];
final StringBuffer generatedSb = StringBuffer();

View File

@@ -59,7 +59,7 @@ class Animation {
sb.write('const $className $varName = const $className(\n');
sb.write('${kIndent}const Size(${size.x}, ${size.y}),\n');
sb.write('${kIndent}const <_PathFrames>[\n');
for (PathAnimation path in paths)
for (final PathAnimation path in paths)
sb.write(path.toDart());
sb.write('$kIndent],\n');
sb.write(');');
@@ -117,11 +117,11 @@ class PathAnimation {
final StringBuffer sb = StringBuffer();
sb.write('${kIndent * 2}const _PathFrames(\n');
sb.write('${kIndent * 3}opacities: const <double>[\n');
for (double opacity in opacities)
for (final double opacity in opacities)
sb.write('${kIndent * 4}$opacity,\n');
sb.write('${kIndent * 3}],\n');
sb.write('${kIndent * 3}commands: const <_PathCommand>[\n');
for (PathCommandAnimation command in commands)
for (final PathCommandAnimation command in commands)
sb.write(command.toDart());
sb.write('${kIndent * 3}],\n');
sb.write('${kIndent * 2}),\n');
@@ -166,9 +166,9 @@ class PathCommandAnimation {
}
final StringBuffer sb = StringBuffer();
sb.write('${kIndent * 4}const $dartCommandClass(\n');
for (List<Point<double>> pointFrames in points) {
for (final List<Point<double>> pointFrames in points) {
sb.write('${kIndent * 5}const <Offset>[\n');
for (Point<double> point in pointFrames)
for (final Point<double> point in pointFrames)
sb.write('${kIndent * 6}const Offset(${point.x}, ${point.y}),\n');
sb.write('${kIndent * 5}],\n');
}
@@ -201,7 +201,7 @@ FrameData interpretSvg(String svgFilePath) {
List<SvgPath> _interpretSvgGroup(List<XmlNode> children, _Transform transform) {
final List<SvgPath> paths = <SvgPath>[];
for (XmlNode node in children) {
for (final XmlNode node in children) {
if (node.nodeType != XmlNodeType.ELEMENT)
continue;
final XmlElement element = node as XmlElement;
@@ -304,7 +304,7 @@ class SvgPath {
final SvgPathCommandBuilder commandsBuilder = SvgPathCommandBuilder();
if (!_pathCommandValidator.hasMatch(dAttr))
throw Exception('illegal or unsupported path d expression: $dAttr');
for (Match match in _pathCommandMatcher.allMatches(dAttr)) {
for (final Match match in _pathCommandMatcher.allMatches(dAttr)) {
final String commandType = match.group(1);
final String pointStr = match.group(2);
commands.add(commandsBuilder.build(commandType, parsePoints(pointStr)));
@@ -469,7 +469,7 @@ Matrix3 _parseSvgTransform(String transform) {
throw Exception('illegal or unsupported transform: $transform');
final Iterable<Match> matches =_transformCommand.allMatches(transform).toList().reversed;
Matrix3 result = Matrix3.identity();
for (Match m in matches) {
for (final Match m in matches) {
final String command = m.group(1);
final String params = m.group(2);
if (command == 'translate') {