From 3314a87d954d210430e56658024b36aa7de809f5 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 18 Jul 2024 13:49:11 +0200 Subject: [PATCH] Switch to `package:dart_flutter_team_lints` (#1387) --- analysis_options.yaml | 4 +++- lib/src/batch/batch_compare_command.dart | 3 +-- lib/src/batch/batch_query_command.dart | 2 +- lib/src/batch/batch_run_command.dart | 3 +-- lib/src/license.dart | 2 +- lib/src/license_detection/license_detector.dart | 3 ++- lib/src/package_analyzer.dart | 2 +- lib/src/report/static_analysis.dart | 1 + lib/src/report/template.dart | 3 +-- lib/src/repository/check_repository.dart | 2 ++ lib/src/screenshots.dart | 2 +- lib/src/third_party/diff_match_patch/diff.dart | 2 +- lib/src/third_party/diff_match_patch/test.dart | 3 ++- lib/src/tool/git_tool.dart | 2 +- lib/src/tool/run_constrained.dart | 3 ++- pubspec.yaml | 3 ++- test/license_detector_test.dart | 2 +- test/pubspec_test.dart | 7 ------- 18 files changed, 24 insertions(+), 25 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index cb063fef6..d4e699add 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true @@ -8,6 +8,8 @@ analyzer: unused_local_variable: error dead_code: error deprecated_member_use_from_same_package: ignore + lines_longer_than_80_chars: ignore + avoid_dynamic_calls: ignore linter: rules: diff --git a/lib/src/batch/batch_compare_command.dart b/lib/src/batch/batch_compare_command.dart index 06b9c4069..824676f73 100644 --- a/lib/src/batch/batch_compare_command.dart +++ b/lib/src/batch/batch_compare_command.dart @@ -6,12 +6,11 @@ import 'dart:convert'; import 'dart:io'; import 'package:args/command_runner.dart'; -import 'package:pana/src/package_analyzer.dart'; import 'package:yaml/yaml.dart' as yaml; +import '../package_analyzer.dart'; import '../sdk_env.dart' show SdkConfig, ToolEnvironment; import '../utils.dart' show withTempDir; - import 'batch_model.dart'; /// Compares pana outcomes on the selected packages. diff --git a/lib/src/batch/batch_query_command.dart b/lib/src/batch/batch_query_command.dart index 1fdcc56e7..1f02a0b4e 100644 --- a/lib/src/batch/batch_query_command.dart +++ b/lib/src/batch/batch_query_command.dart @@ -104,7 +104,7 @@ class BatchQueryCommand extends Command { Future _ageInDays(String package) async { final rs = await _client - .get((Uri.parse('https://pub.dartlang.org/api/packages/$package'))); + .get(Uri.parse('https://pub.dartlang.org/api/packages/$package')); if (rs.statusCode != 200) { throw AssertionError('Unexpected status code: ${rs.statusCode}'); } diff --git a/lib/src/batch/batch_run_command.dart b/lib/src/batch/batch_run_command.dart index a43904537..279ed2ecc 100644 --- a/lib/src/batch/batch_run_command.dart +++ b/lib/src/batch/batch_run_command.dart @@ -6,12 +6,11 @@ import 'dart:convert'; import 'dart:io'; import 'package:args/command_runner.dart'; -import 'package:pana/src/package_analyzer.dart'; import 'package:yaml/yaml.dart' as yaml; +import '../package_analyzer.dart'; import '../sdk_env.dart' show SdkConfig, ToolEnvironment; import '../utils.dart' show withTempDir; - import 'batch_model.dart'; /// Runs pana on the selected packages. diff --git a/lib/src/license.dart b/lib/src/license.dart index bde1fc8f2..dfb34b174 100644 --- a/lib/src/license.dart +++ b/lib/src/license.dart @@ -7,9 +7,9 @@ import 'dart:convert'; import 'dart:io'; import 'package:meta/meta.dart'; -import 'package:pana/src/license_detection/license_detector.dart' hide License; import 'package:path/path.dart' as p; +import 'license_detection/license_detector.dart' hide License; import 'model.dart'; const _licenseFileNames = ['LICENSE']; diff --git a/lib/src/license_detection/license_detector.dart b/lib/src/license_detection/license_detector.dart index ad4012f8a..ba17f0df1 100644 --- a/lib/src/license_detection/license_detector.dart +++ b/lib/src/license_detection/license_detector.dart @@ -9,10 +9,11 @@ import 'dart:isolate'; import 'dart:math'; import 'package:meta/meta.dart'; -import 'package:pana/src/third_party/diff_match_patch/diff.dart'; import 'package:source_span/source_span.dart'; import 'package:string_scanner/string_scanner.dart'; +import '../third_party/diff_match_patch/diff.dart'; + part 'confidence.dart'; part 'crc32.dart'; part 'license.dart'; diff --git a/lib/src/package_analyzer.dart b/lib/src/package_analyzer.dart index ced27fc66..f5265e3e4 100644 --- a/lib/src/package_analyzer.dart +++ b/lib/src/package_analyzer.dart @@ -7,7 +7,6 @@ import 'dart:io'; import 'dart:typed_data'; import 'package:logging/logging.dart'; -import 'package:pana/src/tool/git_tool.dart'; import 'package:path/path.dart' as path; import 'download_utils.dart'; @@ -22,6 +21,7 @@ import 'report/create_report.dart'; import 'sdk_env.dart'; import 'tag/pana_tags.dart'; import 'tag/tagger.dart'; +import 'tool/git_tool.dart'; import 'tool/run_constrained.dart'; import 'utils.dart'; diff --git a/lib/src/report/static_analysis.dart b/lib/src/report/static_analysis.dart index 52e7213e3..a4b74d5fc 100644 --- a/lib/src/report/static_analysis.dart +++ b/lib/src/report/static_analysis.dart @@ -166,6 +166,7 @@ FileSpan? sourceSpanFromFile({ return null; } return sourceFile.span(startOffset, startOffset + newLength); + // ignore: avoid_catching_errors } on RangeError { // Note: This happens if the file contains CR as line terminators. // If the range is invalid, then we just return null. diff --git a/lib/src/report/template.dart b/lib/src/report/template.dart index c80ced568..3af0a984b 100644 --- a/lib/src/report/template.dart +++ b/lib/src/report/template.dart @@ -4,15 +4,14 @@ import 'dart:io'; -import 'package:pana/src/tag/license_tags.dart'; import 'package:path/path.dart' as p; import 'package:pubspec_parse/pubspec_parse.dart' show GitDependency; import '../markdown_content.dart'; import '../model.dart'; import '../package_context.dart'; +import '../tag/license_tags.dart'; import '../utils.dart'; - import '_common.dart'; const _pluginDocsUrl = diff --git a/lib/src/repository/check_repository.dart b/lib/src/repository/check_repository.dart index e8b4dd470..fe54f363d 100644 --- a/lib/src/repository/check_repository.dart +++ b/lib/src/repository/check_repository.dart @@ -114,6 +114,7 @@ Future checkRepository({ yamlDoc = yaml.loadYaml(content); } on FormatException catch (e, st) { log.info('Invalid yaml file: $path', e, st); + // ignore: avoid_catching_errors } on ArgumentError catch (e, st) { log.info('Invalid yaml file: $path', e, st); } @@ -234,6 +235,7 @@ Future checkRepository({ } on FormatException catch (e, st) { failVerification( 'Unable to parse `pubspec.yaml` from git repository. $e', e, st); + // ignore: avoid_catching_errors } on ArgumentError catch (e, st) { failVerification( 'Unable to parse `pubspec.yaml` from git repository. $e', e, st); diff --git a/lib/src/screenshots.dart b/lib/src/screenshots.dart index 6f2d72119..8c5db404d 100644 --- a/lib/src/screenshots.dart +++ b/lib/src/screenshots.dart @@ -6,10 +6,10 @@ import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; -import 'package:pana/pana.dart'; import 'package:path/path.dart' as path; import 'package:pubspec_parse/pubspec_parse.dart' as p; +import '../pana.dart'; import 'logging.dart'; final maxFileSizeInBytes = 4194304; // 4MB diff --git a/lib/src/third_party/diff_match_patch/diff.dart b/lib/src/third_party/diff_match_patch/diff.dart index 989997c94..8f8328fa7 100644 --- a/lib/src/third_party/diff_match_patch/diff.dart +++ b/lib/src/third_party/diff_match_patch/diff.dart @@ -539,7 +539,7 @@ List diffBisect(String text1, String text2, DateTime deadline) { for (var d = 0; d < maxD; d++) { // Bail out if deadline is reached. - if ((DateTime.now()).compareTo(deadline) == 1) { + if (DateTime.now().compareTo(deadline) == 1) { break; } diff --git a/lib/src/third_party/diff_match_patch/test.dart b/lib/src/third_party/diff_match_patch/test.dart index b3cdf0b72..6f322c761 100644 --- a/lib/src/third_party/diff_match_patch/test.dart +++ b/lib/src/third_party/diff_match_patch/test.dart @@ -1,9 +1,10 @@ // ignore_for_file: invalid_use_of_visible_for_testing_member -import 'package:pana/src/third_party/diff_match_patch/diff.dart'; // ignore: depend_on_referenced_packages import 'package:test/test.dart'; +import 'diff.dart'; + void testDiffMain() { var expected = []; _testDiffMain( diff --git a/lib/src/tool/git_tool.dart b/lib/src/tool/git_tool.dart index d9ba47a6d..1aedba395 100644 --- a/lib/src/tool/git_tool.dart +++ b/lib/src/tool/git_tool.dart @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:pana/src/utils.dart'; import 'package:path/path.dart' as p; +import '../utils.dart'; import 'run_constrained.dart'; /// Runs `git` in an isolated environment using the [homePath] to access its diff --git a/lib/src/tool/run_constrained.dart b/lib/src/tool/run_constrained.dart index 2134b8705..3850ecd8b 100644 --- a/lib/src/tool/run_constrained.dart +++ b/lib/src/tool/run_constrained.dart @@ -7,9 +7,10 @@ import 'dart:convert'; import 'dart:io' hide BytesBuilder; import 'dart:typed_data'; -import 'package:pana/src/logging.dart'; import 'package:retry/retry.dart'; +import '../logging.dart'; + final _timeout = const Duration(minutes: 2); const _maxOutputBytes = 10 * 1024 * 1024; // 10 MiB const _maxOutputLinesWhenKilled = 1000; diff --git a/pubspec.yaml b/pubspec.yaml index 3f0473084..e75fbce98 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,8 +32,8 @@ dependencies: source_span: ^1.7.0 string_scanner: ^1.1.0 tar: ^2.0.0 - yaml: ^3.0.0 test: ^1.5.2 # needed for lib/src/third_party/diff_match_patch/test.dart + yaml: ^3.0.0 dev_dependencies: build: ^2.0.1 @@ -41,6 +41,7 @@ dev_dependencies: build_runner: ^2.0.4 build_verify: ^3.0.0 build_version: ^2.0.0 + dart_flutter_team_lints: ^3.1.0 json_serializable: ^6.0.0 shelf: ^1.0.0 source_gen: ^1.0.0 diff --git a/test/license_detector_test.dart b/test/license_detector_test.dart index a6039b1fa..251d70b16 100644 --- a/test/license_detector_test.dart +++ b/test/license_detector_test.dart @@ -162,7 +162,7 @@ void main() { ]); }); - group(('longestUnclaimedPercentage tests:'), () { + group('longestUnclaimedPercentage tests:', () { _testUnclaimedPercentage( 'Expect 1.0 for no matches found', [], diff --git a/test/pubspec_test.dart b/test/pubspec_test.dart index bdf89e0ce..730355d2f 100644 --- a/test/pubspec_test.dart +++ b/test/pubspec_test.dart @@ -77,13 +77,6 @@ final Pubspec flutterPluginPubspec = Pubspec({ }, }); -final Pubspec flutterDependencyPubspec = Pubspec({ - 'name': 'sample', - 'dependencies': { - 'flutter': 'any', - }, -}); - final Pubspec flutterSdkPubspec = Pubspec({ 'name': 'sample', 'dependencies': {