Taboo the word "simply" from our API documentation. (#116061)
This commit is contained in:
@@ -8,18 +8,18 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'recorder.dart';
|
||||
|
||||
/// Measures the performance of image decoding.
|
||||
///
|
||||
/// The benchmark measures the decoding latency and not impact on jank. It
|
||||
/// cannot distinguish between blocking and non-blocking decoding. It simply
|
||||
/// measures the total time it takes to decode image frames. For example, the
|
||||
/// WASM codecs execute on the main thread and block the UI, leading to jank,
|
||||
/// but the browser's WebCodecs API is asynchronous running on a separate thread
|
||||
/// and does not jank. However, the benchmark result may be the same.
|
||||
///
|
||||
/// This benchmark does not support the HTML renderer because the HTML renderer
|
||||
/// cannot decode image frames (it always returns 1 dummy frame, even for
|
||||
/// animated images).
|
||||
// Measures the performance of image decoding.
|
||||
//
|
||||
// The benchmark measures the decoding latency and not impact on jank. It
|
||||
// cannot distinguish between blocking and non-blocking decoding. It naively
|
||||
// measures the total time it takes to decode image frames. For example, the
|
||||
// WASM codecs execute on the main thread and block the UI, leading to jank,
|
||||
// but the browser's WebCodecs API is asynchronous running on a separate thread
|
||||
// and does not jank. However, the benchmark result may be the same.
|
||||
//
|
||||
// This benchmark does not support the HTML renderer because the HTML renderer
|
||||
// cannot decode image frames (it always returns 1 dummy frame, even for
|
||||
// animated images).
|
||||
class BenchImageDecoding extends RawRecorder {
|
||||
BenchImageDecoding() : super(
|
||||
name: benchmarkName,
|
||||
|
||||
@@ -143,6 +143,9 @@ Future<void> run(List<String> arguments) async {
|
||||
printProgress('null initialized debug fields...');
|
||||
await verifyNullInitializedDebugExpensiveFields(flutterRoot);
|
||||
|
||||
printProgress('Taboo words...');
|
||||
await verifyTabooDocumentation(flutterRoot);
|
||||
|
||||
// Ensure that all package dependencies are in sync.
|
||||
printProgress('Package dependencies...');
|
||||
await runCommand(flutter, <String>['update-packages', '--verify-only'],
|
||||
@@ -1815,18 +1818,17 @@ Future<void> verifyNullInitializedDebugExpensiveFields(String workingDirectory,
|
||||
final List<String> errors = <String>[];
|
||||
for (final File file in files) {
|
||||
final List<String> lines = file.readAsLinesSync();
|
||||
for (int i = 0; i < lines.length; i += 1) {
|
||||
final String line = lines[i];
|
||||
for (int index = 0; index < lines.length; index += 1) {
|
||||
final String line = lines[index];
|
||||
if (!line.contains(_kDebugOnlyAnnotation)) {
|
||||
continue;
|
||||
}
|
||||
final String nextLine = lines[i + 1];
|
||||
final String nextLine = lines[index + 1];
|
||||
if (_nullInitializedField.firstMatch(nextLine) == null) {
|
||||
errors.add('${file.path} L$i');
|
||||
errors.add('${file.path}:$index');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.isNotEmpty) {
|
||||
foundError(<String>[
|
||||
'${bold}ERROR: ${red}fields annotated with @_debugOnly must null initialize.$reset',
|
||||
@@ -1839,6 +1841,29 @@ Future<void> verifyNullInitializedDebugExpensiveFields(String workingDirectory,
|
||||
}
|
||||
}
|
||||
|
||||
final RegExp tabooPattern = RegExp(r'^ *///.*\b(simply)\b', caseSensitive: false);
|
||||
|
||||
Future<void> verifyTabooDocumentation(String workingDirectory, { int minimumMatches = 100 }) async {
|
||||
final List<String> errors = <String>[];
|
||||
await for (final File file in _allFiles(workingDirectory, 'dart', minimumMatches: minimumMatches)) {
|
||||
final List<String> lines = file.readAsLinesSync();
|
||||
for (int index = 0; index < lines.length; index += 1) {
|
||||
final String line = lines[index];
|
||||
final Match? match = tabooPattern.firstMatch(line);
|
||||
if (match != null) {
|
||||
errors.add('${file.path}:${index + 1}: Found use of the taboo word "${match.group(1)}" in documentation string.');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errors.isNotEmpty) {
|
||||
foundError(<String>[
|
||||
'${bold}Avoid the word "simply" in documentation. See https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-the-passive-voice-recommend-do-not-require-never-say-things-are-simple for details.$reset',
|
||||
'${bold}In many cases the word can be omitted without loss of generality; in other cases it may require a bit of rewording to avoid implying that the task is simple.$reset',
|
||||
...errors,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Future<CommandResult> _runFlutterAnalyze(String workingDirectory, {
|
||||
List<String> options = const <String>[],
|
||||
}) async {
|
||||
|
||||
@@ -16,3 +16,6 @@ class Foo {
|
||||
@_debugOnly
|
||||
final Map<String, String>? bar = kDebugMode ? null : <String, String>{};
|
||||
}
|
||||
|
||||
/// Simply avoid this
|
||||
/// and simply do that.
|
||||
|
||||
@@ -176,7 +176,18 @@ void main() {
|
||||
minimumMatches: 1,
|
||||
), shouldHaveErrors: true);
|
||||
|
||||
expect(result, contains('L15'));
|
||||
expect(result, isNot(contains('L12')));
|
||||
expect(result, contains(':15'));
|
||||
expect(result, isNot(contains(':12')));
|
||||
});
|
||||
|
||||
test('analyze.dart - verifyTabooDocumentation', () async {
|
||||
final String result = await capture(() => verifyTabooDocumentation(
|
||||
testRootPath,
|
||||
minimumMatches: 1,
|
||||
), shouldHaveErrors: true);
|
||||
|
||||
expect(result, isNot(contains(':19')));
|
||||
expect(result, contains(':20'));
|
||||
expect(result, contains(':21'));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user