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>[];
|
||||
|
||||
@@ -30,8 +30,10 @@ void main() {
|
||||
"$directory/main.dart:5:8: Unused import: 'dart:ui'",
|
||||
"$directory/main.dart:6:8: Unused import: 'package:flutter_test/flutter_test.dart'",
|
||||
"$directory/main.dart:9:8: Target of URI doesn't exist: 'package:flutter/known_broken_documentation.dart'",
|
||||
'test/analyze-sample-code-test-input/known_broken_documentation.dart:27:5: Unnecessary new keyword (unnecessary_new)',
|
||||
"test/analyze-sample-code-test-input/known_broken_documentation.dart:27:9: Undefined class 'Opacity' (undefined_class)",
|
||||
"test/analyze-sample-code-test-input/known_broken_documentation.dart:29:20: Undefined class 'Text' (undefined_class)",
|
||||
'test/analyze-sample-code-test-input/known_broken_documentation.dart:39:5: Unnecessary new keyword (unnecessary_new)',
|
||||
"test/analyze-sample-code-test-input/known_broken_documentation.dart:39:9: Undefined class 'Opacity' (undefined_class)",
|
||||
"test/analyze-sample-code-test-input/known_broken_documentation.dart:41:20: Undefined class 'Text' (undefined_class)",
|
||||
'test/analyze-sample-code-test-input/known_broken_documentation.dart:42:5: unexpected comma at end of sample code',
|
||||
|
||||
Reference in New Issue
Block a user