Skip to content

Commit

Permalink
Ignore unnecessary casts from utf8.encode (dart-lang/package_config#114)
Browse files Browse the repository at this point in the history
An upcoming SDK change will change the return type to `Uint8List` which
makes the casts unnecessary and introduces analyzer diagnostics.
Preemptively ignore these to make it easier to roll the SDK.

https://dart-review.googlesource.com/c/sdk/+/208190
  • Loading branch information
natebosch authored Aug 6, 2021
1 parent 028521a commit 0061cdb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkgs/package_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.0.2-dev

## 2.0.1

- Use unique library names to correct docs issue.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/package_config/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: package_config
version: 2.0.1
version: 2.0.2-dev
description: Support for working with Package Configuration files.
homepage: https://github.com/dart-lang/package_config

Expand Down
6 changes: 6 additions & 0 deletions pkgs/package_config/test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void main() {
}
''';
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode(packageConfigFile) as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
Expand Down Expand Up @@ -193,6 +194,7 @@ void main() {
}
''';
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode(packageConfigFile) as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
Expand All @@ -219,6 +221,7 @@ void main() {
var root = '"rootUri":"/foo/"';
test('minimal', () {
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode('{$cfg,$pkgs}') as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
Expand All @@ -229,6 +232,7 @@ void main() {
// A package must have a name and a rootUri, the remaining properties
// are optional.
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode('{$cfg,"packages":[{$name,$root}]}') as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
Expand All @@ -246,6 +250,7 @@ void main() {
{'name': 'qux', 'rootUri': '/foo/qux/', 'packageUri': 'lib/'},
]
}));
// ignore: unnecessary_cast
var config = parsePackageConfigBytes(configBytes as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
Expand All @@ -271,6 +276,7 @@ void main() {
void testThrows(String name, String source) {
test(name, () {
expect(
// ignore: unnecessary_cast
() => parsePackageConfigBytes(utf8.encode(source) as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError),
throwsA(TypeMatcher<FormatException>()));
Expand Down
1 change: 1 addition & 0 deletions pkgs/package_config/test/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void loaderTest(
if (value is! Map<String, Object?>) return null;
value = value[parts[i]];
}
// ignore: unnecessary_cast
if (value is String) return utf8.encode(value) as Uint8List;
return null;
}
Expand Down

0 comments on commit 0061cdb

Please sign in to comment.