Analyze all dart code on CI (flutter/engine#35147)

This commit is contained in:
Michael Goderbauer
2022-08-05 10:38:05 -07:00
committed by GitHub
parent bbcfc5c06f
commit bfd0781318
21 changed files with 80 additions and 71 deletions

View File

@@ -54,29 +54,21 @@ echo ""
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/flutter_frontend_server"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/licenses"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/litetest"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/benchmark"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/smoke_test_failure"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/dart"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/scenario_app"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/symbols"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/githooks"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/clang_tidy"
(cd "$FLUTTER_DIR/testing/skia_gold_client"; "$DART" pub get)
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing"
echo ""
# Check that dart libraries conform.
echo "Checking the integrity of the Web SDK"
(cd "$FLUTTER_DIR/web_sdk"; "$DART" pub get)
(cd "$FLUTTER_DIR/web_sdk/web_test_utils"; "$DART" pub get)
(cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; "$DART" pub get)
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/web_sdk"
WEB_SDK_TEST_FILES="$FLUTTER_DIR/web_sdk/test/*"
for testFile in $WEB_SDK_TEST_FILES
do

View File

@@ -0,0 +1,5 @@
include: ../analysis_options.yaml
linter:
rules:
avoid_print: false

View File

@@ -36,11 +36,11 @@ List<String> getDartClassFields({
final RegExp fieldExp = RegExp(r'_k(\w*)Index');
final List<String> fields = <String>[];
for (final CompilationUnitMember unitMember in result.unit.declarations) {
if (unitMember is ClassDeclaration && unitMember.name.name == className) {
if (unitMember is ClassDeclaration && unitMember.name.name == className) { // ignore: deprecated_member_use
for (final ClassMember classMember in unitMember.members) {
if (classMember is FieldDeclaration) {
for (final VariableDeclaration field in classMember.fields.variables) {
final String fieldName = field.name.name;
final String fieldName = field.name.name; // ignore: deprecated_member_use
final RegExpMatch? match = fieldExp.firstMatch(fieldName);
if (match != null) {
fields.add(match.group(1)!);

View File

@@ -28,13 +28,13 @@ environment:
dependencies:
analyzer: any
_fe_analyzer_shared: any
pub_semver: any
dev_dependencies:
async_helper: any
expect: any
litetest: any
path: any
pub_semver: any
smith: any
dependency_overrides:

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: avoid_dynamic_calls
import 'dart:convert' show jsonEncode;
import 'dart:io';
@@ -175,7 +177,7 @@ Future<void> main(List<String> args) async {
final String frontendServer = args[0];
final String sdkRoot = args[1];
try {
void _checkProcessResult(ProcessResult result) {
void checkProcessResult(ProcessResult result) {
if (result.exitCode != 0) {
stdout.writeln(result.stdout);
stderr.writeln(result.stderr);
@@ -186,7 +188,7 @@ Future<void> main(List<String> args) async {
stdout.writeln('Generating kernel fixtures...');
stdout.writeln(consts);
_checkProcessResult(Process.runSync(dart, <String>[
checkProcessResult(Process.runSync(dart, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
@@ -197,7 +199,7 @@ Future<void> main(List<String> args) async {
box,
]));
_checkProcessResult(Process.runSync(dart, <String>[
checkProcessResult(Process.runSync(dart, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
@@ -208,7 +210,7 @@ Future<void> main(List<String> args) async {
consts,
]));
_checkProcessResult(Process.runSync(dart, <String>[
checkProcessResult(Process.runSync(dart, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',

View File

@@ -9,9 +9,9 @@
// https://github.com/dart-lang/sdk/blob/ca3ad264a64937d5d336cd04dbf2746d1b7d8fc4/tests/language_2/canonicalize/hashing_memoize_instance_test.dart
class Box {
const Box(this.content1, this.content2);
final Object content1;
final Object content2;
const Box(this.content1, this.content2);
}
const Box box1_0 = Box(null, null);
@@ -217,7 +217,7 @@ const Box box2_98 = Box(box2_97, box2_97);
const Box box2_99 = Box(box2_98, box2_98);
Object confuse(Box x) {
try { throw x; } catch (e) { return e; }
try { throw x; } catch (e) { return e; } // ignore: only_throw_errors
}
void main() {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: prefer_const_constructors, unused_local_variable
// ignore_for_file: prefer_const_constructors, unused_local_variable, depend_on_referenced_packages
import 'dart:core';
import 'package:const_finder_fixtures_package/package.dart';

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: prefer_const_constructors, unused_local_variable
// ignore_for_file: prefer_const_constructors, unused_local_variable, depend_on_referenced_packages
import 'dart:core';
import 'package:const_finder_fixtures_package/package.dart';

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: prefer_const_constructors
// ignore_for_file: prefer_const_constructors, depend_on_referenced_packages
import 'package:const_finder_fixtures/target.dart';
void createTargetInPackage() {

View File

@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(goderbauer): Migrate this to null safety, https://github.com/flutter/flutter/issues/108933
// @dart = 2.7
// This file is used to generate the switch statements in the Locale class.
// See: ../lib/ui/window.dart
@@ -30,7 +33,7 @@ Map<String, List<String>> parseSection(String section) {
}
final int colon = line.indexOf(':');
if (colon <= 0) {
throw 'not sure how to deal with "$line"';
throw StateError('not sure how to deal with "$line"');
}
final String name = line.substring(0, colon);
final String value = line.substring(colon + 2);

View File

@@ -1,10 +1,13 @@
name: web_sdk_tests
author: Flutter Authors <flutter-dev@googlegroups.com>
# Keep the SDK version range in sync with lib/web_ui/pubspec.yaml
environment:
sdk: ">=2.12.0-0 <3.0.0"
dependencies:
args: 2.3.1
path: 1.8.2
dev_dependencies:
analyzer: 4.3.1
test: 1.21.4

View File

@@ -10,8 +10,8 @@ import 'package:path/path.dart' as path;
final ArgParser argParser = ArgParser()
..addOption('output-dir')
..addOption('input-dir')
..addFlag('ui', defaultsTo: false)
..addFlag('engine', defaultsTo: false)
..addFlag('ui')
..addFlag('engine')
..addMultiOption('input')
..addOption('stamp');
@@ -170,7 +170,7 @@ String _preprocessEnginePartFile(String source) {
// Do nothing.
} else {
// Insert the part directive at the beginning of the file.
source = 'part of engine;\n' + source;
source = 'part of engine;\n$source';
}
return source;
}

View File

@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: avoid_print
import 'dart:io';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:pub_semver/pub_semver.dart';
// Ignore members defined on Object.
const Set<String> _kObjectMembers = <String>{
@@ -187,8 +188,8 @@ void main() {
// check nullability
if (uiParam is SimpleFormalParameter &&
webParam is SimpleFormalParameter) {
bool isUiNullable = uiParam.type?.question != null;
bool isWebNullable = webParam.type?.question != null;
final bool isUiNullable = uiParam.type?.question != null;
final bool isWebNullable = webParam.type?.question != null;
if (isUiNullable != isWebNullable) {
failed = true;
print('Warning: lib/ui/ui.dart $className.$methodName parameter $i '
@@ -263,8 +264,8 @@ void main() {
'${uiParam.identifier!.name} is named, but not in lib/web_ui/ui.dart.');
}
bool isUiNullable = uiParam.type?.question != null;
bool isWebNullable = webParam.type?.question != null;
final bool isUiNullable = uiParam.type?.question != null;
final bool isWebNullable = webParam.type?.question != null;
if (isUiNullable != isWebNullable) {
failed = true;
print('Warning: lib/ui/ui.dart $typeDefName parameter $i '

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: avoid_print
/// Checks that JavaScript API is accessed properly.
///
/// JavaScript access needs to be audited to make sure it follows security best

View File

@@ -78,7 +78,7 @@ export 'engine/file3.dart';
'$caught',
'Exception: on line 3: unexpected code in /path/to/lib/web_ui/lib/src/engine.dart. '
'This file may only contain comments and exports. Found:\n'
'import \'dart:something\';',
"import 'dart:something';",
);
});

View File

@@ -7,7 +7,7 @@ import 'dart:convert';
import 'package:test/test.dart';
// ignore: implementation_imports
import 'package:ui/src/engine.dart' show operatingSystem, OperatingSystem, useCanvasKit;
import 'package:ui/src/engine.dart' show OperatingSystem, operatingSystem, useCanvasKit;
// ignore: implementation_imports
import 'package:ui/src/engine/dom.dart';
import 'package:ui/ui.dart';

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: avoid_dynamic_calls
@JS()
library test.host;
@@ -22,7 +24,7 @@ class _TestRunner {
/// Returns the current content shell runner, or `null` if none exists.
@JS()
external _TestRunner? get testRunner;
external _TestRunner? get testRunner; // ignore: library_private_types_in_public_api
/// A class that exposes the test API to JS.
///
@@ -31,6 +33,8 @@ external _TestRunner? get testRunner;
@JS()
@anonymous
class _JSApi {
external factory _JSApi({void Function() resume, void Function() restartCurrent});
/// Causes the test runner to resume running, as though the user had clicked
/// the "play" button.
external Function get resume;
@@ -38,8 +42,6 @@ class _JSApi {
/// Causes the test runner to restart the current test once it finishes
/// running.
external Function get restartCurrent;
external factory _JSApi({void Function() resume, void Function() restartCurrent});
}
/// Sets the top-level `dartTest` object so that it's visible to JS.
@@ -160,7 +162,7 @@ void main() {
}));
},
(dynamic error, StackTrace stackTrace) {
print('$error\n${Trace.from(stackTrace).terse}');
print('$error\n${Trace.from(stackTrace).terse}'); // ignore: avoid_print
},
);
}

View File

@@ -9,5 +9,6 @@ dependencies:
stream_channel: 2.1.0
test: 1.17.7
webkit_inspection_protocol: 1.0.0
stack_trace: 1.10.0
ui:
path: ../../lib/web_ui

View File

@@ -36,6 +36,16 @@ class Environment {
return _prepareEnvironmentFromEngineDir(script, directory);
}
Environment._({
required this.self,
required this.webUiRootDir,
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});
static Environment _prepareEnvironmentFromEngineDir(
io.File self, io.Directory engineSrcDir) {
final io.Directory engineToolsDir =
@@ -72,16 +82,6 @@ class Environment {
);
}
Environment._({
required this.self,
required this.webUiRootDir,
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});
/// The Dart script that's currently running.
final io.File self;

View File

@@ -26,12 +26,22 @@ void main(List<String> args) {
final Image imageB = decodeNamedImage(fileB.readAsBytesSync(), 'b.png')!;
final ImageDiff diff = ImageDiff(
golden: imageA, other: imageB, pixelComparison: PixelComparison.fuzzy);
print('Diff: ${(diff.rate * 100).toStringAsFixed(4)}%');
print('Diff: ${(diff.rate * 100).toStringAsFixed(4)}%'); // ignore: avoid_print
}
/// This class encapsulates visually diffing an Image with any other.
/// Both images need to be the exact same size.
class ImageDiff {
/// Image diff constructor which requires two [Image]s to compare and
/// [PixelComparison] algorithm.
ImageDiff({
required this.golden,
required this.other,
required this.pixelComparison,
}) {
_computeDiff();
}
/// The image to match
final Image golden;
@@ -53,16 +63,6 @@ class ImageDiff {
/// This gets set to 1 (100% difference) when golden and other aren't the same size.
double get rate => _wrongPixels / _pixelCount;
/// Image diff constructor which requires two [Image]s to compare and
/// [PixelComparison] algorithm.
ImageDiff({
required this.golden,
required this.other,
required this.pixelComparison,
}) {
_computeDiff();
}
int _pixelCount = 0;
int _wrongPixels = 0;
@@ -136,8 +136,6 @@ class ImageDiff {
getGreen(pixel),
getBlue(pixel),
];
default:
throw 'Unrecognized pixel comparison value: $pixelComparison';
}
}

View File

@@ -72,7 +72,7 @@ Future<String> compareImage(
// At the moment, we don't support local screenshot testing because we use
// Skia Gold to handle our screenshots and diffing. In the future, we might
// implement local screenshot testing if there's a need.
print('Screenshot generated: file://$screenshotPath');
print('Screenshot generated: file://$screenshotPath'); // ignore: avoid_print
return 'OK';
}
@@ -137,8 +137,8 @@ Golden file $filename did not match the image generated by the test.
if (diff.rate < maxDiffRateFailure) {
// Issue a warning but do not fail the test.
print('WARNING:');
print(message);
print('WARNING:'); // ignore: avoid_print
print(message); // ignore: avoid_print
return 'OK';
} else {
// Fail test
@@ -150,7 +150,7 @@ Golden file $filename did not match the image generated by the test.
Future<Image?> _getGolden(String filename) {
// TODO(mdebbar): Fetch the golden from Skia Gold.
return Future<Image?>.value(null);
return Future<Image?>.value();
}
String _getFullScreenshotPath(String filename) {