Skip to content

Commit 30cd01d

Browse files
Dart Teamalan-knight
Dart Team
authored andcommitted
Automated g4 rollback of changelist 264686901.
*** Reason for rollback *** Google Fiber application doesn't build: https://test.corp.google.com/ui#cl=264686901 *** Original change description *** Make Intl generated code pass most current lint options Mostly using ignore_for_file, but fixing a few of the most obvious issues Started out as integrating dart-archive/intl_translation#31 but then expanded. *** PiperOrigin-RevId: 264727285
1 parent 9918029 commit 30cd01d

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

pkgs/intl_translation/CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## 0.17.6
22
* Strip indentation from generated JSON output to improve codesize.
3-
* Make generated code not trigger most lints, either by fixing issues
4-
or by using lots of ignore_for_file directives.
53

64
## 0.17.5
75
* Allow multiple ARB files with the same locale and combine

pkgs/intl_translation/lib/generate_localized.dart

+35-31
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MessageGeneration {
5757
/// so it's left undefined.
5858
String package;
5959

60-
bool get releaseMode => codegenMode == 'release';
60+
get releaseMode => codegenMode == 'release';
6161

6262
bool get jsonMode => false;
6363

@@ -105,8 +105,10 @@ class MessageGeneration {
105105
for (var translation in usableTranslations) {
106106
// Some messages we generate as methods in this class. Simpler ones
107107
// we inline in the map from names to messages.
108-
var messagesThatNeedMethods =
109-
translation.originalMessages.where(_hasArguments).toSet().toList();
108+
var messagesThatNeedMethods = translation.originalMessages
109+
.where((each) => _hasArguments(each))
110+
.toSet()
111+
.toList();
110112
for (var original in messagesThatNeedMethods) {
111113
output
112114
..write(" ")
@@ -151,21 +153,22 @@ class MessageGeneration {
151153
// messages from the main program should be duplicated here with the same
152154
// function name.
153155
154-
// Ignore issues from commonly used lints in this file.
155-
// ignore_for_file:unnecessary_brace_in_string_interps
156-
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
157-
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
158-
// ignore_for_file:unused_import, file_names
156+
// ignore_for_file: unnecessary_brace_in_string_interps
159157
160158
import 'package:$intlImportPath/intl.dart';
161159
import 'package:$intlImportPath/message_lookup_by_library.dart';
162160
$extraImports
163-
final messages = MessageLookup();
161+
// ignore: unnecessary_new
162+
final messages = new MessageLookup();
164163
165-
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
164+
// ignore: unused_element
165+
final _keepAnalysisHappy = Intl.defaultLocale;
166+
167+
// ignore: non_constant_identifier_names
168+
typedef MessageIfAbsent(String message_str, List<dynamic> args);
166169
167170
class MessageLookup extends MessageLookupByLibrary {
168-
String get localeName => '$locale';
171+
get localeName => '$locale';
169172
170173
""" +
171174
(releaseMode ? overrideLookup : "");
@@ -182,7 +185,8 @@ class MessageLookup extends MessageLookupByLibrary {
182185
// If there's no message_str, then we are an internal lookup, e.g. an
183186
// embedded plural, and shouldn't fail.
184187
if (message_str == null) return null;
185-
throw UnsupportedError(
188+
// ignore: unnecessary_new
189+
throw new UnsupportedError(
186190
"No translation found for message '\$name',\\n"
187191
" original text '\$message_str'");
188192
}
@@ -211,11 +215,12 @@ class MessageLookup extends MessageLookupByLibrary {
211215
var locale = Intl.canonicalizedLocale(rawLocale);
212216
var loadOperation = (useDeferredLoading)
213217
? " '$locale': ${libraryName(locale)}.loadLibrary,\n"
214-
: " '$locale': () => Future.value(null),\n";
218+
: "// ignore: unnecessary_new\n"
219+
" '$locale': () => new Future.value(null),\n";
215220
output.write(loadOperation);
216221
}
217222
output.write("};\n");
218-
output.write("\nMessageLookupByLibrary _findExact(String localeName) {\n"
223+
output.write("\nMessageLookupByLibrary _findExact(localeName) {\n"
219224
" switch (localeName) {\n");
220225
for (var rawLocale in allLocales) {
221226
var locale = Intl.canonicalizedLocale(rawLocale);
@@ -233,17 +238,11 @@ class MessageLookup extends MessageLookupByLibrary {
233238
// This is a library that looks up messages for specific locales by
234239
// delegating to the appropriate library.
235240
236-
// Ignore issues from commonly used lints in this file.
237-
// ignore_for_file:implementation_imports, file_names
238-
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
239-
// ignore_for_file:argument_type_not_assignable, invalid_assignment
240-
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
241-
// ignore_for_file:comment_references
242-
243241
import 'dart:async';
244242
245243
import 'package:$intlImportPath/intl.dart';
246244
import 'package:$intlImportPath/message_lookup_by_library.dart';
245+
// ignore: implementation_imports
247246
import 'package:$intlImportPath/src/intl_helpers.dart';
248247
249248
""";
@@ -261,13 +260,17 @@ Future<bool> initializeMessages(String localeName) async {
261260
(locale) => _deferredLibraries[locale] != null,
262261
onFailure: (_) => null);
263262
if (availableLocale == null) {
264-
return Future.value(false);
263+
// ignore: unnecessary_new
264+
return new Future.value(false);
265265
}
266266
var lib = _deferredLibraries[availableLocale];
267-
await (lib == null ? Future.value(false) : lib());
268-
initializeInternalMessageLookup(() => CompositeMessageLookup());
267+
// ignore: unnecessary_new
268+
await (lib == null ? new Future.value(false) : lib());
269+
// ignore: unnecessary_new
270+
initializeInternalMessageLookup(() => new CompositeMessageLookup());
269271
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
270-
return Future.value(true);
272+
// ignore: unnecessary_new
273+
return new Future.value(true);
271274
}
272275
273276
bool _messagesExistFor(String locale) {
@@ -278,7 +281,7 @@ bool _messagesExistFor(String locale) {
278281
}
279282
}
280283
281-
MessageLookupByLibrary _findGeneratedMessagesFor(String locale) {
284+
MessageLookupByLibrary _findGeneratedMessagesFor(locale) {
282285
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor,
283286
onFailure: (_) => null);
284287
if (actualLocale == null) return null;
@@ -325,9 +328,9 @@ import '${generatedFilePrefix}messages_all.dart' show evaluateJsonTemplate;
325328
void writeTranslations(
326329
Iterable<TranslatedMessage> usableTranslations, String locale) {
327330
output.write(r"""
328-
Map<String, dynamic> _messages;
329-
Map<String,dynamic> get messages => _messages ??=
330-
const JsonDecoder().convert(messageText) as Map<String, dynamic>;
331+
var _messages;
332+
// ignore: unnecessary_new
333+
get messages => _messages ??= new JsonDecoder().convert(messageText);
331334
""");
332335

333336
output.write(" static final messageText = ");
@@ -355,7 +358,7 @@ import '${generatedFilePrefix}messages_all.dart' show evaluateJsonTemplate;
355358
/// * \['Intl.gender', String gender, (templates for female, male, other)\]
356359
/// * \['Intl.select', String choice, { 'case' : template, ...} \]
357360
/// * \['text alternating with ', 0 , ' indexes in the argument list'\]
358-
String evaluateJsonTemplate(dynamic input, List<dynamic> args) {
361+
String evaluateJsonTemplate(Object input, List<dynamic> args) {
359362
if (input == null) return null;
360363
if (input is String) return input;
361364
if (input is int) {
@@ -395,7 +398,8 @@ String evaluateJsonTemplate(dynamic input, List<dynamic> args) {
395398
396399
// If we get this far, then we are a basic interpolation, just strings and
397400
// ints.
398-
var output = StringBuffer();
401+
// ignore: unnecessary_new
402+
var output = new StringBuffer();
399403
for (var entry in template) {
400404
if (entry is int) {
401405
output.write("\${args[entry]}");

0 commit comments

Comments
 (0)