API documentation cleanup (#108500)
This commit is contained in:
@@ -177,7 +177,7 @@ Future<void> run(List<String> arguments) async {
|
||||
// Analyze the code in `{@tool snippet}` sections in the repo.
|
||||
print('$clock Snippet code...');
|
||||
await runCommand(dart,
|
||||
<String>[path.join(flutterRoot, 'dev', 'bots', 'analyze_snippet_code.dart'), '--verbose'],
|
||||
<String>['--enable-asserts', path.join(flutterRoot, 'dev', 'bots', 'analyze_snippet_code.dart'), '--verbose'],
|
||||
workingDirectory: flutterRoot,
|
||||
);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,28 +8,15 @@
|
||||
|
||||
library dart.ui;
|
||||
|
||||
/// Annotation used by Flutter's Dart compiler to indicate that an
|
||||
/// [Object.toString] override should not be replaced with a supercall.
|
||||
///
|
||||
/// {@tool snippet}
|
||||
/// A sample if using keepToString to prevent replacement by a supercall.
|
||||
/// Bla bla bla bla bla bla bla bla bla.
|
||||
///
|
||||
/// ```dart
|
||||
/// class MyStringBuffer {
|
||||
/// error;
|
||||
/// error; // error (missing_const_final_var_or_type, always_specify_types)
|
||||
///
|
||||
/// StringBuffer _buffer = StringBuffer();
|
||||
///
|
||||
/// @keepToString
|
||||
/// @override
|
||||
/// String toString() {
|
||||
/// return _buffer.toString();
|
||||
/// }
|
||||
/// StringBuffer _buffer = StringBuffer(); // error (prefer_final_fields, unused_field)
|
||||
/// }
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
const Object keepToString = _KeepToString();
|
||||
|
||||
class _KeepToString {
|
||||
const _KeepToString();
|
||||
class Foo {
|
||||
const Foo();
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
// Examples can assume:
|
||||
// bool _visible = true;
|
||||
// class _Text extends Text {
|
||||
// const _Text(String text) : super(text);
|
||||
// const _Text.__(String text) : super(text);
|
||||
// const _Text(super.text);
|
||||
// const _Text.__(super.text);
|
||||
// }
|
||||
|
||||
/// A blabla that blabla its blabla blabla blabla.
|
||||
@@ -27,7 +27,7 @@
|
||||
/// blabla it when it is blabla:
|
||||
///
|
||||
/// ```dart
|
||||
/// new Opacity(
|
||||
/// new Opacity( // error (unnecessary_new)
|
||||
/// opacity: _visible ? 1.0 : 0.0,
|
||||
/// child: const Text('Poor wandering ones!'),
|
||||
/// )
|
||||
@@ -38,12 +38,12 @@
|
||||
/// Bla blabla blabla some [Text] when the `_blabla` blabla blabla is true, and
|
||||
/// blabla it when it is blabla:
|
||||
///
|
||||
/// ```dart preamble
|
||||
/// bool _visible = true;
|
||||
/// ```dart
|
||||
/// final GlobalKey globalKey = GlobalKey();
|
||||
/// ```
|
||||
///
|
||||
/// ```dart
|
||||
/// // continuing from previous example...
|
||||
/// Widget build(BuildContext context) {
|
||||
/// return Opacity(
|
||||
/// key: globalKey,
|
||||
@@ -59,7 +59,7 @@
|
||||
/// blabla finale blabla:
|
||||
///
|
||||
/// ```dart
|
||||
/// new Opacity(
|
||||
/// Opacity(
|
||||
/// opacity: _visible ? 1.0 : 0.0,
|
||||
/// child: const Text('Poor wandering ones!'),
|
||||
/// )
|
||||
@@ -92,7 +92,7 @@
|
||||
/// const variable
|
||||
///
|
||||
/// ```dart
|
||||
/// const text0 = Text('Poor wandering ones!');
|
||||
/// const Widget text0 = Text('Poor wandering ones!');
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
@@ -100,7 +100,7 @@
|
||||
/// more const variables
|
||||
///
|
||||
/// ```dart
|
||||
/// const text1 = _Text('Poor wandering ones!');
|
||||
/// const text1 = _Text('Poor wandering ones!'); // error (always_specify_types)
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
@@ -108,35 +108,61 @@
|
||||
/// Snippet with null-safe syntax
|
||||
///
|
||||
/// ```dart
|
||||
/// final String? bar = 'Hello';
|
||||
/// final int foo = null;
|
||||
/// final String? bar = 'Hello'; // error (unnecessary_nullable_for_final_variable_declarations, prefer_const_declarations)
|
||||
/// final int foo = null; // error (invalid_assignment, prefer_const_declarations)
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// {@tool snippet}
|
||||
/// snippet with trailing comma
|
||||
///
|
||||
/// ```dart
|
||||
/// const SizedBox(),
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// {@tool snippet}
|
||||
/// {@tool dartpad}
|
||||
/// Dartpad with null-safe syntax
|
||||
///
|
||||
/// ```dart preamble
|
||||
/// bool? _visible = true;
|
||||
/// ```dart
|
||||
/// final GlobalKey globalKey = GlobalKey();
|
||||
/// ```
|
||||
///
|
||||
/// ```dart
|
||||
/// // not continuing from previous example...
|
||||
/// Widget build(BuildContext context) {
|
||||
/// final String title;
|
||||
/// return Opacity(
|
||||
/// key: globalKey,
|
||||
/// opacity: _visible! ? 1.0 : 0.0,
|
||||
/// child: Text(title),
|
||||
/// key: globalKey, // error (undefined_identifier, argument_type_not_assignable)
|
||||
/// opacity: _visible ? 1.0 : 0.0,
|
||||
/// child: Text(title), // error (read_potentially_unassigned_final)
|
||||
/// );
|
||||
/// }
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// ```csv
|
||||
/// this,is,fine
|
||||
/// ```
|
||||
///
|
||||
/// ```dart
|
||||
/// import 'dart:io'; // error (unused_import)
|
||||
/// final Widget p = Placeholder(); // error (undefined_class, undefined_function, avoid_dynamic_calls)
|
||||
/// ```
|
||||
///
|
||||
/// ```dart
|
||||
/// // (e.g. in a stateful widget)
|
||||
/// void initState() { // error (must_call_super, annotate_overrides)
|
||||
/// widget.toString(); // error (undefined_identifier, return_of_invalid_type)
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```dart
|
||||
/// // not in a stateful widget
|
||||
/// void initState() {
|
||||
/// widget.toString(); // error (undefined_identifier)
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// error (something about backticks)
|
||||
/// this must be the last error, since it aborts parsing of this file
|
||||
/// ```
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This file is used by ../analyze_snippet_code_test.dart, which depends on the
|
||||
// precise contents (including especially the comments) of this file.
|
||||
|
||||
// Examples can assume:
|
||||
// int x = ''; // error (invalid_assignment)
|
||||
|
||||
/// ```dart
|
||||
/// print(x);
|
||||
/// ```
|
||||
|
||||
/// error: empty dart block
|
||||
/// ```dart
|
||||
/// ```
|
||||
@@ -2,10 +2,43 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// we ignore these so that the format of the strings below matches what package:test prints, to make maintenance easier
|
||||
// ignore_for_file: avoid_escaping_inner_quotes
|
||||
// ignore_for_file: use_raw_strings
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
const List<String> expectedMainErrors = <String>[
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:30:5: Unnecessary new keyword (expression) (unnecessary_new)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:103:5: Specify type annotations (statement) (always_specify_types)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:111:5: Prefer const over final for declarations (top-level declaration) (prefer_const_declarations)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:111:19: Use a non-nullable type for a final variable initialized with a non-nullable value (top-level declaration) (unnecessary_nullable_for_final_variable_declarations)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:112:5: Prefer const over final for declarations (top-level declaration) (prefer_const_declarations)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:112:21: A value of type \'Null\' can\'t be assigned to a variable of type \'int\' (top-level declaration) (invalid_assignment)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:134:14: The argument type \'dynamic\' can\'t be assigned to the parameter type \'Key?\' (top-level declaration) (argument_type_not_assignable)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:134:14: Undefined name \'globalKey\' (top-level declaration) (undefined_identifier)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:136:21: The final variable \'title\' can\'t be read because it\'s potentially unassigned at this point (top-level declaration) (read_potentially_unassigned_final)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:147:12: Unused import: \'dart:io\' (self-contained program) (unused_import)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:148:11: Undefined class \'Widget\' (self-contained program) (undefined_class)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:148:22: Avoid method calls or property accesses on a "dynamic" target (self-contained program) (avoid_dynamic_calls)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:148:22: The function \'Placeholder\' isn\'t defined (self-contained program) (undefined_function)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:153:10: Annotate overridden members (stateful widget) (annotate_overrides)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:153:10: This method overrides a method annotated as \'@mustCallSuper\' in \'State\', but doesn\'t invoke the overridden method (stateful widget) (must_call_super)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:161:7: Undefined name \'widget\' (top-level declaration) (undefined_identifier)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:165: Found "```" in code but it did not match RegExp: pattern=^ */// *```dart\$ flags= so something is wrong. Line was: "/// ```"',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/short_but_still_broken.dart:9:12: A value of type \'String\' can\'t be assigned to a variable of type \'int\' (statement) (invalid_assignment)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/short_but_still_broken.dart:17:4: Empty ```dart block in snippet code.',
|
||||
];
|
||||
|
||||
const List<String> expectedUiErrors = <String>[
|
||||
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:15:7: Prefer typing uninitialized variables and fields (top-level declaration) (prefer_typing_uninitialized_variables)',
|
||||
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:15:7: Variables must be declared using the keywords \'const\', \'final\', \'var\' or a type name (top-level declaration) (missing_const_final_var_or_type)',
|
||||
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:17:20: Private field could be final (top-level declaration) (prefer_final_fields)',
|
||||
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:17:20: The value of the field \'_buffer\' isn\'t used (top-level declaration) (unused_field)',
|
||||
];
|
||||
|
||||
void main() {
|
||||
// These tests don't run on Windows because the sample analyzer doesn't
|
||||
// support Windows as a platform, since it is only run on Linux in the
|
||||
@@ -17,55 +50,45 @@ void main() {
|
||||
test('analyze_snippet_code smoke test', () {
|
||||
final ProcessResult process = Process.runSync(
|
||||
'../../bin/cache/dart-sdk/bin/dart',
|
||||
<String>['analyze_snippet_code.dart', '--no-include-dart-ui', 'test/analyze-snippet-code-test-input'],
|
||||
<String>[
|
||||
'--enable-asserts',
|
||||
'analyze_snippet_code.dart',
|
||||
'--no-include-dart-ui',
|
||||
'test/analyze-snippet-code-test-input',
|
||||
],
|
||||
);
|
||||
final List<String> stdoutLines = process.stdout.toString().split('\n');
|
||||
expect(process.stdout, isEmpty);
|
||||
final List<String> stderrLines = process.stderr.toString().split('\n');
|
||||
expect(process.exitCode, isNot(equals(0)));
|
||||
expect(stderrLines, containsAll(<Object>[
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:138:25: child: Text(title),',
|
||||
matches(RegExp(r">>> error: The final variable 'title' can't be read because (it is|it's) potentially unassigned at this point \(read_potentially_unassigned_final\)")),
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:30:9: new Opacity(',
|
||||
'>>> info: Unnecessary new keyword (unnecessary_new)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:62:9: new Opacity(',
|
||||
'>>> info: Unnecessary new keyword (unnecessary_new)',
|
||||
"dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:111:9: final String? bar = 'Hello';",
|
||||
'>>> info: Prefer const over final for declarations (prefer_const_declarations)',
|
||||
'dev/bots/test/analyze-snippet-code-test-input/known_broken_documentation.dart:112:9: final int foo = null;',
|
||||
'>>> info: Prefer const over final for declarations (prefer_const_declarations)',
|
||||
'dev/bots/test/analyze-snippet-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-snippet-code-test-input/known_broken_documentation.dart:120:24: const SizedBox(),',
|
||||
'>>> error: Unexpected comma at end of snippet code. (missing_identifier)',
|
||||
'Found 1 snippet code errors.',
|
||||
]));
|
||||
expect(stdoutLines, containsAll(<String>[
|
||||
'Found 13 snippet code blocks',
|
||||
'Starting analysis of code snippets.',
|
||||
]));
|
||||
expect(stderrLines.length, stderrLines.toSet().length, reason: 'found duplicates in $stderrLines');
|
||||
expect(stderrLines, <String>[
|
||||
...expectedMainErrors,
|
||||
'Found 19 snippet code errors.',
|
||||
'See the documentation at the top of dev/bots/analyze_snippet_code.dart for details.',
|
||||
'', // because we end with a newline, split gives us an extra blank line
|
||||
]);
|
||||
expect(process.exitCode, 1);
|
||||
});
|
||||
|
||||
test('Analyzes dart:ui code', () {
|
||||
final ProcessResult process = Process.runSync(
|
||||
'../../bin/cache/dart-sdk/bin/dart',
|
||||
<String>[
|
||||
'--enable-asserts',
|
||||
'analyze_snippet_code.dart',
|
||||
'--dart-ui-location=test/analyze-snippet-code-test-dart-ui',
|
||||
'test/analyze-snippet-code-test-input',
|
||||
],
|
||||
);
|
||||
final List<String> stdoutLines = process.stdout.toString().split('\n');
|
||||
expect(process.stdout, isEmpty);
|
||||
final List<String> stderrLines = process.stderr.toString().split('\n');
|
||||
expect(process.exitCode, isNot(equals(0)));
|
||||
expect(stderrLines, containsAll(<String>[
|
||||
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:19:11: error;',
|
||||
">>> error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name (missing_const_final_var_or_type)",
|
||||
'dev/bots/test/analyze-snippet-code-test-dart-ui/ui.dart:23:11: @keepToString',
|
||||
">>> error: Undefined name 'keepToString' used as an annotation (undefined_annotation)",
|
||||
]));
|
||||
expect(stdoutLines, containsAll(<String>[
|
||||
// There is one snippet code section in the test's dummy dart:ui code.
|
||||
'Found 14 snippet code blocks',
|
||||
'Starting analysis of code snippets.',
|
||||
]));
|
||||
expect(stderrLines.length, stderrLines.toSet().length, reason: 'found duplicates in $stderrLines');
|
||||
expect(stderrLines, <String>[
|
||||
...expectedUiErrors,
|
||||
...expectedMainErrors,
|
||||
'Found 23 snippet code errors.',
|
||||
'See the documentation at the top of dev/bots/analyze_snippet_code.dart for details.',
|
||||
'', // because we end with a newline, split gives us an extra blank line
|
||||
]);
|
||||
expect(process.exitCode, 1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user