lint unnecessary_new on samples (#21539)

* lint unnecessary_new on samples

* fix tests
This commit is contained in:
Alexandre Ardhuin
2018-09-07 11:00:05 +02:00
committed by GitHub
parent 3c58195350
commit 976cffa24d
93 changed files with 726 additions and 721 deletions

View File

@@ -218,6 +218,7 @@ dependencies:
linter:
rules:
- unnecessary_const
- unnecessary_new
''');
print('Found $sampleCodeSections sample code sections.');
final Process process = await Process.start(
@@ -314,18 +315,20 @@ linter:
exit(exitCode);
}
final RegExp _constructorRegExp = new RegExp(r'[A-Z][a-zA-Z0-9<>.]*\(');
int _expressionId = 0;
void processBlock(Line line, List<String> block, List<Section> sections) {
if (block.isEmpty)
throw '$line: Empty ```dart block in sample code.';
if (block.first.startsWith('new ') || block.first.startsWith('const ')) {
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(), ';'));
} else if (block.first.startsWith('await ')) {
_expressionId += 1;
sections.add(new Section(line, 'Future<Null> expression$_expressionId() async { ', block.toList(), ' }'));
} else if (block.first.startsWith('class ')) {
} else if (block.first.startsWith('class ') || block.first.startsWith('enum ')) {
sections.add(new Section(line, null, block.toList(), null));
} else {
final List<String> buffer = <String>[];