Skip to content

Commit

Permalink
chore: Fix linting (#849)
Browse files Browse the repository at this point in the history
<!--
  Thanks for contributing!

Provide a description of your changes below and a general summary in the
title

Please look at the following checklist to ensure that your PR can be
accepted quickly:
-->

## Description

Fixes linting according to latest linting rules.

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [ ] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [x] 🗑️ `chore` -- Chore
  • Loading branch information
spydon authored Jan 24, 2025
1 parent 949c2f6 commit 0c1df56
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 90 deletions.
8 changes: 6 additions & 2 deletions packages/melos/lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ FutureOr<void> melosEntryPoint(
logger.log(melosVersion);

// No version checks on CIs.
if (utils.isCI) return;
if (utils.isCI) {
return;
}

// Check for updates.
final pubUpdater = PubUpdater();
Expand Down Expand Up @@ -155,7 +157,9 @@ Future<MelosWorkspaceConfig> _resolveConfig(
}

bool _shouldUseEmptyConfig(List<String> arguments) {
if (arguments.firstOrNull == 'init') return true;
if (arguments.firstOrNull == 'init') {
return true;
}
final willShowHelp = arguments.isEmpty ||
arguments.contains('--help') ||
arguments.contains('-h');
Expand Down
20 changes: 15 additions & 5 deletions packages/melos/lib/src/command_runner/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,21 @@ class ListCommand extends MelosCommand {

var kind = ListOutputKind.column;

if (parsable) kind = ListOutputKind.parsable;
if (json) kind = ListOutputKind.json;
if (graph) kind = ListOutputKind.graph;
if (gviz) kind = ListOutputKind.gviz;
if (cycles) kind = ListOutputKind.cycles;
if (parsable) {
kind = ListOutputKind.parsable;
}
if (json) {
kind = ListOutputKind.json;
}
if (graph) {
kind = ListOutputKind.graph;
}
if (gviz) {
kind = ListOutputKind.gviz;
}
if (cycles) {
kind = ListOutputKind.cycles;
}

return melos.list(
long: long,
Expand Down
20 changes: 15 additions & 5 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ mixin _BootstrapMixin on _CleanMixin {
}

for (final entry in workspaceEnvironment.entries) {
if (!packageEnvironment.containsKey(entry.key)) continue;
if (packageEnvironment[entry.key] == entry.value) continue;
if (!packageEnvironment.containsKey(entry.key)) {
continue;
}
if (packageEnvironment[entry.key] == entry.value) {
continue;
}

pubspecEditor.update(
['environment', entry.key],
Expand Down Expand Up @@ -291,11 +295,15 @@ mixin _BootstrapMixin on _CleanMixin {
required Map<String, Dependency> packageDependencies,
required String pubspecKey,
}) {
if (workspaceDependencies == null) return 0;
if (workspaceDependencies == null) {
return 0;
}
// Filter out the packages that do not exist in package and only the
// dependencies that have a different version specified in the workspace.
final dependenciesToUpdate = workspaceDependencies.entries.where((entry) {
if (!packageDependencies.containsKey(entry.key)) return false;
if (!packageDependencies.containsKey(entry.key)) {
return false;
}
// TODO: We may want to replace the `pubspec` dependency with something
// else that is actively maintained, so we don't have to provide our own
// equality logic.
Expand Down Expand Up @@ -353,7 +361,9 @@ mixin _BootstrapMixin on _CleanMixin {
.map((line) {
var lineWithWorkspacePackagesHighlighted = line;
for (final workspacePackage in workspace.allPackages.values) {
if (workspacePackage.name == package.name) continue;
if (workspacePackage.name == package.name) {
continue;
}
lineWithWorkspacePackagesHighlighted =
lineWithWorkspacePackagesHighlighted.replaceAll(
'${workspacePackage.name} ',
Expand Down
8 changes: 6 additions & 2 deletions packages/melos/lib/src/commands/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ mixin _PublishMixin on _ExecMixin {

if (!force) {
final shouldContinue = promptBool();
if (!shouldContinue) throw CancelledException();
if (!shouldContinue) {
throw CancelledException();
}
logger.newLine();
}

Expand All @@ -126,7 +128,9 @@ mixin _PublishMixin on _ExecMixin {

await pool.forEach<Package, void>(workspace.filteredPackages.values,
(package) async {
if (package.isPrivate) return;
if (package.isPrivate) {
return;
}

final pubPackage = await package.getPublishedPackage();
final versions = pubPackage?.prioritizedVersions.reversed
Expand Down
8 changes: 5 additions & 3 deletions packages/melos/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ mixin _RunMixin on _Melos {
bool noSelect = false,
List<String> extraArgs = const [],
}) async {
if (config.scripts.keys.isEmpty) throw NoScriptException._();
if (config.scripts.keys.isEmpty) {
throw NoScriptException._();
}

scriptName ??= await _pickScript(config);
final script = config.scripts[scriptName];
Expand Down Expand Up @@ -217,10 +219,10 @@ mixin _RunMixin on _Melos {

Future<void> _runMultipleScripts(
Script script, {
GlobalOptions? global,
bool noSelect = false,
required Scripts scripts,
required List<String> steps,
GlobalOptions? global,
bool noSelect = false,
}) async {
final workspace = await createWorkspace(
global: global,
Expand Down
8 changes: 6 additions & 2 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ mixin _VersionMixin on _RunMixin {

if (asStableRelease) {
for (final package in workspace.filteredPackages.values) {
if (!package.version.isPreRelease) continue;
if (!package.version.isPreRelease) {
continue;
}

pendingPackageUpdates.add(
MelosPendingPackageUpdate(
Expand Down Expand Up @@ -742,7 +744,9 @@ mixin _VersionMixin on _RunMixin {
final packageCommits = <String, List<RichGitCommit>>{};
await Pool(10).forEach<Package, void>(workspace.filteredPackages.values,
(package) async {
if (!versionPrivatePackages && package.isPrivate) return;
if (!versionPrivatePackages && package.isPrivate) {
return;
}

final commits = await gitCommitsForPackage(
package,
Expand Down
12 changes: 9 additions & 3 deletions packages/melos/lib/src/common/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ extension ChangelogStringBufferExtension on StringBuffer {

final version = update.workspace.config.commands.version;

if (!version.includeCommitBody) continue;
if (parsedMessage.body == null) continue;
if (!version.includeCommitBody) {
continue;
}
if (parsedMessage.body == null) {
continue;
}

final shouldWriteBody =
!version.commitBodyOnlyBreaking || parsedMessage.isBreakingChange;
Expand Down Expand Up @@ -225,7 +229,9 @@ List<RichGitCommit> _filteredAndSortedCommits(
final r = a.parsedMessage.isBreakingChange
.toString()
.compareTo(b.parsedMessage.isBreakingChange.toString());
if (r != 0) return r;
if (r != 0) {
return r;
}
return b.parsedMessage.type!.compareTo(a.parsedMessage.type!);
});

Expand Down
18 changes: 11 additions & 7 deletions packages/melos/lib/src/common/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ Future<ProcessResult> gitExecuteCommand({
/// Optionally specify [tagReleaseType] to specify [TagReleaseType].
Future<List<String>> gitTagsForPackage(
Package package, {
required MelosLogger logger,
TagReleaseType tagReleaseType = TagReleaseType.all,
String preid = 'dev',
required MelosLogger logger,
}) async {
final filterPattern =
gitTagFilterPattern(package.name, tagReleaseType, preid: preid);
Expand Down Expand Up @@ -130,8 +130,8 @@ Future<bool> gitTagCreate(
String tag,
String message, {
required String workingDirectory,
String? commitId,
required MelosLogger logger,
String? commitId,
}) async {
if (await gitTagExists(
tag,
Expand Down Expand Up @@ -171,11 +171,13 @@ Future<bool> gitTagCreate(
/// are requested.
Future<String?> gitLatestTagForPackage(
Package package, {
String preid = 'dev',
required MelosLogger logger,
String preid = 'dev',
}) async {
// Package doesn't have a version, skip.
if (package.version.toString() == '0.0.0') return null;
if (package.version.toString() == '0.0.0') {
return null;
}

final currentVersionTag =
gitTagForPackageVersion(package.name, package.version.toString());
Expand All @@ -202,7 +204,9 @@ Future<String?> gitLatestTagForPackage(
preid: preid,
logger: logger,
);
if (tags.isEmpty) return null;
if (tags.isEmpty) {
return null;
}

return tags.first;
}
Expand Down Expand Up @@ -256,8 +260,8 @@ final _gitVersionRangeShortHandRegExp = RegExp(r'^.+\.{2,3}.+$');
/// Diff also supports specifying a range of commits, e.g. `HEAD~5..HEAD`.
Future<List<GitCommit>> gitCommitsForPackage(
Package package, {
String? diff,
required MelosLogger logger,
String? diff,
}) async {
final revisionRange =
await _resolveRevisionRange(package, diff: diff, logger: logger);
Expand Down Expand Up @@ -355,9 +359,9 @@ Future<void> gitRemoteUpdate({
/// branch.
Future<bool> gitIsBehindUpstream({
required String workingDirectory,
required MelosLogger logger,
String remote = 'origin',
String? branch,
required MelosLogger logger,
}) async {
await gitRemoteUpdate(workingDirectory: workingDirectory, logger: logger);

Expand Down
6 changes: 3 additions & 3 deletions packages/melos/lib/src/common/git_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ mixin SupportsManualRelease on HostedGitRepository {
@immutable
class GitHubRepository extends HostedGitRepository with SupportsManualRelease {
GitHubRepository({
String origin = defaultOrigin,
required this.owner,
required this.name,
String origin = defaultOrigin,
}) : origin = removeTrailingSlash(origin);

factory GitHubRepository.fromUrl(Uri uri) {
Expand Down Expand Up @@ -138,9 +138,9 @@ GitHubRepository(
@immutable
class GitLabRepository extends HostedGitRepository {
GitLabRepository({
String origin = defaultOrigin,
required this.owner,
required this.name,
String origin = defaultOrigin,
}) : origin = removeTrailingSlash(origin);

factory GitLabRepository.fromUrl(Uri uri) {
Expand Down Expand Up @@ -202,9 +202,9 @@ GitLabRepository(

class BitbucketRepository extends HostedGitRepository {
BitbucketRepository({
String origin = defaultOrigin,
required this.owner,
required this.name,
String origin = defaultOrigin,
}) : origin = removeTrailingSlash(origin);

factory BitbucketRepository.fromUrl(Uri uri) {
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/src/common/glob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:path/path.dart' as p;
/// Workaround for https://github.com/dart-lang/glob/issues/52
Glob createGlob(
String pattern, {
required String currentDirectoryPath,
p.Context? context,
bool recursive = false,
bool? caseSensitive,
required String currentDirectoryPath,
}) {
context ??= p.Context(
style: p.context.style,
Expand Down
8 changes: 6 additions & 2 deletions packages/melos/lib/src/common/intellij_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class IntellijProject {
String fileName, {
String? templateCategory,
}) async {
if (_cacheTemplates[fileName] != null) return _cacheTemplates[fileName]!;
if (_cacheTemplates[fileName] != null) {
return _cacheTemplates[fileName]!;
}

String templatesRootPath;
if (templateCategory != null) {
Expand Down Expand Up @@ -282,7 +284,9 @@ class IntellijProject {
);

await Future.forEach(_workspace.filteredPackages.values, (package) async {
if (!package.isFlutterApp) return;
if (!package.isFlutterApp) {
return;
}

final generatedRunConfiguration = injectTemplateVariables(
flutterTestTemplate,
Expand Down
8 changes: 6 additions & 2 deletions packages/melos/lib/src/common/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ void copyFile(String from, String to, {bool recursive = false}) {
/// The [File] class overwrites the symlink targets when writing to a file,
/// which is never what we want, so this delete the symlink first if necessary.
void deleteIfLink(String file) {
if (!linkExists(file)) return;
if (!linkExists(file)) {
return;
}
Link(file).deleteSync();
}

Expand Down Expand Up @@ -180,7 +182,9 @@ void _attempt(
break;
} on FileSystemException catch (error) {
final reason = getErrorReason(error);
if (reason == null) rethrow;
if (reason == null) {
rethrow;
}

if (i < maxRetries - 1) {
sleep(const Duration(milliseconds: 50));
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/common/pending_package_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class MelosPendingPackageUpdate {
this.package,
this.commits,
this.reason, {
required this.logger,
this.prerelease = false,
this.graduate = false,
this.preid,
required this.logger,
}) : manualVersion = null,
userChangelogMessage = null;

Expand All @@ -46,8 +46,8 @@ class MelosPendingPackageUpdate {
this.package,
this.commits,
this.manualVersion, {
this.userChangelogMessage,
required this.logger,
this.userChangelogMessage,
}) : reason = PackageUpdateReason.manual,
prerelease = false,
graduate = false,
Expand Down
4 changes: 3 additions & 1 deletion packages/melos/lib/src/common/pub_credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class PubCredential {
}

String? getAuthHeader() {
if (!isValid()) return null;
if (!isValid()) {
return null;
}
return 'Bearer $_tokenValue';
}
}
Loading

0 comments on commit 0c1df56

Please sign in to comment.