Unnecessary new (#20138)

* enable lint unnecessary_new

* fix tests

* fix tests

* fix tests
This commit is contained in:
Alexandre Ardhuin
2018-09-12 08:29:29 +02:00
committed by GitHub
parent d7a0dcaa4a
commit d927c93310
1285 changed files with 26519 additions and 26519 deletions

View File

@@ -58,7 +58,7 @@ class Line {
Line operator +(int count) {
if (count == 0)
return this;
return new Line(filename, line + count, indent);
return Line(filename, line + count, indent);
}
@override
String toString([int column]) {
@@ -87,7 +87,7 @@ class Section {
}
}
List<Line> get lines {
final List<Line> result = new List<Line>.generate(code.length, (int index) => start + index);
final List<Line> result = List<Line>.generate(code.length, (int index) => start + index);
if (preamble != null)
result.insert(0, null);
if (postamble != null)
@@ -105,15 +105,15 @@ Future<Null> main(List<String> arguments) async {
bool keepMain = false;
final List<String> buffer = <String>[];
try {
final File mainDart = new File(path.join(tempDir.path, 'main.dart'));
final File pubSpec = new File(path.join(tempDir.path, 'pubspec.yaml'));
final File analysisOptions = new File(path.join(tempDir.path, 'analysis_options.yaml'));
final File mainDart = File(path.join(tempDir.path, 'main.dart'));
final File pubSpec = File(path.join(tempDir.path, 'pubspec.yaml'));
final File analysisOptions = File(path.join(tempDir.path, 'analysis_options.yaml'));
Directory flutterPackage;
if (arguments.length == 1) {
// Used for testing.
flutterPackage = new Directory(arguments.single);
flutterPackage = Directory(arguments.single);
} else {
flutterPackage = new Directory(path.join(_flutterRoot, 'packages', 'flutter', 'lib'));
flutterPackage = Directory(path.join(_flutterRoot, 'packages', 'flutter', 'lib'));
}
final List<Section> sections = <Section>[];
int sampleCodeSections = 0;
@@ -161,7 +161,7 @@ Future<Null> main(List<String> arguments) async {
}
} else if (trimmedLine == '/// ```dart') {
assert(block.isEmpty);
startLine = new Line(file.path, lineNumber + 1, line.indexOf(kDartDocPrefixWithSpace) + kDartDocPrefixWithSpace.length);
startLine = Line(file.path, lineNumber + 1, line.indexOf(kDartDocPrefixWithSpace) + kDartDocPrefixWithSpace.length);
inDart = true;
foundDart = true;
}
@@ -170,7 +170,7 @@ Future<Null> main(List<String> arguments) async {
if (!inSampleSection) {
if (line == '// Examples can assume:') {
assert(block.isEmpty);
startLine = new Line(file.path, lineNumber + 1, 3);
startLine = Line(file.path, lineNumber + 1, 3);
inPreamble = true;
} else if (trimmedLine == '/// ## Sample code' ||
trimmedLine.startsWith('/// ## Sample code:') ||
@@ -199,7 +199,7 @@ Future<Null> main(List<String> arguments) async {
}
}
buffer.add('');
final List<Line> lines = new List<Line>.filled(buffer.length, null, growable: true);
final List<Line> lines = List<Line>.filled(buffer.length, null, growable: true);
for (Section section in sections) {
buffer.addAll(section.strings);
lines.addAll(section.lines);
@@ -247,7 +247,7 @@ linter:
errors.removeAt(0);
int errorCount = 0;
final String kBullet = Platform.isWindows ? ' - ' : ' • ';
final RegExp errorPattern = new RegExp('^ +([a-z]+)$kBullet(.+)$kBullet(.+):([0-9]+):([0-9]+)$kBullet([-a-z_]+)\$', caseSensitive: false);
final RegExp errorPattern = RegExp('^ +([a-z]+)$kBullet(.+)$kBullet(.+):([0-9]+):([0-9]+)$kBullet([-a-z_]+)\$', caseSensitive: false);
for (String error in errors) {
final Match parts = errorPattern.matchAsPrefix(error);
if (parts != null) {
@@ -315,7 +315,7 @@ linter:
exit(exitCode);
}
final RegExp _constructorRegExp = new RegExp(r'[A-Z][a-zA-Z0-9<>.]*\(');
final RegExp _constructorRegExp = RegExp(r'[A-Z][a-zA-Z0-9<>.]*\(');
int _expressionId = 0;
@@ -324,12 +324,12 @@ void processBlock(Line line, List<String> block, List<Section> sections) {
throw '$line: Empty ```dart block in sample code.';
if (block.first.startsWith('new ') || block.first.startsWith('const ') || block.first.startsWith(_constructorRegExp)) {
_expressionId += 1;
sections.add(new Section(line, 'dynamic expression$_expressionId = ', block.toList(), ';'));
sections.add(Section(line, 'dynamic expression$_expressionId = ', block.toList(), ';'));
} else if (block.first.startsWith('await ')) {
_expressionId += 1;
sections.add(new Section(line, 'Future<Null> expression$_expressionId() async { ', block.toList(), ' }'));
sections.add(Section(line, 'Future<Null> expression$_expressionId() async { ', block.toList(), ' }'));
} else if (block.first.startsWith('class ') || block.first.startsWith('enum ')) {
sections.add(new Section(line, null, block.toList(), null));
sections.add(Section(line, null, block.toList(), null));
} else {
final List<String> buffer = <String>[];
int subblocks = 0;
@@ -354,7 +354,7 @@ void processBlock(Line line, List<String> block, List<Section> sections) {
if (subline != null)
processBlock(subline, buffer, sections);
} else {
sections.add(new Section(line, null, block.toList(), null));
sections.add(Section(line, null, block.toList(), null));
}
}
block.clear();