Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 2.0.2-dev

* Don't unnecessarily split argument lists with `/* */` comments (#837).
* Return correct exit code from `FormatCommand` when formatting stdin (#1035).

# 2.0.1

Expand Down
4 changes: 2 additions & 2 deletions bin/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:dart_style/src/cli/summary.dart';
import 'package:dart_style/src/io.dart';
import 'package:dart_style/src/style_fix.dart';

void main(List<String> args) {
void main(List<String> args) async {
var parser = ArgParser(allowTrailingOptions: true);

defineOptions(parser,
Expand Down Expand Up @@ -135,7 +135,7 @@ void main(List<String> args) {
setExitIfChanged: setExitIfChanged);

if (argResults.rest.isEmpty) {
formatStdin(options, selection, argResults['stdin-name'] as String);
await formatStdin(options, selection, argResults['stdin-name'] as String);
} else {
formatPaths(options, argResults.rest);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cli/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class FormatCommand extends Command<int> {
setExitIfChanged: setExitIfChanged);

if (argResults.rest.isEmpty) {
formatStdin(options, selection, stdinName);
await formatStdin(options, selection, stdinName);
} else {
formatPaths(options, argResults.rest);
options.summary.show();
Expand Down
11 changes: 7 additions & 4 deletions lib/src/io.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library dart_style.src.io;

import 'dart:async';
import 'dart:convert';
import 'dart:io';

Expand All @@ -15,7 +13,7 @@ import 'exceptions.dart';
import 'source_code.dart';

/// Reads and formats input from stdin until closed.
void formatStdin(FormatterOptions options, List<int>? selection, String name) {
Future<void> formatStdin(FormatterOptions options, List<int>? selection, String name) async {
var selectionStart = 0;
var selectionLength = 0;

Expand All @@ -24,6 +22,7 @@ void formatStdin(FormatterOptions options, List<int>? selection, String name) {
selectionLength = selection[1];
}

var completer = Completer<void>();
var input = StringBuffer();
stdin.transform(Utf8Decoder()).listen(input.write, onDone: () {
var formatter = DartFormatter(
Expand All @@ -50,7 +49,11 @@ $err
$stack''');
exitCode = 70; // sysexits.h: EX_SOFTWARE
}

completer.complete();
});

return completer.future;
}

/// Formats all of the files and directories given by [paths].
Expand Down