Skip to content

Commit

Permalink
Merge pull request #279 from google/devoncarew_linelength
Browse files Browse the repository at this point in the history
add a linelength arg to Dartfmt
  • Loading branch information
devoncarew committed Jun 25, 2015
2 parents a498345 + 35d43e1 commit 1f9edc7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add `sourceDirs` and `existingSourceDirs` to return the projects top-level
directories usually containing Dart source files.
- Deprecate the `Tests` class (in favor of `TestRunner`)
- Add `lineLength` as an optional argument to `DartFmt.format`

## 0.7.1+3 (2015/5/24)
- Fix bug with Dart.run/runAsync. Args were swapped.
Expand Down
17 changes: 11 additions & 6 deletions lib/grinder_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,25 @@ class Analyzer {
class DartFmt {
/// Run the `dartfmt` command with the `--overwrite` option. Format a file, a
/// directory or a list of files or directories in place.
static void format(fileOrPath) {
_run('--overwrite', coerceToPathList(fileOrPath));
static void format(fileOrPath, {int lineLength}) {
_run('--overwrite', coerceToPathList(fileOrPath), lineLength: lineLength);
}

/// Run the `dartfmt` command with the `--dry-run` option. Return `true` if
/// any files would be changed by running the formatter.
static bool dryRun(fileOrPath) {
String results = _run('--dry-run', coerceToPathList(fileOrPath));
static bool dryRun(fileOrPath, {int lineLength}) {
String results = _run('--dry-run', coerceToPathList(fileOrPath),
lineLength: lineLength);
return results.trim().isNotEmpty;
}

static String _run(String option, List<String> targets,
{bool quiet: false}) => run_lib.run(_sdkBin('dartfmt'),
quiet: quiet, arguments: [option]..addAll(targets));
{bool quiet: false, int lineLength}) {
List args = [option];
if (lineLength != null) args.add('--line-length=${lineLength}');
args.addAll(targets);
return run_lib.run(_sdkBin('dartfmt'), quiet: quiet, arguments: args);
}
}

/// Access the `pub global` commands.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'dart:convert';

/// Synchronously run an [executable].
///
/// If [quiet] is false, [log]s the stdout. The stderr is always logged.
/// If [quiet] is false, [log]s the stdout. The stderr is always logged.
///
/// Returns the stdout.
///
Expand Down Expand Up @@ -52,7 +52,7 @@ String run(String executable, {List<String> arguments: const [],

/// Synchronously run an [executable].
///
/// If [quiet] is false, [log]s the stdout. The stderr is always logged.
/// If [quiet] is false, [log]s the stdout. The stderr is always logged.
///
/// Returns the stdout.
///
Expand Down

0 comments on commit 1f9edc7

Please sign in to comment.