lint unnecessary_new on samples (#21539)
* lint unnecessary_new on samples * fix tests
This commit is contained in:
committed by
GitHub
parent
3c58195350
commit
976cffa24d
@@ -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>[];
|
||||
|
||||
Reference in New Issue
Block a user