From d328a1a6a6c6d57be82f699d4de3e1313a711ce8 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Wed, 14 Feb 2024 13:21:02 -0500 Subject: [PATCH] Linting clean up finish --- bin/compile.dart | 2 ++ lib/src/commands/base_command.dart | 1 + lib/src/commands/config_command.dart | 2 +- lib/src/commands/dart_command.dart | 3 ++- lib/src/commands/doctor_command.dart | 14 +++++++----- lib/src/commands/exec_command.dart | 5 +++-- lib/src/commands/flutter_command.dart | 5 +++-- lib/src/commands/spawn_command.dart | 2 +- lib/src/commands/use_command.dart | 10 +++++---- lib/src/models/config_model.dart | 7 +++--- lib/src/runner.dart | 10 ++++----- lib/src/services/config_repository.dart | 2 +- lib/src/services/flutter_service.dart | 22 +++++++++++-------- .../models/flutter_releases.model.dart | 3 ++- .../releases_service/releases_client.dart | 15 ++++++++----- lib/src/utils/commands.dart | 5 ++--- lib/src/utils/context.dart | 10 ++++++--- lib/src/utils/deprecation_util.dart | 4 +--- lib/src/utils/helpers.dart | 2 ++ .../parsers/git_clone_update_printer.dart | 5 ++++- lib/src/utils/pretty_json.dart | 2 +- tool/grind.dart | 2 +- tool/homebrew.dart | 4 +++- 23 files changed, 82 insertions(+), 55 deletions(-) diff --git a/bin/compile.dart b/bin/compile.dart index c9637c1a..0073fb95 100644 --- a/bin/compile.dart +++ b/bin/compile.dart @@ -10,6 +10,7 @@ Future main() async { if (os != 'macos' && os != 'linux') { print('Unsupported OS. Only MacOS and Linux are supported.'); + return; } @@ -28,6 +29,7 @@ Future main() async { // Error checking for compile process if (compileResult.exitCode != 0) { print('Error occurred in compilation:\n ${compileResult.stderr}'); + return; } diff --git a/lib/src/commands/base_command.dart b/lib/src/commands/base_command.dart index 47968389..ef25a0cc 100644 --- a/lib/src/commands/base_command.dart +++ b/lib/src/commands/base_command.dart @@ -21,6 +21,7 @@ abstract class BaseCommand extends Command { } /// Gets the parsed command-line option named [name] as `List`. + // ignore: prefer-correct-json-casts List stringsArg(String name) => argResults![name] as List; @override String get invocation => 'fvm $name'; diff --git a/lib/src/commands/config_command.dart b/lib/src/commands/config_command.dart index 80b45f99..864a08d0 100644 --- a/lib/src/commands/config_command.dart +++ b/lib/src/commands/config_command.dart @@ -1,7 +1,7 @@ import 'package:io/ansi.dart'; import 'package:io/io.dart'; -import '../../fvm.dart'; +import '../models/config_model.dart'; import '../services/config_repository.dart'; import '../services/logger_service.dart'; import '../utils/constants.dart'; diff --git a/lib/src/commands/dart_command.dart b/lib/src/commands/dart_command.dart index 3df03b6f..e0ddd4a1 100644 --- a/lib/src/commands/dart_command.dart +++ b/lib/src/commands/dart_command.dart @@ -1,7 +1,8 @@ import 'package:args/args.dart'; -import '../../fvm.dart'; +import '../models/cache_flutter_version_model.dart'; import '../services/logger_service.dart'; +import '../services/project_service.dart'; import '../utils/commands.dart'; import '../utils/constants.dart'; import '../workflows/ensure_cache.workflow.dart'; diff --git a/lib/src/commands/doctor_command.dart b/lib/src/commands/doctor_command.dart index 6c76c278..52179a52 100644 --- a/lib/src/commands/doctor_command.dart +++ b/lib/src/commands/doctor_command.dart @@ -5,8 +5,10 @@ import 'package:dart_console/dart_console.dart'; import 'package:io/io.dart'; import 'package:path/path.dart'; -import '../../fvm.dart'; +import '../models/config_model.dart'; +import '../models/project_model.dart'; import '../services/logger_service.dart'; +import '../services/project_service.dart'; import '../utils/console_utils.dart'; import '../utils/constants.dart'; import '../utils/context.dart'; @@ -87,14 +89,17 @@ class DoctorCommand extends BaseCommand { table.insertRow( ['Matches pinned version:', sdkPath == relativeSymlinkPath], ); - } on FormatException { + } on FormatException catch (_, stackTrace) { logger ..err('Error parsing Vscode settings.json on ${settingsFile.path}') ..err( 'Please use a tool like https://jsonformatter.curiousconcept.com to validate and fix it', ); - throw AppException( - 'Could not get vscode settings, please check settings.json', + Error.throwWithStackTrace( + AppException( + 'Could not get vscode settings, please check settings.json', + ), + stackTrace, ); } } else { @@ -195,7 +200,6 @@ class DoctorCommand extends BaseCommand { logger.write(table.toString()); } - void printFVMDetails() {} @override Future run() async { final project = ProjectService.fromContext.findAncestor(); diff --git a/lib/src/commands/exec_command.dart b/lib/src/commands/exec_command.dart index e4b5334b..2b568d44 100644 --- a/lib/src/commands/exec_command.dart +++ b/lib/src/commands/exec_command.dart @@ -1,8 +1,9 @@ import 'package:args/args.dart'; import 'package:args/command_runner.dart'; -import '../../fvm.dart'; +import '../models/cache_flutter_version_model.dart'; import '../services/logger_service.dart'; +import '../services/project_service.dart'; import '../utils/commands.dart'; import '../utils/constants.dart'; import '../workflows/ensure_cache.workflow.dart'; @@ -31,7 +32,7 @@ class ExecCommand extends BaseCommand { final cmd = argResults!.rest[0]; // Removes version from first arg - final execArgs = [...argResults!.rest]..removeAt(0); + final execArgs = [...?argResults?.rest]..removeAt(0); // If no version is provided try to use global CacheFlutterVersion? cacheVersion; diff --git a/lib/src/commands/flutter_command.dart b/lib/src/commands/flutter_command.dart index 560de3f4..f12a3557 100644 --- a/lib/src/commands/flutter_command.dart +++ b/lib/src/commands/flutter_command.dart @@ -1,7 +1,8 @@ import 'package:args/args.dart'; -import '../../fvm.dart'; +import '../models/cache_flutter_version_model.dart'; import '../services/logger_service.dart'; +import '../services/project_service.dart'; import '../utils/commands.dart'; import '../utils/constants.dart'; import '../utils/exceptions.dart'; @@ -23,7 +24,7 @@ class FlutterCommand extends BaseCommand { @override Future run() async { final version = ProjectService.fromContext.findVersion(); - final args = [...argResults!.arguments]; + final args = [...?argResults?.arguments]; CacheFlutterVersion? cacheVersion; diff --git a/lib/src/commands/spawn_command.dart b/lib/src/commands/spawn_command.dart index 8e576147..36477dc7 100644 --- a/lib/src/commands/spawn_command.dart +++ b/lib/src/commands/spawn_command.dart @@ -30,7 +30,7 @@ class SpawnCommand extends BaseCommand { final version = argResults!.rest[0]; // Removes version from first arg - final flutterArgs = [...argResults!.rest]..removeAt(0); + final flutterArgs = [...?argResults?.rest]..removeAt(0); // Will install version if not already instaled final cacheVersion = await ensureCacheWorkflow(version); diff --git a/lib/src/commands/use_command.dart b/lib/src/commands/use_command.dart index 0dad8c2d..cccc4afe 100644 --- a/lib/src/commands/use_command.dart +++ b/lib/src/commands/use_command.dart @@ -1,12 +1,14 @@ import 'package:args/command_runner.dart'; -import '../../fvm.dart'; -import '../services/releases_service/releases_client.dart'; -import '../utils/helpers.dart'; -import '../workflows/ensure_cache.workflow.dart'; import 'package:io/io.dart'; +import '../services/cache_service.dart'; import '../services/logger_service.dart'; +import '../services/project_service.dart'; +import '../services/releases_service/models/channels.model.dart'; +import '../services/releases_service/releases_client.dart'; import '../utils/console_utils.dart'; +import '../utils/helpers.dart'; +import '../workflows/ensure_cache.workflow.dart'; import '../workflows/use_version.workflow.dart'; import 'base_command.dart'; diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 26897b9b..d958a9fe 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -96,7 +96,7 @@ class ConfigKeys { String get propKey => _recase.camelCase; @override - operator ==(other) => other is ConfigKeys && other.key == key; + operator ==(Object other) => other is ConfigKeys && other.key == key; @override int get hashCode => key.hashCode; @@ -363,12 +363,13 @@ class ProjectConfig extends Config { }) { // merge map and override the keys final mergedFlavors = { - if (this.flavors != null) ...this.flavors!, + if (this.flavors != null) ...?this.flavors, + // ignore: prefer-null-aware-spread if (flavors != null) ...flavors, }; return ProjectConfig( - cachePath: cachePath ?? cachePath, + cachePath: cachePath ?? this.cachePath, useGitCache: useGitCache ?? this.useGitCache, gitCachePath: gitCachePath ?? this.gitCachePath, flutterUrl: flutterUrl ?? this.flutterUrl, diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 21684117..84f1a518 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -195,9 +195,8 @@ class FvmCommandRunner extends CommandRunner { ..detail('') ..detail('Argument information:'); - final hasTopLevelOption = topLevelResults.options - .where((e) => topLevelResults.wasParsed(e)) - .isNotEmpty; + final hasTopLevelOption = + topLevelResults.options.any((e) => topLevelResults.wasParsed(e)); if (hasTopLevelOption) { logger.detail(' Top level options:'); @@ -214,9 +213,8 @@ class FvmCommandRunner extends CommandRunner { logger.detail('Command: ${commandResult.name}'); // Check if any command option was parsed - final hasCommandOption = commandResult.options - .where((e) => commandResult.wasParsed(e)) - .isNotEmpty; + final hasCommandOption = + commandResult.options.any((e) => commandResult.wasParsed(e)); if (hasCommandOption) { logger.detail(' Command options:'); diff --git a/lib/src/services/config_repository.dart b/lib/src/services/config_repository.dart index dd6ab30a..ccc8e10c 100644 --- a/lib/src/services/config_repository.dart +++ b/lib/src/services/config_repository.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import '../../fvm.dart'; +import '../models/config_model.dart'; import '../utils/constants.dart'; import '../utils/helpers.dart'; diff --git a/lib/src/services/flutter_service.dart b/lib/src/services/flutter_service.dart index 1e1f5110..0fa2f216 100644 --- a/lib/src/services/flutter_service.dart +++ b/lib/src/services/flutter_service.dart @@ -6,13 +6,14 @@ import 'package:git/git.dart'; import 'package:io/io.dart' as io; import 'package:mason_logger/mason_logger.dart'; -import '../../fvm.dart'; +import '../models/cache_flutter_version_model.dart'; import '../models/flutter_version_model.dart'; import '../utils/commands.dart'; import '../utils/context.dart'; import '../utils/exceptions.dart'; import '../utils/parsers/git_clone_update_printer.dart'; import 'base_service.dart'; +import 'cache_service.dart'; import 'logger_service.dart'; import 'releases_service/releases_client.dart'; @@ -78,13 +79,16 @@ class FlutterService extends ContextService { ]; try { - final result = await runGit([ - 'clone', - '--progress', - ...cloneArgs, - context.flutterUrl, - versionDir.path, - ], echoOutput: !(context.isTest || !logger.isVerbose)); + final result = await runGit( + [ + 'clone', + '--progress', + ...cloneArgs, + context.flutterUrl, + versionDir.path, + ], + echoOutput: !(context.isTest || !logger.isVerbose), + ); final gitVersionDir = CacheService(context).getVersionCacheDir(version.name); @@ -166,7 +170,7 @@ class FlutterService extends ContextService { final tags = await getTags(); - return tags.where((t) => t == tag).isNotEmpty; + return tags.any((t) => t == tag); } Future> getTags() async { diff --git a/lib/src/services/releases_service/models/flutter_releases.model.dart b/lib/src/services/releases_service/models/flutter_releases.model.dart index 6b7adf9f..4e64e5b4 100644 --- a/lib/src/services/releases_service/models/flutter_releases.model.dart +++ b/lib/src/services/releases_service/models/flutter_releases.model.dart @@ -69,7 +69,7 @@ class Releases { Map toMap() => { 'base_url': baseUrl, 'channels': channels.toMap(), - 'releases': List.from(releases.map((x) => x.toMap())), + 'releases': List.from(releases.map((x) => x.toMap())), }; } @@ -79,6 +79,7 @@ class Releases { Releases _parseCurrentReleases(Map map) { final baseUrl = map['base_url'] as String; final currentRelease = map['current_release'] as Map; + // ignore: avoid-dynamic final releasesJson = map['releases'] as List; final systemArch = 'x64'; diff --git a/lib/src/services/releases_service/releases_client.dart b/lib/src/services/releases_service/releases_client.dart index 753a1610..9aa1568d 100644 --- a/lib/src/services/releases_service/releases_client.dart +++ b/lib/src/services/releases_service/releases_client.dart @@ -60,12 +60,15 @@ class FlutterReleases { _cacheReleasesRes = Releases.fromJson(response); return await Future.value(_cacheReleasesRes); - } on Exception { - throw AppException( - 'Failed to retrieve the Flutter SDK from: ${getFlutterReleasesUrl(platform)}\n' - 'Fvm will use the value set on ' - 'env FLUTTER_STORAGE_BASE_URL to check versions\n' - 'if you are located in China, please see this page: https://flutter.dev/community/china', + } on Exception catch (_, stackTrace) { + Error.throwWithStackTrace( + AppException( + 'Failed to retrieve the Flutter SDK from: ${getFlutterReleasesUrl(platform)}\n' + 'Fvm will use the value set on ' + 'env FLUTTER_STORAGE_BASE_URL to check versions\n' + 'if you are located in China, please see this page: https://flutter.dev/community/china', + ), + stackTrace, ); } } diff --git a/lib/src/utils/commands.dart b/lib/src/utils/commands.dart index dcd64fe3..ac3c8319 100644 --- a/lib/src/utils/commands.dart +++ b/lib/src/utils/commands.dart @@ -1,10 +1,9 @@ import 'dart:io'; +import '../models/cache_flutter_version_model.dart'; import 'context.dart'; -import 'run_command.dart'; - -import '../../fvm.dart'; import 'helpers.dart'; +import 'run_command.dart'; final _dartCmd = 'dart'; final _flutterCmd = 'flutter'; diff --git a/lib/src/utils/context.dart b/lib/src/utils/context.dart index 59a10f7a..2b5ede1b 100644 --- a/lib/src/utils/context.dart +++ b/lib/src/utils/context.dart @@ -4,11 +4,13 @@ import 'package:mason_logger/mason_logger.dart'; import 'package:path/path.dart'; import 'package:scope/scope.dart'; -import '../../fvm.dart'; +import '../models/config_model.dart'; +import '../services/cache_service.dart'; import '../services/config_repository.dart'; import '../services/flutter_service.dart'; import '../services/global_version_service.dart'; import '../services/logger_service.dart'; +import '../services/project_service.dart'; import 'constants.dart'; final contextKey = ScopeKey(); @@ -17,6 +19,7 @@ final contextKey = ScopeKey(); /// /// Generators are allowed to return `null`, in which case the context will /// store the `null` value as the value for that type. +// ignore: avoid-dynamic typedef Generator = dynamic Function(FVMContext context); FVMContext get ctx => use(contextKey, withDefault: () => FVMContext.main); @@ -56,9 +59,10 @@ class FVMContext { // Load config from file in config path final projectConfig = ProjectConfig.loadFromPath(workingDirectory); final envConfig = ConfigRepository.loadEnv(); - var appConfig = ConfigRepository.loadFile(); - appConfig = appConfig.mergeConfig(envConfig).mergeConfig(projectConfig); + final appConfig = ConfigRepository.loadFile() + .mergeConfig(envConfig) + .mergeConfig(projectConfig); // Merge config from file with env config final config = appConfig.merge(configOverrides); diff --git a/lib/src/utils/deprecation_util.dart b/lib/src/utils/deprecation_util.dart index 489bfaf8..6fb21ab8 100644 --- a/lib/src/utils/deprecation_util.dart +++ b/lib/src/utils/deprecation_util.dart @@ -4,7 +4,7 @@ import 'dart:io'; import 'package:mason_logger/mason_logger.dart'; import 'package:path/path.dart'; -import '../../fvm.dart'; +import '../models/config_model.dart'; import '../services/config_repository.dart'; import '../services/logger_service.dart'; import 'constants.dart'; @@ -96,6 +96,4 @@ void _warnDeprecatedEnvVars() { logger.warn('$oldCachePathEnv environment variable is deprecated. '); logger.info('Please use ${ConfigKeys.cachePath.envKey} instead'); } - - if (flutterRoot == null || fvmHome == null) {} } diff --git a/lib/src/utils/helpers.dart b/lib/src/utils/helpers.dart index 7979793e..6e5ce448 100644 --- a/lib/src/utils/helpers.dart +++ b/lib/src/utils/helpers.dart @@ -63,6 +63,8 @@ String assignVersionWeight(String version) { } try { + // Checking to throw an issue if it cannot parse + // ignore: avoid-unused-instances Version.parse(version); } on Exception { logger.warn('Version $version is not a valid semver'); diff --git a/lib/src/utils/parsers/git_clone_update_printer.dart b/lib/src/utils/parsers/git_clone_update_printer.dart index 5fe94d9a..f4e884ff 100644 --- a/lib/src/utils/parsers/git_clone_update_printer.dart +++ b/lib/src/utils/parsers/git_clone_update_printer.dart @@ -1,9 +1,10 @@ import 'dart:convert'; import 'dart:io'; +import 'package:mason_logger/mason_logger.dart'; + import '../../services/logger_service.dart'; import '../extensions.dart'; -import 'package:mason_logger/mason_logger.dart'; final regexes = { 'Enumerating objects:': RegExp(r'Enumerating objects: +(\d+)%'), @@ -61,10 +62,12 @@ void printProgressBar(String label, int percentage) { Future runGitCloneUpdate(List args) async { final process = await Process.start('git', args); + // ignore: avoid-unassigned-stream-subscriptions process.stderr.transform(utf8.decoder).listen((line) { updateProgress(line); }); + // ignore: avoid-unassigned-stream-subscriptions process.stdout.transform(utf8.decoder).listen((line) { logger.info(line); }); diff --git a/lib/src/utils/pretty_json.dart b/lib/src/utils/pretty_json.dart index c3f3ad9c..cb612ef5 100644 --- a/lib/src/utils/pretty_json.dart +++ b/lib/src/utils/pretty_json.dart @@ -1,7 +1,7 @@ import 'dart:convert'; /// Formats [json] -String prettyJson(dynamic json) { +String prettyJson(Map json) { var spaces = ' ' * 2; var encoder = JsonEncoder.withIndent(spaces); diff --git a/tool/grind.dart b/tool/grind.dart index 24d14a51..27d1a5a5 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -83,7 +83,7 @@ Future getReleases() async { final stringBuffer = StringBuffer(); - List releases = jsonDecode(response); + List releases = jsonDecode(response); for (var release in releases) { String tagName = release['tag_name']; String date = release['published_at']; diff --git a/tool/homebrew.dart b/tool/homebrew.dart index 07dafd66..b033f376 100644 --- a/tool/homebrew.dart +++ b/tool/homebrew.dart @@ -34,7 +34,7 @@ Future _homebrewFormula() async { final response = await fetch(url.toString(), headers: headers); final Map release = json.decode(response); - final List assets = release['assets']; + final List assets = release['assets']; final Map assetData = {}; for (final asset in assets) { @@ -85,8 +85,10 @@ Future _downloadFile( // Calculate SHA-256 hash final sha256Hash = sha256.convert(bytes).toString(); print('SHA-256 Hash: $sha256Hash'); + return sha256Hash; } print('Failed to download $filename: ${response.statusCode}'); + return ''; }