Skip to content

Commit

Permalink
fix: tryParse line-length to int when it's not already an integer (#708)
Browse files Browse the repository at this point in the history
* fix: tryParse line-length to int when it's not already an integer

* test: add format with line-length test
  • Loading branch information
jkoenig134 committed Apr 26, 2024
1 parent b538eef commit 35ef462
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/melos/lib/src/command_runner/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FormatCommand extends MelosCommand {
final concurrency = int.parse(argResults!['concurrency'] as String);
final lineLength = switch (argResults?['line-length']) {
final int length => length,
final String length => int.tryParse(length),
_ => null,
};

Expand Down
34 changes: 34 additions & 0 deletions packages/melos/test/commands/format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,39 @@ $ melos format
skip: 'Differ at offset 1261',
);
});

test('should run format with --line-length flag', () async {
const code = '''
void main() {
print('a very long line that should be wrapped with default dart settings but we use a longer line length');
}
''';

writeTextFile(
p.join(aDir.path, 'main.dart'),
code,
);

final result = await Process.run(
'melos',
['format', '--set-exit-if-changed', '--line-length', '150'],
workingDirectory: workspaceDir.path,
runInShell: Platform.isWindows,
stdoutEncoding: utf8,
stderrEncoding: utf8,
);

expect(result.exitCode, equals(0));

expect(
result.stdout,
contains(
r'''
$ melos format
└> dart format --set-exit-if-changed --line-length 150 .
└> SUCCESS''',
),
);
});
});
}

0 comments on commit 35ef462

Please sign in to comment.