Skip to content

Commit

Permalink
feat: add --line-length option to melos format command (#689)
Browse files Browse the repository at this point in the history
* add line-length option for format command

* Make lineLength parameter nullable

* make line-length nullable

* fix cast error
  • Loading branch information
utamori authored Apr 2, 2024
1 parent 2af2877 commit 048ab30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/melos/lib/src/command_runner/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class FormatCommand extends MelosCommand {
'[write] Overwrite formatted files on disk.\n',
abbr: 'o',
);
argParser.addOption(
'line-length',
help: 'The line length to format the code to.',
);
}

@override
Expand All @@ -32,6 +36,10 @@ class FormatCommand extends MelosCommand {
final setExitIfChanged = argResults?['set-exit-if-changed'] as bool;
final output = argResults?['output'] as String?;
final concurrency = int.parse(argResults!['concurrency'] as String);
final lineLength = switch (argResults?['line-length']) {
final int length => length,
_ => null,
};

final melos = Melos(logger: logger, config: config);

Expand All @@ -41,6 +49,7 @@ class FormatCommand extends MelosCommand {
concurrency: concurrency,
setExitIfChanged: setExitIfChanged,
output: output,
lineLength: lineLength,
);
}
}
4 changes: 4 additions & 0 deletions packages/melos/lib/src/commands/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mixin _FormatMixin on _Melos {
int concurrency = 1,
bool setExitIfChanged = false,
String? output,
int? lineLength,
}) async {
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);
Expand All @@ -18,6 +19,7 @@ mixin _FormatMixin on _Melos {
concurrency: concurrency,
setExitIfChanged: setExitIfChanged,
output: output,
lineLength: lineLength,
);
}

Expand All @@ -27,6 +29,7 @@ mixin _FormatMixin on _Melos {
required int concurrency,
required bool setExitIfChanged,
String? output,
int? lineLength,
}) async {
final failures = <String, int?>{};
final pool = Pool(concurrency);
Expand All @@ -35,6 +38,7 @@ mixin _FormatMixin on _Melos {
'format',
if (setExitIfChanged) '--set-exit-if-changed',
if (output != null) '--output $output',
if (lineLength != null) '--line-length $lineLength',
'.',
];
final formatArgsString = formatArgs.join(' ');
Expand Down

0 comments on commit 048ab30

Please sign in to comment.