diff --git a/ci/analyze.sh b/ci/analyze.sh index 62886f53165c7..fbfa6b7805d94 100755 --- a/ci/analyze.sh +++ b/ci/analyze.sh @@ -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 diff --git a/tools/analysis_options.yaml b/tools/analysis_options.yaml new file mode 100644 index 0000000000000..7f47e0448b47f --- /dev/null +++ b/tools/analysis_options.yaml @@ -0,0 +1,5 @@ +include: ../analysis_options.yaml + +linter: + rules: + avoid_print: false diff --git a/tools/api_check/lib/apicheck.dart b/tools/api_check/lib/apicheck.dart index 1ba28a086c001..8413cc6f37e95 100644 --- a/tools/api_check/lib/apicheck.dart +++ b/tools/api_check/lib/apicheck.dart @@ -36,11 +36,11 @@ List getDartClassFields({ final RegExp fieldExp = RegExp(r'_k(\w*)Index'); final List fields = []; 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)!); diff --git a/tools/api_check/pubspec.yaml b/tools/api_check/pubspec.yaml index 8ac0e26b0dafc..60a1493a0247a 100644 --- a/tools/api_check/pubspec.yaml +++ b/tools/api_check/pubspec.yaml @@ -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: diff --git a/tools/const_finder/test/const_finder_test.dart b/tools/const_finder/test/const_finder_test.dart index 4289c584fb312..9eac1900b7e97 100644 --- a/tools/const_finder/test/const_finder_test.dart +++ b/tools/const_finder/test/const_finder_test.dart @@ -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 main(List 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 main(List args) async { stdout.writeln('Generating kernel fixtures...'); stdout.writeln(consts); - _checkProcessResult(Process.runSync(dart, [ + checkProcessResult(Process.runSync(dart, [ frontendServer, '--sdk-root=$sdkRoot', '--target=flutter', @@ -197,7 +199,7 @@ Future main(List args) async { box, ])); - _checkProcessResult(Process.runSync(dart, [ + checkProcessResult(Process.runSync(dart, [ frontendServer, '--sdk-root=$sdkRoot', '--target=flutter', @@ -208,7 +210,7 @@ Future main(List args) async { consts, ])); - _checkProcessResult(Process.runSync(dart, [ + checkProcessResult(Process.runSync(dart, [ frontendServer, '--sdk-root=$sdkRoot', '--target=flutter', diff --git a/tools/const_finder/test/fixtures/lib/box.dart b/tools/const_finder/test/fixtures/lib/box.dart index f84961d10883b..ea31a1ed3be4e 100644 --- a/tools/const_finder/test/fixtures/lib/box.dart +++ b/tools/const_finder/test/fixtures/lib/box.dart @@ -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() { diff --git a/tools/const_finder/test/fixtures/lib/consts.dart b/tools/const_finder/test/fixtures/lib/consts.dart index ba66e7a946fb0..a13a5772a4521 100644 --- a/tools/const_finder/test/fixtures/lib/consts.dart +++ b/tools/const_finder/test/fixtures/lib/consts.dart @@ -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'; diff --git a/tools/const_finder/test/fixtures/lib/consts_and_non.dart b/tools/const_finder/test/fixtures/lib/consts_and_non.dart index 6b85ac2687cd3..fa91c318bcb7b 100644 --- a/tools/const_finder/test/fixtures/lib/consts_and_non.dart +++ b/tools/const_finder/test/fixtures/lib/consts_and_non.dart @@ -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'; diff --git a/tools/const_finder/test/fixtures/pkg/package.dart b/tools/const_finder/test/fixtures/pkg/package.dart index 87a92bb57221d..b5256d53e154b 100644 --- a/tools/const_finder/test/fixtures/pkg/package.dart +++ b/tools/const_finder/test/fixtures/pkg/package.dart @@ -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() { diff --git a/tools/gen_locale.dart b/tools/gen_locale.dart index 22c4c894a6636..2c4cedcea0d2a 100644 --- a/tools/gen_locale.dart +++ b/tools/gen_locale.dart @@ -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> 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); diff --git a/web_sdk/pubspec.yaml b/web_sdk/pubspec.yaml index cfc4aeca2f5d5..bd2d22bba6c72 100644 --- a/web_sdk/pubspec.yaml +++ b/web_sdk/pubspec.yaml @@ -1,10 +1,13 @@ name: web_sdk_tests -author: Flutter Authors # 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 diff --git a/web_sdk/sdk_rewriter.dart b/web_sdk/sdk_rewriter.dart index c71e0d5f8a054..bacc7683443e0 100644 --- a/web_sdk/sdk_rewriter.dart +++ b/web_sdk/sdk_rewriter.dart @@ -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; } diff --git a/web_sdk/test/api_conform_test.dart b/web_sdk/test/api_conform_test.dart index 1a659ca3790ec..755b6f9a3345c 100644 --- a/web_sdk/test/api_conform_test.dart +++ b/web_sdk/test/api_conform_test.dart @@ -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 _kObjectMembers = { @@ -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 ' diff --git a/web_sdk/test/js_access_test.dart b/web_sdk/test/js_access_test.dart index ee41a1e83d880..985ab28e3180d 100644 --- a/web_sdk/test/js_access_test.dart +++ b/web_sdk/test/js_access_test.dart @@ -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 diff --git a/web_sdk/test/sdk_rewriter_test.dart b/web_sdk/test/sdk_rewriter_test.dart index 36de7f6939798..4e17279f3353e 100644 --- a/web_sdk/test/sdk_rewriter_test.dart +++ b/web_sdk/test/sdk_rewriter_test.dart @@ -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';", ); }); diff --git a/web_sdk/web_engine_tester/lib/golden_tester.dart b/web_sdk/web_engine_tester/lib/golden_tester.dart index e5c2f04a9667a..732866637ec64 100644 --- a/web_sdk/web_engine_tester/lib/golden_tester.dart +++ b/web_sdk/web_engine_tester/lib/golden_tester.dart @@ -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'; diff --git a/web_sdk/web_engine_tester/lib/static/host.dart b/web_sdk/web_engine_tester/lib/static/host.dart index e98cc23128f35..320dba2134da1 100644 --- a/web_sdk/web_engine_tester/lib/static/host.dart +++ b/web_sdk/web_engine_tester/lib/static/host.dart @@ -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 }, ); } diff --git a/web_sdk/web_engine_tester/pubspec.yaml b/web_sdk/web_engine_tester/pubspec.yaml index 489401ff2913e..25219b1071327 100644 --- a/web_sdk/web_engine_tester/pubspec.yaml +++ b/web_sdk/web_engine_tester/pubspec.yaml @@ -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 diff --git a/web_sdk/web_test_utils/lib/environment.dart b/web_sdk/web_test_utils/lib/environment.dart index 81466b4bba828..30ea72edb9e1f 100644 --- a/web_sdk/web_test_utils/lib/environment.dart +++ b/web_sdk/web_test_utils/lib/environment.dart @@ -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; diff --git a/web_sdk/web_test_utils/lib/goldens.dart b/web_sdk/web_test_utils/lib/goldens.dart index 2f3f199614b52..e39e1f7fa4863 100644 --- a/web_sdk/web_test_utils/lib/goldens.dart +++ b/web_sdk/web_test_utils/lib/goldens.dart @@ -26,12 +26,22 @@ void main(List 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'; } } diff --git a/web_sdk/web_test_utils/lib/image_compare.dart b/web_sdk/web_test_utils/lib/image_compare.dart index 29de42db0757e..aeadee1863841 100644 --- a/web_sdk/web_test_utils/lib/image_compare.dart +++ b/web_sdk/web_test_utils/lib/image_compare.dart @@ -72,7 +72,7 @@ Future 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 _getGolden(String filename) { // TODO(mdebbar): Fetch the golden from Skia Gold. - return Future.value(null); + return Future.value(); } String _getFullScreenshotPath(String filename) {