Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit f85205a

Browse files
Dart Teamalan-knight
Dart Team
authored andcommitted
Make Intl generated code pass most current lint options
Trying this again, but reverted the "new" removal and one additional type in generated code, as the generated code is used in Dart 1 projects that are still active. 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. Cloned from CL 264686901 by 'g4 patch'. Original change by alanknight@alanknight:intl_maintenance:290:citc on 2019/08/21 14:02:13. PiperOrigin-RevId: 264925581
1 parent f1d3ebd commit f85205a

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.16.0
22
* Fix 'k' formatting (1 to 24 hours) which incorrectly showed 0 to 23.
3+
* Tighten up types in a couple of places.
34

45
## 0.15.8
56
* Add return type to some internal methods to improve dart2js output.

lib/intl.dart

+17-6
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Intl {
9494
/// [Intl.withLocale] may be preferable if you are using different locales
9595
/// in the same application.
9696
static String get defaultLocale {
97-
var zoneLocale = Zone.current[#Intl.locale];
97+
var zoneLocale = Zone.current[#Intl.locale] as String;
9898
return zoneLocale == null ? _defaultLocale : zoneLocale;
9999
}
100100

@@ -207,8 +207,9 @@ class Intl {
207207
///
208208
/// Note that null is interpreted as meaning the default locale, so if
209209
/// [newLocale] is null the default locale will be returned.
210-
static String verifiedLocale(String newLocale, Function localeExists,
211-
{Function onFailure: _throwLocaleError}) {
210+
static String verifiedLocale(
211+
String newLocale, bool Function(String) localeExists,
212+
{String Function(String) onFailure: _throwLocaleError}) {
212213
// TODO(alanknight): Previously we kept a single verified locale on the Intl
213214
// object, but with different verification for different uses, that's more
214215
// difficult. As a result, we call this more often. Consider keeping
@@ -340,8 +341,15 @@ class Intl {
340341

341342
/// Internal: Implements the logic for plural selection - use [plural] for
342343
/// normal messages.
343-
static pluralLogic(num howMany,
344-
{zero, one, two, few, many, other, String locale, int precision,
344+
static T pluralLogic<T>(num howMany,
345+
{T zero,
346+
T one,
347+
T two,
348+
T few,
349+
T many,
350+
T other,
351+
String locale,
352+
int precision,
345353
String meaning}) {
346354
if (other == null) {
347355
throw new ArgumentError("The 'other' named argument must be provided");
@@ -549,7 +557,10 @@ class Intl {
549557
/// desc: 'Say Hello');
550558
/// Intl.withLocale("zh", new Timer(new Duration(milliseconds:10),
551559
/// () => print(hello("World")));
552-
static withLocale(String locale, function()) {
560+
static dynamic withLocale<T>(String locale, T Function() function) {
561+
// TODO(alanknight): Make this return T. This requires work because T might
562+
// be Future and the caller could get an unawaited Future. Which is
563+
// probably an error in their code, but the change is semi-breaking.
553564
var canonical = Intl.canonicalizedLocale(locale);
554565
return runZoned(function, zoneValues: {#Intl.locale: canonical});
555566
}

lib/src/intl/date_format.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class DateFormat {
277277
/// This will accept dates whose values are not strictly valid, or strings
278278
/// with additional characters (including whitespace) after a valid date. For
279279
/// stricter parsing, use [parseStrict].
280-
DateTime parse(String inputString, [utc = false]) =>
280+
DateTime parse(String inputString, [bool utc = false]) =>
281281
_parse(inputString, utc: utc, strict: false);
282282

283283
/// Given user input, attempt to parse the [inputString] "loosely" into the
@@ -305,15 +305,15 @@ class DateFormat {
305305
///
306306
/// // "Sept" is not a valid month name.
307307
/// new DateFormat.yMMMd("en_US").parseLoose("Sept 3, 2014");
308-
DateTime parseLoose(String inputString, [utc = false]) {
308+
DateTime parseLoose(String inputString, [bool utc = false]) {
309309
try {
310310
return _parse(inputString, utc: utc, strict: true);
311311
} on FormatException {
312312
return _parseLoose(inputString.toLowerCase(), utc);
313313
}
314314
}
315315

316-
_parseLoose(String inputString, bool utc) {
316+
DateTime _parseLoose(String inputString, bool utc) {
317317
var dateFields = new _DateBuilder();
318318
if (utc) dateFields.utc = true;
319319
var stream = new _Stream(inputString);
@@ -334,10 +334,10 @@ class DateFormat {
334334
/// DateTime constructor will accept them. It will also rejct strings with
335335
/// additional characters (including whitespace) after a valid date. For
336336
/// looser parsing, use [parse].
337-
DateTime parseStrict(String inputString, [utc = false]) =>
337+
DateTime parseStrict(String inputString, [bool utc = false]) =>
338338
_parse(inputString, utc: utc, strict: true);
339339

340-
DateTime _parse(String inputString, {utc: false, strict: false}) {
340+
DateTime _parse(String inputString, {bool utc: false, bool strict: false}) {
341341
// TODO(alanknight): The Closure code refers to special parsing of numeric
342342
// values with no delimiters, which we currently don't do. Should we?
343343
var dateFields = new _DateBuilder();

test/fixnum_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ main() {
8080

8181
test('micro money', () {
8282
microMoneyValues.forEach((number, expected) {
83-
// ignore: deprecated_member_use
83+
// ignore: deprecated_member_use_from_same_package
8484
var currency = new NumberFormat.currencyPattern().format(number);
8585
expect(currency, expected.first);
8686
var percent = new NumberFormat.percentPattern().format(number);

test/number_format_test_core.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ runTests(Map<String, num> allTestNumbers) {
149149
expect(formatted, '€1,000,000.32');
150150
var readBack = usConvention.parse(formatted);
151151
expect(readBack, amount);
152-
// ignore: deprecated_member_use
152+
// ignore: deprecated_member_use_from_same_package
153153
var swissConvention = new NumberFormat.currencyPattern('de_CH', r'$');
154154
formatted = swissConvention.format(amount);
155155
var nbsp = new String.fromCharCode(0xa0);
@@ -159,7 +159,7 @@ runTests(Map<String, num> allTestNumbers) {
159159
readBack = swissConvention.parse(formatted);
160160
expect(readBack, amount);
161161

162-
// ignore: deprecated_member_use
162+
// ignore: deprecated_member_use_from_same_package
163163
var italianSwiss = new NumberFormat.currencyPattern('it_CH', r'$');
164164
formatted = italianSwiss.format(amount);
165165
expect(formatted,
@@ -177,7 +177,7 @@ runTests(Map<String, num> allTestNumbers) {
177177

178178
// Verify that we can pass null in order to specify the currency symbol
179179
// but use the default locale.
180-
// ignore: deprecated_member_use
180+
// ignore: deprecated_member_use_from_same_package
181181
var defaultLocale = new NumberFormat.currencyPattern(null, 'Smurfs');
182182
formatted = defaultLocale.format(amount);
183183
// We don't know what the exact format will be, but it should have Smurfs.

0 commit comments

Comments
 (0)