implicit-casts:false in dev (#45787)

This commit is contained in:
Alexandre Ardhuin
2019-12-05 22:34:06 +01:00
committed by GitHub
parent fa0c49d775
commit ec1a015045
68 changed files with 411 additions and 396 deletions

View File

@@ -32,7 +32,7 @@ import 'localizations_utils.dart';
Map<String, dynamic> loadBundle(File file) {
if (!FileSystemEntity.isFileSync(file.path))
exitWithError('Unable to find input file: ${file.path}');
return json.decode(file.readAsStringSync());
return json.decode(file.readAsStringSync()) as Map<String, dynamic>;
}
void encodeBundleTranslations(Map<String, dynamic> bundle) {
@@ -41,7 +41,7 @@ void encodeBundleTranslations(Map<String, dynamic> bundle) {
// to encode them.
if (key.startsWith('@'))
continue;
final String translation = bundle[key];
final String translation = bundle[key] as String;
// Rewrite the string as a series of unicode characters in JSON format.
// Like "\u0012\u0123\u1234".
bundle[key] = translation.runes.map((int code) {

View File

@@ -108,7 +108,7 @@ Future<void> main(List<String> rawArgs) async {
buffer.writeln('const Map<String, Map<String, String>> datePatterns = <String, Map<String, String>> {');
patternFiles.forEach((String locale, File data) {
if (_supportedLocales().contains(locale)) {
final Map<String, dynamic> patterns = json.decode(data.readAsStringSync());
final Map<String, dynamic> patterns = json.decode(data.readAsStringSync()) as Map<String, dynamic>;
buffer.writeln("'$locale': <String, String>{");
patterns.forEach((String key, dynamic value) {
assert(value is String);
@@ -177,12 +177,13 @@ Set<String> _supportedLocales() {
Map<String, File> _listIntlData(Directory directory) {
final Map<String, File> localeFiles = <String, File>{};
for (FileSystemEntity entity in directory.listSync()) {
final String filePath = entity.path;
if (FileSystemEntity.isFileSync(filePath) && filePath.endsWith('.json')) {
final String locale = path.basenameWithoutExtension(filePath);
localeFiles[locale] = entity;
}
final Iterable<File> files = directory
.listSync()
.whereType<File>()
.where((File file) => file.path.endsWith('.json'));
for (File file in files) {
final String locale = path.basenameWithoutExtension(file.path);
localeFiles[locale] = file;
}
final List<String> locales = localeFiles.keys.toList(growable: false);

View File

@@ -154,9 +154,9 @@ int sortFilesByPath (FileSystemEntity a, FileSystemEntity b) {
}
List<String> genMethodParameters(Map<String, dynamic> bundle, String key, String type) {
final Map<String, dynamic> attributesMap = bundle['@$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'];
final Map<String, dynamic> placeholders = attributesMap['placeholders'] as Map<String, dynamic>;
return placeholders.keys.map((String parameter) => '$type $parameter').toList();
}
return <String>[];
@@ -164,14 +164,14 @@ List<String> genMethodParameters(Map<String, dynamic> bundle, String key, String
List<String> genIntlMethodArgs(Map<String, dynamic> bundle, String key) {
final List<String> attributes = <String>['name: \'$key\''];
final Map<String, dynamic> attributesMap = bundle['@$key'];
final Map<String, dynamic> attributesMap = bundle['@$key'] as Map<String, dynamic>;
if (attributesMap != null) {
if (attributesMap.containsKey('description')) {
final String description = attributesMap['description'];
final String description = attributesMap['description'] as String;
attributes.add('desc: ${generateString(description)}');
}
if (attributesMap.containsKey('placeholders')) {
final Map<String, dynamic> placeholders = attributesMap['placeholders'];
final Map<String, dynamic> placeholders = attributesMap['placeholders'] as Map<String, dynamic>;
if (placeholders.isNotEmpty) {
final String args = placeholders.keys.join(', ');
attributes.add('args: <Object>[$args]');
@@ -183,15 +183,15 @@ List<String> genIntlMethodArgs(Map<String, dynamic> bundle, String key) {
String genSimpleMethod(Map<String, dynamic> bundle, String key) {
String genSimpleMethodMessage(Map<String, dynamic> bundle, String key) {
String message = bundle[key];
final Map<String, dynamic> attributesMap = bundle['@$key'];
final Map<String, dynamic> placeholders = attributesMap['placeholders'];
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)
message = message.replaceAll('{$placeholder}', '\$$placeholder');
return generateString(message);
}
final Map<String, dynamic> attributesMap = bundle['@$key'];
final Map<String, dynamic> attributesMap = bundle['@$key'] as Map<String, dynamic>;
if (attributesMap == null)
exitWithError(
'Resource attribute "@$key" was not found. Please ensure that each '
@@ -208,18 +208,18 @@ String genSimpleMethod(Map<String, dynamic> bundle, String key) {
return getterMethodTemplate
.replaceAll('@methodName', key)
.replaceAll('@message', '${generateString(bundle[key])}')
.replaceAll('@message', '${generateString(bundle[key] as String)}')
.replaceAll('@intlMethodArgs', genIntlMethodArgs(bundle, key).join(',\n '));
}
String genPluralMethod(Map<String, dynamic> bundle, String key) {
final Map<String, dynamic> attributesMap = bundle['@$key'];
final Map<String, dynamic> attributesMap = bundle['@$key'] as Map<String, dynamic>;
assert(attributesMap != null && attributesMap.containsKey('placeholders'));
final Iterable<String> placeholders = attributesMap['placeholders'].keys;
final Iterable<String> placeholders = attributesMap['placeholders'].keys as Iterable<String>;
// To make it easier to parse the plurals message, temporarily replace each
// "{placeholder}" parameter with "#placeholder#".
String message = bundle[key];
String message = bundle[key] as String;
for (String placeholder in placeholders)
message = message.replaceAll('{$placeholder}', '#$placeholder#');
@@ -354,13 +354,13 @@ Future<void> main(List<String> arguments) async {
exit(0);
}
final String arbPathString = results['arb-dir'];
final String outputFileString = results['output-localization-file'];
final String arbPathString = results['arb-dir'] as String;
final String outputFileString = results['output-localization-file'] as String;
final Directory l10nDirectory = Directory(arbPathString);
final File templateArbFile = File(path.join(l10nDirectory.path, results['template-arb-file']));
final File templateArbFile = File(path.join(l10nDirectory.path, results['template-arb-file'] as String));
final File outputFile = File(path.join(l10nDirectory.path, outputFileString));
final String stringsClassName = results['output-class'];
final String stringsClassName = results['output-class'] as String;
if (!l10nDirectory.existsSync())
exitWithError(
@@ -395,8 +395,8 @@ Future<void> main(List<String> arguments) async {
final RegExp arbFilenameRE = RegExp(r'(\w+)\.arb$');
if (arbFilenameRE.hasMatch(entityPath)) {
final File arbFile = File(entityPath);
final Map<String, dynamic> arbContents = json.decode(arbFile.readAsStringSync());
String localeString = arbContents['@@locale'];
final Map<String, dynamic> arbContents = json.decode(arbFile.readAsStringSync()) as Map<String, dynamic>;
String localeString = arbContents['@@locale'] as String;
if (localeString == null) {
final RegExp arbFilenameLocaleRE = RegExp(r'^[^_]*_(\w+)\.arb$');
@@ -430,7 +430,7 @@ Future<void> main(List<String> arguments) async {
Map<String, dynamic> bundle;
try {
bundle = json.decode(templateArbFile.readAsStringSync());
bundle = json.decode(templateArbFile.readAsStringSync()) as Map<String, dynamic>;
} on FileSystemException catch (e) {
exitWithError('Unable to read input arb file: $e');
} on FormatException catch (e) {
@@ -447,7 +447,7 @@ Future<void> main(List<String> arguments) async {
'Invalid key format: $key \n It has to be in camel case, cannot start '
'with a number, and cannot contain non-alphanumeric characters.'
);
if (pluralValueRE.hasMatch(bundle[key]))
if (pluralValueRE.hasMatch(bundle[key] as String))
classMethods.add(genPluralMethod(bundle, key));
else
classMethods.add(genSimpleMethod(bundle, key));

View File

@@ -136,7 +136,7 @@ String generateArbBasedLocalizationSubclasses({
final Map<String, String> languageResources = localeToResources[languageLocale];
for (String key in allKeys) {
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key];
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
output.writeln(generateGetter(key, languageResources[key], attributes, languageLocale));
}
output.writeln('}');
@@ -158,7 +158,7 @@ String generateArbBasedLocalizationSubclasses({
for (String key in scriptResources.keys.toList()..sort()) {
if (languageResources[key] == scriptResources[key])
continue;
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key];
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
output.writeln(generateGetter(key, scriptResources[key], attributes, languageLocale));
}
output.writeln('}');
@@ -183,7 +183,7 @@ String generateArbBasedLocalizationSubclasses({
// 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;
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key];
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
output.writeln(generateGetter(key, localeResources[key], attributes, languageLocale));
}
output.writeln('}');
@@ -207,7 +207,7 @@ String generateArbBasedLocalizationSubclasses({
for (String key in localeResources.keys) {
if (languageResources[key] == localeResources[key])
continue;
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key];
final Map<String, dynamic> attributes = localeToResourceAttributes[canonicalLocale][key] as Map<String, dynamic>;
output.writeln(generateGetter(key, localeResources[key], attributes, languageLocale));
}
output.writeln('}');
@@ -380,7 +380,7 @@ $factoryDeclaration
/// Used by [generateGetter] below.
String generateType(Map<String, dynamic> attributes) {
if (attributes != null) {
switch (attributes['x-flutter-type']) {
switch (attributes['x-flutter-type'] as String) {
case 'icuShortTimePattern':
return 'TimeOfDayFormat';
case 'scriptCategory':
@@ -401,7 +401,7 @@ String generateKey(String key, Map<String, dynamic> attributes) {
if (attributes != null) {
if (attributes.containsKey('parameters'))
return '${key}Raw';
switch (attributes['x-flutter-type']) {
switch (attributes['x-flutter-type'] as String) {
case 'icuShortTimePattern':
return '${key}Raw';
}
@@ -443,7 +443,7 @@ String generateValue(String value, Map<String, dynamic> attributes, LocaleInfo l
return null;
// cupertino_en.arb doesn't use x-flutter-type.
if (attributes != null) {
switch (attributes['x-flutter-type']) {
switch (attributes['x-flutter-type'] as String) {
case 'icuShortTimePattern':
if (!_icuTimeOfDayToEnum.containsKey(value)) {
throw Exception(

View File

@@ -114,10 +114,8 @@ class LocaleInfo implements Comparable<LocaleInfo> {
@override
bool operator ==(Object other) {
if (!(other is LocaleInfo))
return false;
final LocaleInfo otherLocale = other;
return originalString == otherLocale.originalString;
return other is LocaleInfo
&& other.originalString == originalString;
}
@override
@@ -167,13 +165,13 @@ void loadMatchingArbsIntoBundleMaps({
void populateResources(LocaleInfo locale, File file) {
final Map<String, String> resources = localeToResources[locale];
final Map<String, dynamic> attributes = localeToResourceAttributes[locale];
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync());
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
for (String key in bundle.keys) {
// The ARB file resource "attributes" for foo are called @foo.
if (key.startsWith('@'))
attributes[key.substring(1)] = bundle[key];
else
resources[key] = bundle[key];
resources[key] = bundle[key] as String;
}
}
// Only pre-assume scriptCode if there is a country or script code to assume off of.
@@ -247,9 +245,9 @@ GeneratorOptions parseArgs(List<String> rawArgs) {
defaultsTo: false,
);
final argslib.ArgResults args = argParser.parse(rawArgs);
final bool writeToFile = args['overwrite'];
final bool materialOnly = args['material'];
final bool cupertinoOnly = args['cupertino'];
final bool writeToFile = args['overwrite'] as bool;
final bool materialOnly = args['material'] as bool;
final bool cupertinoOnly = args['cupertino'] as bool;
return GeneratorOptions(writeToFile: writeToFile, materialOnly: materialOnly, cupertinoOnly: cupertinoOnly);
}

View File

@@ -36,7 +36,7 @@ void validateEnglishLocalizations(File file) {
throw ValidationError(errorMessages.toString());
}
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync());
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
for (String resourceId in bundle.keys) {
if (resourceId.startsWith('@'))
@@ -67,11 +67,11 @@ void validateEnglishLocalizations(File file) {
continue;
}
final String description = atResource['description'];
final String description = atResource['description'] as String;
if (description == null)
errorMessages.writeln('No description specified for $atResourceId');
final String plural = atResource['plural'];
final String plural = atResource['plural'] as String;
final String resourceId = atResourceId.substring(1);
if (plural != null) {
final String resourceIdOther = '${resourceId}Other';