Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --line-length option to melos format command #689

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 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,7 @@ 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 = int.parse(argResults!['line-length'] as String);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to accept null too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it. thanks.


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

Expand All @@ -41,6 +46,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
Loading