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

@@ -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;