diff --git a/pkgs/extension_discovery/CHANGELOG.md b/pkgs/extension_discovery/CHANGELOG.md index ca24e84cd4..20291176a8 100644 --- a/pkgs/extension_discovery/CHANGELOG.md +++ b/pkgs/extension_discovery/CHANGELOG.md @@ -1,4 +1,10 @@ +## 2.0.1-wip + +- Require Dart 3.0. +- Update to the latest version of `package:dart_flutter_team_lints`. + ## 2.0.0 + - Use `extension//config.yaml` instead of `extension//config.json` for better consistency with other tooling. - Require that the top-level value in `extension//config.yaml` is diff --git a/pkgs/extension_discovery/analysis_options.yaml b/pkgs/extension_discovery/analysis_options.yaml index d3d1daabfe..aadd26e94a 100644 --- a/pkgs/extension_discovery/analysis_options.yaml +++ b/pkgs/extension_discovery/analysis_options.yaml @@ -2,8 +2,4 @@ include: package:dart_flutter_team_lints/analysis_options.yaml linter: rules: - - always_declare_return_types - avoid_catches_without_on_clauses - - camel_case_types - - prefer_single_quotes - - unawaited_futures diff --git a/pkgs/extension_discovery/lib/src/expect_json.dart b/pkgs/extension_discovery/lib/src/expect_json.dart index 5f6713cbce..c2784bc1f9 100644 --- a/pkgs/extension_discovery/lib/src/expect_json.dart +++ b/pkgs/extension_discovery/lib/src/expect_json.dart @@ -7,7 +7,7 @@ import 'dart:convert' show jsonDecode; Map decodeJsonMap(String json) { final root = jsonDecode(json); if (root case Map v) return v; - throw FormatException('root must be a map'); + throw const FormatException('root must be a map'); } extension ExpectJson on Map { diff --git a/pkgs/extension_discovery/lib/src/io.dart b/pkgs/extension_discovery/lib/src/io.dart index 9941d17821..9343ced93c 100644 --- a/pkgs/extension_discovery/lib/src/io.dart +++ b/pkgs/extension_discovery/lib/src/io.dart @@ -20,7 +20,7 @@ const _maxAttempts = 20; /// /// This ensures that if `pub get` is racing with cache writing then we won't /// rely on the result. -Duration modificationMaturityDelay = Duration(seconds: 5); +Duration modificationMaturityDelay = const Duration(seconds: 5); /// On windows some renaming files/folders recently created can be problematic /// as they may be locked by security scanning systems. @@ -45,7 +45,7 @@ Future _attempt(FutureOr Function() fn) async { if (code != 5 && code != 32) rethrow; // Sleep a bit a try again. - await Future.delayed(Duration(milliseconds: 5)); + await Future.delayed(const Duration(milliseconds: 5)); } } } diff --git a/pkgs/extension_discovery/lib/src/package_config.dart b/pkgs/extension_discovery/lib/src/package_config.dart index fc0c7aa587..478da8e56a 100644 --- a/pkgs/extension_discovery/lib/src/package_config.dart +++ b/pkgs/extension_discovery/lib/src/package_config.dart @@ -16,7 +16,7 @@ Future loadPackageConfig( try { final packageConfig = decodeJsonMap(await packageConfigFile.readAsString()); if (packageConfig.expectNumber('configVersion') != 2) { - throw FormatException('"configVersion" must be 2'); + throw const FormatException('"configVersion" must be 2'); } return packageConfig.expectListObjects('packages').map((p) { final rootUri = p.expectUri('rootUri').asDirectory(); diff --git a/pkgs/extension_discovery/lib/src/registry.dart b/pkgs/extension_discovery/lib/src/registry.dart index 72b2a27d8e..60efc75e57 100644 --- a/pkgs/extension_discovery/lib/src/registry.dart +++ b/pkgs/extension_discovery/lib/src/registry.dart @@ -8,9 +8,12 @@ import 'dart:io' show File, FileSystemEntityType, IOException; import 'expect_json.dart'; import 'io.dart'; +// TODO: Convert the 'rootUri' reference below to a doc comment reference once +// https://github.com/dart-lang/linter/issues/4645 is addressed. + /// Entry in the `.dart_tool/extension_discovery/.json` file. /// -/// If the [rootUri] is not an absolute path, then we will assume that the +/// If the `rootUri` is not an absolute path, then we will assume that the /// package is mutable (either it's the root package or a path dependency). /// If there is no extension config file for a mutable package, then we will /// still store a [RegistryEntry] with `config = null`. Because everytime we @@ -29,7 +32,7 @@ Future loadRegistry(File registryFile) async { try { final registryJson = decodeJsonMap(await registryFile.readAsString()); if (registryJson.expectNumber('version') != 2) { - throw FormatException('"version" must be 2'); + throw const FormatException('"version" must be 2'); } return registryJson .expectListObjects('entries') diff --git a/pkgs/extension_discovery/lib/src/yaml_config_format.dart b/pkgs/extension_discovery/lib/src/yaml_config_format.dart index 4fddd2067b..53da6d3d8b 100644 --- a/pkgs/extension_discovery/lib/src/yaml_config_format.dart +++ b/pkgs/extension_discovery/lib/src/yaml_config_format.dart @@ -44,7 +44,7 @@ Map parseYamlFromConfigFile(String yamlString) { final visited = {}; Object? toPlainType(YamlNode n) { if (!visited.add(n)) { - throw FormatException( + throw const FormatException( 'Anchors/aliases are not supported in YAML config files', ); } @@ -54,7 +54,7 @@ Map parseYamlFromConfigFile(String yamlString) { String s => s, num n => n, bool b => b, - _ => throw FormatException( + _ => throw const FormatException( 'Only null, string, number, bool, map and lists are supported ' 'in YAML config files', ), @@ -67,7 +67,7 @@ Map parseYamlFromConfigFile(String yamlString) { return n.nodes.map((key, value) { final k = toPlainType(key as YamlNode); if (k is! String) { - throw FormatException( + throw const FormatException( 'Only string keys are allowed in YAML config files', ); } @@ -79,7 +79,7 @@ Map parseYamlFromConfigFile(String yamlString) { final value = toPlainType(loadYamlNode(yamlString)); if (value is! Map) { - throw FormatException('The root of a YAML config file must be a map'); + throw const FormatException('The root of a YAML config file must be a map'); } return value; } diff --git a/pkgs/extension_discovery/pubspec.yaml b/pkgs/extension_discovery/pubspec.yaml index b48ce31ab7..290a845a1c 100644 --- a/pkgs/extension_discovery/pubspec.yaml +++ b/pkgs/extension_discovery/pubspec.yaml @@ -1,18 +1,18 @@ name: extension_discovery description: >- A convention and utilities for package extension discovery. -version: 2.0.0 +version: 2.0.1-wip repository: https://github.com/dart-lang/tools/tree/main/pkgs/extension_discovery +environment: + sdk: ^3.0.0 + dependencies: yaml: ^3.0.0 dev_dependencies: collection: ^1.18.0 - dart_flutter_team_lints: ^1.0.0 + dart_flutter_team_lints: ^2.0.0 lints: ^2.0.0 test: ^1.21.0 test_descriptor: ^2.0.1 - -environment: - sdk: ^3.0.0 diff --git a/pkgs/extension_discovery/test/find_extensions_test.dart b/pkgs/extension_discovery/test/find_extensions_test.dart index 707ab563c3..33e8bf7d67 100644 --- a/pkgs/extension_discovery/test/find_extensions_test.dart +++ b/pkgs/extension_discovery/test/find_extensions_test.dart @@ -13,7 +13,7 @@ import 'test_descriptor.dart' as d; void main() { test('findExtensions', () async { // Override the maturity delay for reliable testing of caching logic. - modificationMaturityDelay = Duration(milliseconds: 500); + modificationMaturityDelay = const Duration(milliseconds: 500); final pkgLibDir = await Isolate.resolvePackageUri( Uri.parse('package:extension_discovery/'), @@ -238,7 +238,7 @@ void main() { // If the modification time of package_config.json and the cache is no more // than [modificationMaturityDelay] time apart, we'll ignore the cache. // Under the assumption that there was a tiny risk of a race condition. - await Future.delayed(modificationMaturityDelay * 2); + await Future.delayed(modificationMaturityDelay * 2); // Ensure that we have a cache value! await findExtensions( 'myapp', diff --git a/pkgs/extension_discovery/test/test_descriptor.dart b/pkgs/extension_discovery/test/test_descriptor.dart index c1f7a4cb3d..e0dc4a7796 100644 --- a/pkgs/extension_discovery/test/test_descriptor.dart +++ b/pkgs/extension_discovery/test/test_descriptor.dart @@ -10,7 +10,7 @@ import 'package:test_descriptor/test_descriptor.dart' as d; export 'package:test_descriptor/test_descriptor.dart'; d.FileDescriptor json(String fileName, Object? json) => - d.file(fileName, JsonEncoder.withIndent(' ').convert(json)); + d.file(fileName, const JsonEncoder.withIndent(' ').convert(json)); d.FileDescriptor pubspec(Map pubspec) => json('pubspec.yaml', pubspec); diff --git a/pkgs/extension_discovery/test/yaml_config_format_test.dart b/pkgs/extension_discovery/test/yaml_config_format_test.dart index 32b24d00d8..0e3f568dd3 100644 --- a/pkgs/extension_discovery/test/yaml_config_format_test.dart +++ b/pkgs/extension_discovery/test/yaml_config_format_test.dart @@ -134,7 +134,7 @@ void main() { '''; final data = parseYamlFromConfigFile(yaml); expect( - DeepCollectionEquality().equals(data, { + const DeepCollectionEquality().equals(data, { 'keyA': 'hello', 'keyB': 42, 'keyC': 42.2,