Unverified Commit 169bb1b7 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Fix the sample code analyzer to properly handle `missing_identifier` errors (#87593)

This fixes how the sample analyzer handles missing_identifier errors. It was looking at the wrong line, and missing an else clause, so it was silently allowing missing_identifier errors to pass.

In addition, this fixes the sample generation so that it uses the correct filename for the output files: it previously was looking for the first line that had a filename, which was meant to indicate a non-generated line. This change adds a new Line.generated constructor for generated lines, so that they can also have the correct filename associated with them.
parent cc63c814
......@@ -109,7 +109,7 @@ Future<void> run(List<String> arguments) async {
// Analyze all the sample code in the repo
print('$clock Sample code...');
await runCommand(dart,
<String>[path.join(flutterRoot, 'dev', 'bots', 'analyze_sample_code.dart'), '--verbose'],
<String>[path.join(flutterRoot, 'dev', 'bots', 'analyze_sample_code.dart')],
workingDirectory: flutterRoot,
);
......
This diff is collapsed.
......@@ -113,6 +113,14 @@
/// ```
/// {@end-tool}
///
/// {@tool snippet}
/// snippet with trailing comma
///
/// ```dart
/// const SizedBox(),
/// ```
/// {@end-tool}
///
/// {@tool dartpad --template=stateless_widget_material}
/// Dartpad with null-safe syntax
///
......
......@@ -24,7 +24,7 @@ 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 dev/bots/test/analyze-sample-code-test-input/known_broken_documentation.dart:117: child: Text(title),',
'In sample starting at dev/bots/test/analyze-sample-code-test-input/known_broken_documentation.dart:125: child: Text(title),',
">>> error: The final variable 'title' can't be read because it is potentially unassigned at this point (read_potentially_unassigned_final)",
'dev/bots/test/analyze-sample-code-test-input/known_broken_documentation.dart:30:9: new Opacity(',
'>>> info: Unnecessary new keyword (unnecessary_new)',
......@@ -36,12 +36,14 @@ void main() {
'>>> info: Prefer const over final for declarations (prefer_const_declarations)',
'dev/bots/test/analyze-sample-code-test-input/known_broken_documentation.dart:112:25: final int foo = null;',
">>> error: A value of type 'Null' can't be assigned to a variable of type 'int' (invalid_assignment)",
'dev/bots/test/analyze-sample-code-test-input/known_broken_documentation.dart:120:24: const SizedBox(),',
'>>> error: Unexpected comma at end of sample code. (missing_identifier)',
'',
'Found 2 sample code errors.',
''
]);
expect(stdoutLines, <String>[
'Found 8 snippet code blocks, 0 sample code sections, and 2 dartpad sections.',
'Found 9 snippet code blocks, 0 sample code sections, and 2 dartpad sections.',
'Starting analysis of code samples.',
'',
]);
......@@ -60,7 +62,7 @@ void main() {
expect(process.exitCode, isNot(equals(0)));
expect(stdoutLines, equals(<String>[
// There is one sample code section in the test's dummy dart:ui code.
'Found 8 snippet code blocks, 1 sample code sections, and 2 dartpad sections.',
'Found 9 snippet code blocks, 1 sample code sections, and 2 dartpad sections.',
'',
]));
});
......
......@@ -142,7 +142,7 @@ import 'text_style.dart';
/// fontSize: 30,
/// height: 1.5,
/// ),
/// ),
/// )
/// ```
/// {@end-tool}
///
......@@ -183,7 +183,7 @@ import 'text_style.dart';
/// fontFamily: 'Roboto',
/// height: 1.5,
/// ),
/// ),
/// )
/// ```
/// {@end-tool}
///
......@@ -226,7 +226,7 @@ import 'text_style.dart';
/// height: 1,
/// forceStrutHeight: true,
/// ),
/// ),
/// )
/// ```
/// {@end-tool}
///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment