Skip to content

Commit

Permalink
Update to latest lints, Require Dart 3.2 (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Jan 10, 2024
1 parent 33dd246 commit 3e7d93c
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.0.0, dev]
sdk: [3.2, dev]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2.1.1-wip

- Require Dart 3.0
- Require Dart 3.2

## 2.1.0

Expand Down
4 changes: 2 additions & 2 deletions lib/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Future<PackageConfig> loadPackageConfigUri(Uri file,
/// then the parent directories are checked recursively,
/// all the way to the root directory, to check if those contains
/// a package configuration.
/// If [recurse] is set to [false], this parent directory check is not
/// If [recurse] is set to `false`, this parent directory check is not
/// performed.
///
/// If [onError] is provided, the configuration file parsing will report errors
Expand Down Expand Up @@ -140,7 +140,7 @@ Future<PackageConfig?> findPackageConfig(Directory directory,
/// then the parent directories are checked recursively,
/// all the way to the root directory, to check if those contains
/// a package configuration.
/// If [recurse] is set to [false], this parent directory check is not
/// If [recurse] is set to `false`, this parent directory check is not
/// performed.
///
/// If [loader] is provided, URIs are loaded using that function.
Expand Down
9 changes: 5 additions & 4 deletions lib/src/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ abstract class PackageConfigError {

class PackageConfigArgumentError extends ArgumentError
implements PackageConfigError {
PackageConfigArgumentError(Object? value, String name, String message)
: super.value(value, name, message);
PackageConfigArgumentError(
Object? super.value, String super.name, String super.message)
: super.value();

PackageConfigArgumentError.from(ArgumentError error)
: super.value(error.invalidValue, error.name, error.message);
}

class PackageConfigFormatException extends FormatException
implements PackageConfigError {
PackageConfigFormatException(String message, Object? source, [int? offset])
: super(message, source, offset);
PackageConfigFormatException(super.message, Object? super.source,
[super.offset]);

PackageConfigFormatException.from(FormatException exception)
: super(exception.message, exception.source, exception.offset);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class PackageConfig {
/// absolute directory URIs, valid language version, if any),
/// and there must not be two packages with the same name.
///
/// The package's root ([Package.rootUri]) and package-root
/// The package's root ([Package.root]) and package-root
/// ([Package.packageUriRoot]) paths must satisfy a number of constraints
/// We say that one path (which we know ends with a `/` charater)
/// is inside another path, if the latter path is a prefix of the former path,
Expand Down Expand Up @@ -95,7 +95,7 @@ abstract class PackageConfig {

/// Parses the JSON data of a package configuration file.
///
/// The [configuration] must be a JSON-like Dart data structure,
/// The [jsonData] must be a JSON-like Dart data structure,
/// like the one provided by parsing JSON text using `dart:convert`,
/// containing a valid package configuration.
///
Expand Down Expand Up @@ -167,7 +167,7 @@ abstract class PackageConfig {
/// Provides the associated package for a specific [file] (or directory).
///
/// Returns a [Package] which contains the [file]'s path, if any.
/// That is, the [Package.rootUri] directory is a parent directory
/// That is, the [Package.root] directory is a parent directory
/// of the [file]'s location.
///
/// Returns `null` if the file does not belong to any package.
Expand Down Expand Up @@ -247,7 +247,7 @@ abstract class Package {
/// Is always an absolute URI with no query or fragment parts,
/// and with a path ending in `/`.
///
/// All files in the [rootUri] directory are considered
/// All files in the [root] directory are considered
/// part of the package for purposes where that that matters.
Uri get root;

Expand Down
13 changes: 3 additions & 10 deletions lib/src/package_config_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ class SimplePackageConfig implements PackageConfig {
@override
Package? operator [](String packageName) => _packages[packageName];

/// Provides the associated package for a specific [file] (or directory).
///
/// Returns a [Package] which contains the [file]'s path.
/// That is, the [Package.rootUri] directory is a parent directory
/// of the [file]'s location.
/// Returns `null` if the file does not belong to any package.
@override
Package? packageOf(Uri file) => _packageTree.packageOf(file);

Expand Down Expand Up @@ -270,7 +264,7 @@ class SimplePackage implements Package {
}
}

/// Checks whether [version] is a valid Dart language version string.
/// Checks whether [source] is a valid Dart language version string.
///
/// The format is (as RegExp) `^(0|[1-9]\d+)\.(0|[1-9]\d+)$`.
///
Expand Down Expand Up @@ -553,9 +547,8 @@ enum ConflictType { sameRoots, interleaving, insidePackageRoot }
/// Conflict between packages added to the same configuration.
///
/// The [package] conflicts with [existingPackage] if it has
/// the same root path ([isRootConflict]) or the package URI root path
/// of [existingPackage] is inside the root path of [package]
/// ([isPackageRootConflict]).
/// the same root path or the package URI root path
/// of [existingPackage] is inside the root path of [package].
class ConflictException {
/// The existing package that [package] conflicts with.
final SimplePackage existingPackage;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/package_config_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const packagesFileName = '.packages';
/// If the [file] is a `.packages` file and [preferNewest] is true,
/// first checks whether there is an adjacent `.dart_tool/package_config.json`
/// file, and if so, reads that instead.
/// If [preferNewset] is false, the specified file is loaded even if it is
/// If [preferNewest] is false, the specified file is loaded even if it is
/// a `.packages` file and there is an available `package_config.json` file.
///
/// The file must exist and be a normal file.
Expand Down
8 changes: 3 additions & 5 deletions lib/src/package_config_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ PackageConfig parsePackageConfigString(
/// where the integer numeral cannot have a sign, and can only have a
/// leading zero if the entire numeral is a single zero.
///
/// All other properties are stored in [extraData].
///
/// The [baseLocation] is used as base URI to resolve the "rootUri"
/// URI referencestring.
/// URI reference string.
PackageConfig parsePackageConfigJson(
Object? json, Uri baseLocation, void Function(Object error) onError) {
if (!baseLocation.hasScheme || baseLocation.isScheme('package')) {
Expand All @@ -93,7 +91,7 @@ PackageConfig parsePackageConfigJson(
String typeName<T>() {
if (0 is T) return 'int';
if ('' is T) return 'string';
if (const [] is T) return 'array';
if (const <Object?>[] is T) return 'array';
return 'object';
}

Expand Down Expand Up @@ -239,7 +237,7 @@ void writePackageConfigJsonString(
PackageConfig config, Uri? baseUri, StringSink output) {
// Can be optimized.
var data = packageConfigToJson(config, baseUri);
output.write(JsonEncoder.withIndent(' ').convert(data));
output.write(const JsonEncoder.withIndent(' ').convert(data));
}

Map<String, Object?> packageConfigToJson(PackageConfig config, Uri? baseUri) =>
Expand Down
6 changes: 0 additions & 6 deletions lib/src/packages_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ PackageConfig parse(
///
/// If [baseUri] is provided, package locations will be made relative
/// to the base URI, if possible, before writing.
///
/// If [allowDefaultPackage] is `true`, the [packageMapping] may contain an
/// empty string mapping to the _default package name_.
///
/// All the keys of [packageMapping] must be valid package names,
/// and the values must be URIs that do not have the `package:` scheme.
void write(StringSink output, PackageConfig config,
{Uri? baseUri, String? comment}) {
if (baseUri != null && !baseUri.isAbsolute) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Support for reading and writing Dart Package Configuration files.
repository: https://github.com/dart-lang/package_config

environment:
sdk: ^3.0.0
sdk: ^3.2.0

dependencies:
path: ^1.8.0
Expand All @@ -13,5 +13,5 @@ dev_dependencies:
build_runner: ^2.0.0
build_test: ^2.1.2
build_web_compilers: ^4.0.0
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^2.0.0
test: ^1.16.0
22 changes: 9 additions & 13 deletions test/discovery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void main() {
fileTest('package_config.json', {
'.packages': 'invalid .packages file',
'script.dart': 'main(){}',
'packages': {'shouldNotBeFound': {}},
'packages': {'shouldNotBeFound': <Never>{}},
'.dart_tool': {
'package_config.json': packageConfigFile,
}
Expand All @@ -73,7 +73,7 @@ void main() {
fileTest('.packages', {
'.packages': packagesFile,
'script.dart': 'main(){}',
'packages': {'shouldNotBeFound': {}}
'packages': {'shouldNotBeFound': <Object, Object>{}}
}, (Directory directory) async {
var config = (await findPackageConfig(directory))!;
expect(config.version, 1); // Found .packages file.
Expand Down Expand Up @@ -108,7 +108,7 @@ void main() {
// Does not find a packages/ directory, and returns null if nothing found.
fileTest('package directory packages not supported', {
'packages': {
'foo': {},
'foo': <String, dynamic>{},
}
}, (Directory directory) async {
var config = await findPackageConfig(directory);
Expand All @@ -119,33 +119,29 @@ void main() {
fileTest('invalid .packages', {
'.packages': 'not a .packages file',
}, (Directory directory) {
expect(findPackageConfig(directory),
throwsA(TypeMatcher<FormatException>()));
expect(findPackageConfig(directory), throwsA(isA<FormatException>()));
});

fileTest('invalid .packages as JSON', {
'.packages': packageConfigFile,
}, (Directory directory) {
expect(findPackageConfig(directory),
throwsA(TypeMatcher<FormatException>()));
expect(findPackageConfig(directory), throwsA(isA<FormatException>()));
});

fileTest('invalid .packages', {
'.dart_tool': {
'package_config.json': 'not a JSON file',
}
}, (Directory directory) {
expect(findPackageConfig(directory),
throwsA(TypeMatcher<FormatException>()));
expect(findPackageConfig(directory), throwsA(isA<FormatException>()));
});

fileTest('invalid .packages as INI', {
'.dart_tool': {
'package_config.json': packagesFile,
}
}, (Directory directory) {
expect(findPackageConfig(directory),
throwsA(TypeMatcher<FormatException>()));
expect(findPackageConfig(directory), throwsA(isA<FormatException>()));
});
});

Expand Down Expand Up @@ -304,8 +300,8 @@ void main() {

fileTest('no config found', {}, (Directory directory) {
var file = dirFile(directory, 'anyname');
expect(() => loadPackageConfig(file),
throwsA(TypeMatcher<FileSystemException>()));
expect(
() => loadPackageConfig(file), throwsA(isA<FileSystemException>()));
});

fileTest('no config found, handled', {}, (Directory directory) async {
Expand Down
14 changes: 7 additions & 7 deletions test/discovery_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void main() {
loaderTest('package_config.json', {
'.packages': 'invalid .packages file',
'script.dart': 'main(){}',
'packages': {'shouldNotBeFound': {}},
'packages': {'shouldNotBeFound': <String, dynamic>{}},
'.dart_tool': {
'package_config.json': packageConfigFile,
}
Expand All @@ -70,7 +70,7 @@ void main() {
loaderTest('.packages', {
'.packages': packagesFile,
'script.dart': 'main(){}',
'packages': {'shouldNotBeFound': {}}
'packages': {'shouldNotBeFound': <String, dynamic>{}}
}, (directory, loader) async {
var config = (await findPackageConfigUri(directory, loader: loader))!;
expect(config.version, 1); // Found .packages file.
Expand Down Expand Up @@ -107,7 +107,7 @@ void main() {
// Does not find a packages/ directory, and returns null if nothing found.
loaderTest('package directory packages not supported', {
'packages': {
'foo': {},
'foo': <String, dynamic>{},
}
}, (Uri directory, loader) async {
var config = await findPackageConfigUri(directory, loader: loader);
Expand All @@ -118,14 +118,14 @@ void main() {
'.packages': 'not a .packages file',
}, (Uri directory, loader) {
expect(() => findPackageConfigUri(directory, loader: loader),
throwsA(TypeMatcher<FormatException>()));
throwsA(isA<FormatException>()));
});

loaderTest('invalid .packages as JSON', {
'.packages': packageConfigFile,
}, (Uri directory, loader) {
expect(() => findPackageConfigUri(directory, loader: loader),
throwsA(TypeMatcher<FormatException>()));
throwsA(isA<FormatException>()));
});

loaderTest('invalid .packages', {
Expand All @@ -134,7 +134,7 @@ void main() {
}
}, (Uri directory, loader) {
expect(() => findPackageConfigUri(directory, loader: loader),
throwsA(TypeMatcher<FormatException>()));
throwsA(isA<FormatException>()));
});

loaderTest('invalid .packages as INI', {
Expand All @@ -143,7 +143,7 @@ void main() {
}
}, (Uri directory, loader) {
expect(() => findPackageConfigUri(directory, loader: loader),
throwsA(TypeMatcher<FormatException>()));
throwsA(isA<FormatException>()));
});

// Does not find .packages if no package_config.json and minVersion > 1.
Expand Down
2 changes: 1 addition & 1 deletion test/package_config_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
void failParse(String name, String input) {
test('$name - error', () {
expect(() => LanguageVersion.parse(input),
throwsA(TypeMatcher<PackageConfigError>()));
throwsA(isA<PackageConfigError>()));
expect(() => LanguageVersion.parse(input), throwsFormatException);
var failed = false;
var actual = LanguageVersion.parse(input, onError: (_) {
Expand Down
4 changes: 2 additions & 2 deletions test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void main() {
test(name, () {
expect(
() => packages.parse(utf8.encode(content), baseFile, throwError),
throwsA(TypeMatcher<FormatException>()));
throwsA(isA<FormatException>()));
});
test('$name, handle error', () {
var hadError = false;
Expand Down Expand Up @@ -308,7 +308,7 @@ void main() {
// ignore: unnecessary_cast
() => parsePackageConfigBytes(utf8.encode(source) as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError),
throwsA(TypeMatcher<FormatException>()));
throwsA(isA<FormatException>()));
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ${packages.map((nu) => """
}
""";

/// Mimics a directory structure of [description] and runs [fileTest].
/// Mimics a directory structure of [description] and runs [loaderTest].
///
/// Description is a map, each key is a file entry. If the value is a map,
/// it's a subdirectory, otherwise it's a file and the value is the content
Expand Down

0 comments on commit 3e7d93c

Please sign in to comment.