lints: migrate to pkg:lints, enable and fix two more lints
diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md index 98fbbbf..9cc4b52 100644 --- a/pkgs/pubspec_parse/CHANGELOG.md +++ b/pkgs/pubspec_parse/CHANGELOG.md
@@ -1,3 +1,5 @@ +## 1.1.1-dev + ## 1.1.0 - Export `HostedDetails` publicly.
diff --git a/pkgs/pubspec_parse/analysis_options.yaml b/pkgs/pubspec_parse/analysis_options.yaml index 39be54a..67e23cb 100644 --- a/pkgs/pubspec_parse/analysis_options.yaml +++ b/pkgs/pubspec_parse/analysis_options.yaml
@@ -1,4 +1,4 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml analyzer: strong-mode: @@ -9,70 +9,41 @@ - avoid_bool_literals_in_conditional_expressions - avoid_catching_errors - avoid_classes_with_only_static_members - - avoid_function_literals_in_foreach_calls + - avoid_dynamic_calls - avoid_private_typedef_functions - avoid_redundant_argument_values - - avoid_renaming_method_parameters - avoid_returning_null - avoid_returning_null_for_future - - avoid_returning_null_for_void - avoid_returning_this - - avoid_single_cascade_in_expression_statements - avoid_unused_constructor_parameters - avoid_void_async - - await_only_futures - - camel_case_types - cancel_subscriptions - cascade_invocations - comment_references - - constant_identifier_names - - control_flow_in_finally - directives_ordering - - empty_statements - - file_names - - hash_and_equals - - implementation_imports - invariant_booleans - - iterable_contains_unrelated_type - join_return_with_assignment - lines_longer_than_80_chars - - list_remove_unrelated_type - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - no_runtimeType_toString - - non_constant_identifier_names - only_throw_errors - - overridden_fields - package_api_docs - - package_names - - package_prefixed_library_names - prefer_asserts_in_initializer_lists - prefer_const_constructors - prefer_const_declarations - prefer_expression_function_bodies - prefer_final_locals - - prefer_function_declarations_over_variables - - prefer_initializing_formals - - prefer_inlined_adds - prefer_interpolation_to_compose_strings - - prefer_is_not_operator - - prefer_null_aware_operators - prefer_relative_imports - - prefer_typing_uninitialized_variables - - prefer_void_to_null - - provide_deprecation_message + - require_trailing_commas - sort_pub_dependencies - test_types_in_equals - throw_in_finally - unnecessary_await_in_return - - unnecessary_brace_in_string_interps - - unnecessary_getters_setters - unnecessary_lambdas - unnecessary_null_aware_assignments - - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements - - unnecessary_string_interpolations - use_string_buffers - - void_checks
diff --git a/pkgs/pubspec_parse/build.yaml b/pkgs/pubspec_parse/build.yaml index ddec84e..2003bc2 100644 --- a/pkgs/pubspec_parse/build.yaml +++ b/pkgs/pubspec_parse/build.yaml
@@ -19,5 +19,7 @@ options: ignore_for_file: - deprecated_member_use_from_same_package + - lines_longer_than_80_chars + - require_trailing_commas # https://github.com/google/json_serializable.dart/issues/945 - unnecessary_cast
diff --git a/pkgs/pubspec_parse/lib/src/dependency.dart b/pkgs/pubspec_parse/lib/src/dependency.dart index 20e7eb6..f8d3ecd 100644 --- a/pkgs/pubspec_parse/lib/src/dependency.dart +++ b/pkgs/pubspec_parse/lib/src/dependency.dart
@@ -27,7 +27,11 @@ if (value == null) { throw CheckedFromJsonException( - source, key, 'Pubspec', 'Not a valid dependency value.'); + source, + key, + 'Pubspec', + 'Not a valid dependency value.', + ); } return MapEntry(key, value); }) ?? @@ -54,11 +58,18 @@ return $checkedNew<Dependency>('Dependency', data, () { if (firstUnrecognizedKey != null) { throw UnrecognizedKeysException( - [firstUnrecognizedKey], data, _sourceKeys); + [firstUnrecognizedKey], + data, + _sourceKeys, + ); } if (matchedKeys.length > 1) { - throw CheckedFromJsonException(data, matchedKeys[1], 'Dependency', - 'A dependency may only have one source.'); + throw CheckedFromJsonException( + data, + matchedKeys[1], + 'Dependency', + 'A dependency may only have one source.', + ); } final key = matchedKeys.single;
diff --git a/pkgs/pubspec_parse/lib/src/dependency.g.dart b/pkgs/pubspec_parse/lib/src/dependency.g.dart index b917563..4e9d399 100644 --- a/pkgs/pubspec_parse/lib/src/dependency.g.dart +++ b/pkgs/pubspec_parse/lib/src/dependency.g.dart
@@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_cast +// ignore_for_file: deprecated_member_use_from_same_package, lines_longer_than_80_chars, require_trailing_commas, unnecessary_cast part of 'dependency.dart';
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.dart b/pkgs/pubspec_parse/lib/src/pubspec.dart index b851486..8cc7b09 100644 --- a/pkgs/pubspec_parse/lib/src/pubspec.dart +++ b/pkgs/pubspec_parse/lib/src/pubspec.dart
@@ -195,7 +195,11 @@ return MapEntry(key, constraint); } else { throw CheckedFromJsonException( - source, key, 'VersionConstraint', '`$value` is not a String.'); + source, + key, + 'VersionConstraint', + '`$value` is not a String.', + ); } return MapEntry(key, constraint);
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.g.dart b/pkgs/pubspec_parse/lib/src/pubspec.g.dart index 0231c97..cadd38e 100644 --- a/pkgs/pubspec_parse/lib/src/pubspec.g.dart +++ b/pkgs/pubspec_parse/lib/src/pubspec.g.dart
@@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_cast +// ignore_for_file: deprecated_member_use_from_same_package, lines_longer_than_80_chars, require_trailing_commas, unnecessary_cast part of 'pubspec.dart';
diff --git a/pkgs/pubspec_parse/pubspec.yaml b/pkgs/pubspec_parse/pubspec.yaml index afaa952..5e51c29 100644 --- a/pkgs/pubspec_parse/pubspec.yaml +++ b/pkgs/pubspec_parse/pubspec.yaml
@@ -2,7 +2,7 @@ description: >- Simple package for parsing pubspec.yaml files with a type-safe API and rich error reporting. -version: 1.1.0 +version: 1.1.1-dev repository: https://github.com/dart-lang/pubspec_parse environment: @@ -19,8 +19,8 @@ build_runner: ^2.0.3 build_verify: ^2.0.0 json_serializable: ^5.0.0 + lints: ^1.0.0 path: ^1.5.1 - pedantic: ^1.4.0 # Needed because we are configuring `combining_builder` source_gen: ^1.0.0 stack_trace: ^1.9.2
diff --git a/pkgs/pubspec_parse/test/dependency_test.dart b/pkgs/pubspec_parse/test/dependency_test.dart index 9ccd614..20053a8 100644 --- a/pkgs/pubspec_parse/test/dependency_test.dart +++ b/pkgs/pubspec_parse/test/dependency_test.dart
@@ -56,12 +56,15 @@ }); test('map with unsupported keys', () { - _expectThrows({'bob': 'a', 'jones': 'b'}, r''' + _expectThrows( + {'bob': 'a', 'jones': 'b'}, + r''' line 5, column 4: Unrecognized keys: [bob]; supported keys: [sdk, git, path, hosted] ╷ 5 │ "bob": "a", │ ^^^^^ - ╵'''); + ╵''', + ); }); }); } @@ -133,21 +136,25 @@ }); test('map w/ extra keys should fail', () { - _expectThrows({ - 'version': '^1.0.0', - 'hosted': {'name': 'hosted_name', 'url': 'hosted_url'}, - 'not_supported': null - }, r''' + _expectThrows( + { + 'version': '^1.0.0', + 'hosted': {'name': 'hosted_name', 'url': 'hosted_url'}, + 'not_supported': null + }, + r''' line 10, column 4: Unrecognized keys: [not_supported]; supported keys: [sdk, git, path, hosted] ╷ 10 │ "not_supported": null │ ^^^^^^^^^^^^^^^ - ╵'''); + ╵''', + ); }); test('map w/ version and hosted as String', () { final dep = _dependency<HostedDependency>( - {'version': '^1.0.0', 'hosted': 'hosted_name'}); + {'version': '^1.0.0', 'hosted': 'hosted_name'}, + ); expect(dep.version.toString(), '^1.0.0'); expect(dep.hosted!.name, 'hosted_name'); expect(dep.hosted!.url, isNull); @@ -192,7 +199,8 @@ test('with version', () { final dep = _dependency<SdkDependency>( - {'sdk': 'flutter', 'version': '>=1.2.3 <2.0.0'}); + {'sdk': 'flutter', 'version': '>=1.2.3 <2.0.0'}, + ); expect(dep.sdk, 'flutter'); expect(dep.version.toString(), '>=1.2.3 <2.0.0'); expect(dep.toString(), 'SdkDependency: flutter'); @@ -250,8 +258,10 @@ if (skipTryParse) { print('FYI: not validating git@ URI on travis due to failure'); } - final dep = _dependency<GitDependency>({'git': 'git@localhost:dep.git'}, - skipTryPub: skipTryParse); + final dep = _dependency<GitDependency>( + {'git': 'git@localhost:dep.git'}, + skipTryPub: skipTryParse, + ); expect(dep.url.toString(), 'ssh://git@localhost/dep.git'); expect(dep.path, isNull); expect(dep.ref, isNull); @@ -259,12 +269,15 @@ }); test('string with random extra key fails', () { - _expectThrows({'git': 'url', 'bob': '^1.2.3'}, r''' + _expectThrows( + {'git': 'url', 'bob': '^1.2.3'}, + r''' line 6, column 4: Unrecognized keys: [bob]; supported keys: [sdk, git, path, hosted] ╷ 6 │ "bob": "^1.2.3" │ ^^^^^ - ╵'''); + ╵''', + ); }); test('map', () { @@ -365,12 +378,15 @@ }); test('valid with random extra key fails', () { - _expectThrows({'path': '../path', 'bob': '^1.2.3'}, r''' + _expectThrows( + {'path': '../path', 'bob': '^1.2.3'}, + r''' line 6, column 4: Unrecognized keys: [bob]; supported keys: [sdk, git, path, hosted] ╷ 6 │ "bob": "^1.2.3" │ ^^^^^ - ╵'''); + ╵''', + ); }); test('null content', () { @@ -403,20 +419,26 @@ } void _expectThrows(Object content, String expectedError) { - expectParseThrows({ - 'name': 'sample', - 'dependencies': {'dep': content} - }, expectedError); + expectParseThrows( + { + 'name': 'sample', + 'dependencies': {'dep': content} + }, + expectedError, + ); } T _dependency<T extends Dependency>( Object? content, { bool skipTryPub = false, }) { - final value = parse({ - ...defaultPubspec, - 'dependencies': {'dep': content} - }, skipTryPub: skipTryPub); + final value = parse( + { + ...defaultPubspec, + 'dependencies': {'dep': content} + }, + skipTryPub: skipTryPub, + ); expect(value.name, 'sample'); expect(value.dependencies, hasLength(1));
diff --git a/pkgs/pubspec_parse/test/git_uri_test.dart b/pkgs/pubspec_parse/test/git_uri_test.dart index 36e55a8..be89ba8 100644 --- a/pkgs/pubspec_parse/test/git_uri_test.dart +++ b/pkgs/pubspec_parse/test/git_uri_test.dart
@@ -16,7 +16,8 @@ final uri = parseGitUri(item.key); printOnFailure( - [uri.scheme, uri.userInfo, uri.host, uri.port, uri.path].join('\n')); + [uri.scheme, uri.userInfo, uri.host, uri.port, uri.path].join('\n'), + ); expect(uri, Uri.parse(item.value)); });
diff --git a/pkgs/pubspec_parse/test/parse_test.dart b/pkgs/pubspec_parse/test/parse_test.dart index 52df370..5f70de8 100644 --- a/pkgs/pubspec_parse/test/parse_test.dart +++ b/pkgs/pubspec_parse/test/parse_test.dart
@@ -62,8 +62,10 @@ expect(value.devDependencies, isEmpty); expect(value.dependencyOverrides, isEmpty); expect(value.repository, Uri.parse('https://github.com/example/repo')); - expect(value.issueTracker, - Uri.parse('https://github.com/example/repo/issues')); + expect( + value.issueTracker, + Uri.parse('https://github.com/example/repo/issues'), + ); }); test('environment values can be null', () { @@ -212,12 +214,15 @@ ); }); test('array', () { - expectParseThrows([], r''' + expectParseThrows( + [], + r''' line 1, column 1: Not a map ╷ 1 │ [] │ ^^ - ╵'''); + ╵''', + ); }); test('missing name', () { @@ -257,15 +262,18 @@ }); test('"dart" is an invalid environment key', () { - expectParseThrows({ - 'name': 'sample', - 'environment': {'dart': 'cool'} - }, r''' + expectParseThrows( + { + 'name': 'sample', + 'environment': {'dart': 'cool'} + }, + r''' line 4, column 3: Use "sdk" to for Dart SDK constraints. ╷ 4 │ "dart": "cool" │ ^^^^^^ - ╵'''); + ╵''', + ); }); test('environment values cannot be int', () { @@ -298,15 +306,18 @@ }); test('invalid environment value', () { - expectParseThrows({ - 'name': 'sample', - 'environment': {'sdk': 'silly'} - }, r''' + expectParseThrows( + { + 'name': 'sample', + 'environment': {'sdk': 'silly'} + }, + r''' line 4, column 10: Unsupported value for "sdk". Could not parse version "silly". Unknown text at "silly". ╷ 4 │ "sdk": "silly" │ ^^^^^^^ - ╵'''); + ╵''', + ); }); test('bad repository url', () { @@ -426,16 +437,21 @@ test('deep error throws with lenient', () { expect( - () => parse({ - 'name': 'sample', - 'dependencies': { - 'foo': { - 'git': {'url': 1} - }, - }, - 'issue_tracker': {'x': 'y'}, - }, skipTryPub: true, lenient: true), - throwsException); + () => parse( + { + 'name': 'sample', + 'dependencies': { + 'foo': { + 'git': {'url': 1} + }, + }, + 'issue_tracker': {'x': 'y'}, + }, + skipTryPub: true, + lenient: true, + ), + throwsException, + ); }); }); }
diff --git a/pkgs/pubspec_parse/test/pub_utils.dart b/pkgs/pubspec_parse/test/pub_utils.dart index 17e8970..5871b1b 100644 --- a/pkgs/pubspec_parse/test/pub_utils.dart +++ b/pkgs/pubspec_parse/test/pub_utils.dart
@@ -23,21 +23,25 @@ final result = await ProcResult.fromTestProcess(proc); - printOnFailure([ - '-----BEGIN pub output-----', - result.toString().trim(), - '-----END pub output-----', - ].join('\n')); + printOnFailure( + [ + '-----BEGIN pub output-----', + result.toString().trim(), + '-----END pub output-----', + ].join('\n'), + ); if (result.exitCode == 0) { final lockContent = File(p.join(d.sandbox, 'pubspec.lock')).readAsStringSync(); - printOnFailure([ - '-----BEGIN pubspec.lock-----', - lockContent.trim(), - '-----END pubspec.lock-----', - ].join('\n')); + printOnFailure( + [ + '-----BEGIN pubspec.lock-----', + lockContent.trim(), + '-----END pubspec.lock-----', + ].join('\n'), + ); } return result;
diff --git a/pkgs/pubspec_parse/test/test_utils.dart b/pkgs/pubspec_parse/test/test_utils.dart index 132ef64..72d2142 100644 --- a/pkgs/pubspec_parse/test/test_utils.dart +++ b/pkgs/pubspec_parse/test/test_utils.dart
@@ -22,13 +22,18 @@ String _encodeJson(Object? input) => const JsonEncoder.withIndent(' ').convert(input); -Matcher _throwsParsedYamlException(String prettyValue) => - throwsA(const TypeMatcher<ParsedYamlException>().having((e) { - final message = e.formattedMessage; - printOnFailure("Actual error format:\nr'''\n$message'''"); - _printDebugParsedYamlException(e); - return message; - }, 'formattedMessage', prettyValue)); +Matcher _throwsParsedYamlException(String prettyValue) => throwsA( + const TypeMatcher<ParsedYamlException>().having( + (e) { + final message = e.formattedMessage; + printOnFailure("Actual error format:\nr'''\n$message'''"); + _printDebugParsedYamlException(e); + return message; + }, + 'formattedMessage', + prettyValue, + ), + ); void _printDebugParsedYamlException(ParsedYamlException e) { var innerError = e.innerError; @@ -76,18 +81,23 @@ if (pubResult != null) { addTearDown(() { - expect(pubResult!.cleanParse, isTrue, - reason: - 'On success, parsing from the pub client should also succeed.'); + expect( + pubResult!.cleanParse, + isTrue, + reason: + 'On success, parsing from the pub client should also succeed.', + ); }); } return value; } catch (e) { if (pubResult != null) { addTearDown(() { - expect(pubResult!.cleanParse, isFalse, - reason: - 'On failure, parsing from the pub client should also fail.'); + expect( + pubResult!.cleanParse, + isFalse, + reason: 'On failure, parsing from the pub client should also fail.', + ); }); } if (e is ParsedYamlException) {