Skip to content

update to the latest package:dart_flutter_team_lints #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkgs/extension_discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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/<package>/config.yaml` instead of
`extension/<package>/config.json` for better consistency with other tooling.
- Require that the top-level value in `extension/<package>/config.yaml` is
Expand Down
4 changes: 0 additions & 4 deletions pkgs/extension_discovery/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pkgs/extension_discovery/lib/src/expect_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:convert' show jsonDecode;
Map<String, Object?> decodeJsonMap(String json) {
final root = jsonDecode(json);
if (root case Map<String, Object?> v) return v;
throw FormatException('root must be a map');
throw const FormatException('root must be a map');
}

extension ExpectJson on Map<String, Object?> {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/extension_discovery/lib/src/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -45,7 +45,7 @@ Future<T> _attempt<T>(FutureOr<T> Function() fn) async {
if (code != 5 && code != 32) rethrow;

// Sleep a bit a try again.
await Future.delayed(Duration(milliseconds: 5));
await Future<void>.delayed(const Duration(milliseconds: 5));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/extension_discovery/lib/src/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Future<PackageConfig> 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();
Expand Down
7 changes: 5 additions & 2 deletions pkgs/extension_discovery/lib/src/registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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/<package>.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
Expand All @@ -29,7 +32,7 @@ Future<Registry?> 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')
Expand Down
8 changes: 4 additions & 4 deletions pkgs/extension_discovery/lib/src/yaml_config_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Map<String, Object?> parseYamlFromConfigFile(String yamlString) {
final visited = <YamlNode>{};
Object? toPlainType(YamlNode n) {
if (!visited.add(n)) {
throw FormatException(
throw const FormatException(
'Anchors/aliases are not supported in YAML config files',
);
}
Expand All @@ -54,7 +54,7 @@ Map<String, Object?> 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',
),
Expand All @@ -67,7 +67,7 @@ Map<String, Object?> 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',
);
}
Expand All @@ -79,7 +79,7 @@ Map<String, Object?> parseYamlFromConfigFile(String yamlString) {

final value = toPlainType(loadYamlNode(yamlString));
if (value is! Map<String, Object?>) {
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;
}
10 changes: 5 additions & 5 deletions pkgs/extension_discovery/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions pkgs/extension_discovery/test/find_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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/'),
Expand Down Expand Up @@ -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<void>.delayed(modificationMaturityDelay * 2);
// Ensure that we have a cache value!
await findExtensions(
'myapp',
Expand Down
2 changes: 1 addition & 1 deletion pkgs/extension_discovery/test/test_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object?> pubspec) =>
json('pubspec.yaml', pubspec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down