Update samples to use repo analysis options, Fix sample templates and a ton of analyzer issues (#77868)

This commit is contained in:
Greg Spencer
2021-03-11 16:45:03 -08:00
committed by GitHub
parent d6f5767ec8
commit a8d820a46e
168 changed files with 1429 additions and 1115 deletions

View File

@@ -17,20 +17,32 @@ void main() {
..removeWhere((String line) => line.startsWith('Analyzer output:') || line.startsWith('Building flutter tool...'));
expect(process.exitCode, isNot(equals(0)));
expect(stderrLines, <String>[
'In sample starting at known_broken_documentation.dart:117:bool? _visible = true;',
'>>> info: Use late for private members with non-nullable type (use_late_for_private_fields_and_variables)',
'In sample starting at known_broken_documentation.dart:117: child: Text(title),',
'>>> The final variable \'title\' can\'t be read because it is potentially unassigned at this point (read_potentially_unassigned_final)',
'>>> error: The final variable \'title\' can\'t be read because it is potentially unassigned at this point (read_potentially_unassigned_final)',
'known_broken_documentation.dart:30:9: new Opacity(',
'>>> Unnecessary new keyword (unnecessary_new)',
'>>> info: Unnecessary new keyword (unnecessary_new)',
'known_broken_documentation.dart:62:9: new Opacity(',
'>>> Unnecessary new keyword (unnecessary_new)',
'>>> info: Unnecessary new keyword (unnecessary_new)',
'known_broken_documentation.dart:95:9: const text0 = Text(\'Poor wandering ones!\');',
'>>> info: Specify type annotations (always_specify_types)',
'known_broken_documentation.dart:103:9: const text1 = _Text(\'Poor wandering ones!\');',
'>>> info: Specify type annotations (always_specify_types)',
'known_broken_documentation.dart:111:9: final String? bar = \'Hello\';',
'>>> info: Prefer const over final for declarations (prefer_const_declarations)',
'known_broken_documentation.dart:111:23: final String? bar = \'Hello\';',
'>>> info: Use a non-nullable type for a final variable initialized with a non-nullable value (unnecessary_nullable_for_final_variable_declarations)',
'known_broken_documentation.dart:112:9: final int foo = null;',
'>>> info: Prefer const over final for declarations (prefer_const_declarations)',
'known_broken_documentation.dart:112:25: final int foo = null;',
'>>> A value of type \'Null\' can\'t be assigned to a variable of type \'int\' (invalid_assignment)',
'>>> error: A value of type \'Null\' can\'t be assigned to a variable of type \'int\' (invalid_assignment)',
'',
'Found 2 sample code errors.',
''
]);
expect(stdoutLines, <String>[
'Found 8 sample code sections.',
'Found 8 snippet code blocks, 0 sample code sections, and 2 dartpad sections.',
'Starting analysis of code samples.',
'',
]);

View File

@@ -28,7 +28,12 @@ Future<String> capture(AsyncVoidCallback callback, { int exitCode = 0 }) async {
} finally {
print = oldPrint;
}
return buffer.toString();
if (stdout.supportsAnsiEscapes) {
// Remove ANSI escapes when this test is running on a terminal.
return buffer.toString().replaceAll(RegExp(r'(\x9B|\x1B\[)[0-?]{1,3}[ -/]*[@-~]'), '');
} else {
return buffer.toString();
}
}
void main() {