Permalink
Browse files

Don't remove "new" and "const" from dartfmt itself yet. (#701)

Reverts d80a1ea.

Since people import dartfmt as a library, I don't want to require them
to move to Dart 2 just yet, so I'm going to postpone removing "new" and
"const" from dartfmt itself for a while.

It, of course, still supports "--fix" and is able to remove them from
*your* code.
  • Loading branch information...
munificent committed Jun 18, 2018
1 parent aa9eefa commit 8d6511e71ffb977d08e3aad68a24534c144f8cb3
View
@@ -25,7 +25,7 @@ void main(List<String> args) {
// Run the benchmark several times. This ensures the VM is warmed up and lets
// us see how much variance there is.
for (var i = 0; i <= NUM_TRIALS; i++) {
var start = DateTime.now();
var start = new DateTime.now();
// For a single benchmark, format the source multiple times.
var result;
@@ -34,7 +34,7 @@ void main(List<String> args) {
}
var elapsed =
DateTime.now().difference(start).inMilliseconds / FORMATS_PER_TRIAL;
new DateTime.now().difference(start).inMilliseconds / FORMATS_PER_TRIAL;
// Keep track of the best run so far.
if (elapsed >= best) continue;
@@ -58,7 +58,7 @@ void main(List<String> args) {
String loadFile(String name) {
var path = p.join(p.dirname(p.fromUri(Platform.script)), name);
return File(path).readAsStringSync();
return new File(path).readAsStringSync();
}
void printResult(String label, double time) {
@@ -76,6 +76,6 @@ String padLeft(input, int length) {
}
String formatSource() {
var formatter = DartFormatter();
var formatter = new DartFormatter();
return formatter.format(source);
}
View
@@ -18,7 +18,7 @@ import 'package:dart_style/src/style_fix.dart';
const version = "1.0.14";
void main(List<String> args) {
var parser = ArgParser(allowTrailingOptions: true);
var parser = new ArgParser(allowTrailingOptions: true);
parser.addSeparator("Common options:");
parser.addFlag("help",
@@ -127,11 +127,11 @@ void main(List<String> args) {
}
if (argResults["profile"]) {
reporter = ProfileReporter(reporter);
reporter = new ProfileReporter(reporter);
}
if (argResults["set-exit-if-changed"]) {
reporter = SetExitReporter(reporter);
reporter = new SetExitReporter(reporter);
}
var pageWidth;
@@ -148,7 +148,7 @@ void main(List<String> args) {
try {
indent = int.parse(argResults["indent"]);
if (indent < 0 || indent.toInt() != indent) throw FormatException();
if (indent < 0 || indent.toInt() != indent) throw new FormatException();
} on FormatException catch (_) {
usageError(
parser,
@@ -170,7 +170,7 @@ void main(List<String> args) {
}
}
var options = FormatterOptions(reporter,
var options = new FormatterOptions(reporter,
indent: indent,
pageWidth: pageWidth,
followLinks: followLinks,
@@ -192,7 +192,7 @@ List<int> parseSelection(String selection) {
var coordinates = selection.split(":");
if (coordinates.length != 2) {
throw FormatException(
throw new FormatException(
'Selection should be a colon-separated pair of integers, "123:45".');
}
@@ -209,15 +209,15 @@ void formatStdin(FormatterOptions options, List<int> selection) {
selectionLength = selection[1];
}
var input = StringBuffer();
stdin.transform(Utf8Decoder()).listen(input.write, onDone: () {
var formatter = DartFormatter(
var input = new StringBuffer();
stdin.transform(new Utf8Decoder()).listen(input.write, onDone: () {
var formatter = new DartFormatter(
indent: options.indent,
pageWidth: options.pageWidth,
fixes: options.fixes);
try {
options.reporter.beforeFile(null, "<stdin>");
var source = SourceCode(input.toString(),
var source = new SourceCode(input.toString(),
uri: "stdin",
selectionStart: selectionStart,
selectionLength: selectionLength);
@@ -241,15 +241,15 @@ $stack''');
/// Formats all of the files and directories given by [paths].
void formatPaths(FormatterOptions options, List<String> paths) {
for (var path in paths) {
var directory = Directory(path);
var directory = new Directory(path);
if (directory.existsSync()) {
if (!processDirectory(options, directory)) {
exitCode = 65;
}
continue;
}
var file = File(path);
var file = new File(path);
if (file.existsSync()) {
if (!processFile(options, file)) {
exitCode = 65;
View
@@ -35,7 +35,7 @@ void formatUnit(String source, [int pageWidth = 80]) {
void runFormatter(String source, int pageWidth, {bool isCompilationUnit}) {
try {
var formatter = DartFormatter(pageWidth: pageWidth);
var formatter = new DartFormatter(pageWidth: pageWidth);
var result;
if (isCompilationUnit) {
@@ -61,7 +61,7 @@ void drawRuler(String label, int width) {
/// Runs the formatter test starting on [line] at [path] inside the "test"
/// directory.
void runTest(String path, int line) {
var indentPattern = RegExp(r"^\(indent (\d+)\)\s*");
var indentPattern = new RegExp(r"^\(indent (\d+)\)\s*");
// Locate the "test" directory. Use mirrors so that this works with the test
// package, which loads this suite into an isolate.
@@ -72,7 +72,7 @@ void runTest(String path, int line) {
.path),
"../test");
var lines = File(p.join(testDir, path)).readAsLinesSync();
var lines = new File(p.join(testDir, path)).readAsLinesSync();
// The first line may have a "|" to indicate the page width.
var pageWidth = 80;
@@ -121,7 +121,8 @@ void runTest(String path, int line) {
var expected =
_extractSelection(expectedOutput, isCompilationUnit: isCompilationUnit);
var formatter = DartFormatter(pageWidth: pageWidth, indent: leadingIndent);
var formatter =
new DartFormatter(pageWidth: pageWidth, indent: leadingIndent);
var actual = formatter.formatSource(inputCode);
@@ -150,14 +151,14 @@ void runTest(String path, int line) {
/// Given a source string that contains ‹ and › to indicate a selection, returns
/// a [SourceCode] with the text (with the selection markers removed) and the
/// correct selection range.
SourceCode _extractSelection(String source, {bool isCompilationUnit = false}) {
SourceCode _extractSelection(String source, {bool isCompilationUnit: false}) {
var start = source.indexOf("‹");
source = source.replaceAll("‹", "");
var end = source.indexOf("›");
source = source.replaceAll("›", "");
return SourceCode(source,
return new SourceCode(source,
isCompilationUnit: isCompilationUnit,
selectionStart: start == -1 ? null : start,
selectionLength: end == -1 ? null : end - start);
@@ -57,7 +57,7 @@ class ArgumentListVisitor {
_arguments._blocks.isNotEmpty || _functions != null;
factory ArgumentListVisitor(SourceVisitor visitor, ArgumentList node) {
return ArgumentListVisitor.forArguments(
return new ArgumentListVisitor.forArguments(
visitor, node.leftParenthesis, node.rightParenthesis, node.arguments);
}
@@ -147,8 +147,14 @@ class ArgumentListVisitor {
if (functionsStart == null) {
// No functions, so there is just a single argument list.
return ArgumentListVisitor._(visitor, leftParenthesis, rightParenthesis,
arguments, ArgumentSublist(arguments, arguments), null, null);
return new ArgumentListVisitor._(
visitor,
leftParenthesis,
rightParenthesis,
arguments,
new ArgumentSublist(arguments, arguments),
null,
null);
}
// Split the arguments into two independent argument lists with the
@@ -157,14 +163,14 @@ class ArgumentListVisitor {
var functions = arguments.sublist(functionsStart, functionsEnd);
var argumentsAfter = arguments.skip(functionsEnd).toList();
return ArgumentListVisitor._(
return new ArgumentListVisitor._(
visitor,
leftParenthesis,
rightParenthesis,
arguments,
ArgumentSublist(arguments, argumentsBefore),
new ArgumentSublist(arguments, argumentsBefore),
functions,
ArgumentSublist(arguments, argumentsAfter));
new ArgumentSublist(arguments, argumentsAfter));
}
ArgumentListVisitor._(
@@ -364,7 +370,7 @@ class ArgumentSublist {
blocks.clear();
}
return ArgumentSublist._(
return new ArgumentSublist._(
allArguments, positional, named, blocks, leadingBlocks, trailingBlocks);
}
@@ -373,7 +379,7 @@ class ArgumentSublist {
void visit(SourceVisitor visitor) {
if (_blocks.isNotEmpty) {
_blockRule = Rule(Cost.splitBlocks);
_blockRule = new Rule(Cost.splitBlocks);
}
var rule = _visitPositional(visitor);
@@ -388,7 +394,7 @@ class ArgumentSublist {
// Only count the blocks in the positional rule.
var leadingBlocks = math.min(_leadingBlocks, _positional.length);
var trailingBlocks = math.max(_trailingBlocks - _named.length, 0);
var rule = PositionalRule(_blockRule, leadingBlocks, trailingBlocks);
var rule = new PositionalRule(_blockRule, leadingBlocks, trailingBlocks);
_visitArguments(visitor, _positional, rule);
return rule;
@@ -401,7 +407,7 @@ class ArgumentSublist {
// Only count the blocks in the named rule.
var leadingBlocks = math.max(_leadingBlocks - _positional.length, 0);
var trailingBlocks = math.min(_trailingBlocks, _named.length);
var namedRule = NamedRule(_blockRule, leadingBlocks, trailingBlocks);
var namedRule = new NamedRule(_blockRule, leadingBlocks, trailingBlocks);
// Let the positional args force the named ones to split.
if (positionalRule != null) {
@@ -157,7 +157,7 @@ class CallChainVisitor {
// See if this call is a method call whose arguments are block formatted.
var isBlockCall = false;
if (call is MethodInvocation) {
var args = ArgumentListVisitor(visitor, call.argumentList);
var args = new ArgumentListVisitor(visitor, call.argumentList);
isBlockCall = args.hasBlockArguments;
}
@@ -187,7 +187,7 @@ class CallChainVisitor {
calls.remove(hangingCall);
}
return CallChainVisitor._(
return new CallChainVisitor._(
visitor, target, properties, calls, blockCalls, hangingCall);
}
@@ -214,7 +214,7 @@ class CallChainVisitor {
if (splitOnTarget) {
if (_properties.length > 1) {
_propertyRule = PositionalRule(null, 0, 0);
_propertyRule = new PositionalRule(null, 0, 0);
_visitor.builder.startLazyRule(_propertyRule);
} else {
_enableRule(lazy: true);
@@ -230,7 +230,7 @@ class CallChainVisitor {
_writeCall(_properties.single);
} else if (_properties.length > 1) {
if (!splitOnTarget) {
_propertyRule = PositionalRule(null, 0, 0);
_propertyRule = new PositionalRule(null, 0, 0);
_visitor.builder.startRule(_propertyRule);
}
@@ -432,11 +432,11 @@ class CallChainVisitor {
}
/// Creates a new method chain [Rule] if one is not already active.
void _enableRule({bool lazy = false}) {
void _enableRule({bool lazy: false}) {
if (_ruleEnabled) return;
// If the properties split, force the calls to split too.
var rule = Rule();
var rule = new Rule();
if (_propertyRule != null) _propertyRule.setNamedArgsRule(rule);
if (lazy) {
View
@@ -225,7 +225,7 @@ class Chunk extends Selection {
/// Turns this chunk into one that can contain a block of child chunks.
void makeBlock(Chunk blockArgument) {
assert(_block == null);
_block = ChunkBlock(blockArgument);
_block = new ChunkBlock(blockArgument);
}
/// Returns `true` if the block body owned by this chunk should be expression
Oops, something went wrong.

0 comments on commit 8d6511e

Please sign in to comment.