Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1f9d87d

Browse files
authored
Analyze all dart code on CI (#35147)
1 parent eaeae8e commit 1f9d87d

21 files changed

+80
-71
lines changed

ci/analyze.sh

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,21 @@ echo ""
5454

5555
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/flutter_frontend_server"
5656

57-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/licenses"
57+
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools"
5858

59-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/litetest"
60-
61-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/benchmark"
62-
63-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/smoke_test_failure"
64-
65-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/dart"
66-
67-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/scenario_app"
68-
69-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/symbols"
70-
71-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/githooks"
72-
73-
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/clang_tidy"
59+
(cd "$FLUTTER_DIR/testing/skia_gold_client"; "$DART" pub get)
60+
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing"
7461

7562
echo ""
7663

7764
# Check that dart libraries conform.
7865
echo "Checking the integrity of the Web SDK"
7966
(cd "$FLUTTER_DIR/web_sdk"; "$DART" pub get)
67+
(cd "$FLUTTER_DIR/web_sdk/web_test_utils"; "$DART" pub get)
68+
(cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; "$DART" pub get)
69+
70+
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/web_sdk"
71+
8072
WEB_SDK_TEST_FILES="$FLUTTER_DIR/web_sdk/test/*"
8173
for testFile in $WEB_SDK_TEST_FILES
8274
do

tools/analysis_options.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include: ../analysis_options.yaml
2+
3+
linter:
4+
rules:
5+
avoid_print: false

tools/api_check/lib/apicheck.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ List<String> getDartClassFields({
3636
final RegExp fieldExp = RegExp(r'_k(\w*)Index');
3737
final List<String> fields = <String>[];
3838
for (final CompilationUnitMember unitMember in result.unit.declarations) {
39-
if (unitMember is ClassDeclaration && unitMember.name.name == className) {
39+
if (unitMember is ClassDeclaration && unitMember.name.name == className) { // ignore: deprecated_member_use
4040
for (final ClassMember classMember in unitMember.members) {
4141
if (classMember is FieldDeclaration) {
4242
for (final VariableDeclaration field in classMember.fields.variables) {
43-
final String fieldName = field.name.name;
43+
final String fieldName = field.name.name; // ignore: deprecated_member_use
4444
final RegExpMatch? match = fieldExp.firstMatch(fieldName);
4545
if (match != null) {
4646
fields.add(match.group(1)!);

tools/api_check/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ environment:
2828
dependencies:
2929
analyzer: any
3030
_fe_analyzer_shared: any
31+
pub_semver: any
3132

3233
dev_dependencies:
3334
async_helper: any
3435
expect: any
3536
litetest: any
3637
path: any
37-
pub_semver: any
3838
smith: any
3939

4040
dependency_overrides:

tools/const_finder/test/const_finder_test.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// ignore_for_file: avoid_dynamic_calls
6+
57
import 'dart:convert' show jsonEncode;
68
import 'dart:io';
79

@@ -175,7 +177,7 @@ Future<void> main(List<String> args) async {
175177
final String frontendServer = args[0];
176178
final String sdkRoot = args[1];
177179
try {
178-
void _checkProcessResult(ProcessResult result) {
180+
void checkProcessResult(ProcessResult result) {
179181
if (result.exitCode != 0) {
180182
stdout.writeln(result.stdout);
181183
stderr.writeln(result.stderr);
@@ -186,7 +188,7 @@ Future<void> main(List<String> args) async {
186188
stdout.writeln('Generating kernel fixtures...');
187189
stdout.writeln(consts);
188190

189-
_checkProcessResult(Process.runSync(dart, <String>[
191+
checkProcessResult(Process.runSync(dart, <String>[
190192
frontendServer,
191193
'--sdk-root=$sdkRoot',
192194
'--target=flutter',
@@ -197,7 +199,7 @@ Future<void> main(List<String> args) async {
197199
box,
198200
]));
199201

200-
_checkProcessResult(Process.runSync(dart, <String>[
202+
checkProcessResult(Process.runSync(dart, <String>[
201203
frontendServer,
202204
'--sdk-root=$sdkRoot',
203205
'--target=flutter',
@@ -208,7 +210,7 @@ Future<void> main(List<String> args) async {
208210
consts,
209211
]));
210212

211-
_checkProcessResult(Process.runSync(dart, <String>[
213+
checkProcessResult(Process.runSync(dart, <String>[
212214
frontendServer,
213215
'--sdk-root=$sdkRoot',
214216
'--target=flutter',

tools/const_finder/test/fixtures/lib/box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// https://github.com/dart-lang/sdk/blob/ca3ad264a64937d5d336cd04dbf2746d1b7d8fc4/tests/language_2/canonicalize/hashing_memoize_instance_test.dart
1010

1111
class Box {
12+
const Box(this.content1, this.content2);
1213
final Object content1;
1314
final Object content2;
14-
const Box(this.content1, this.content2);
1515
}
1616

1717
const Box box1_0 = Box(null, null);
@@ -217,7 +217,7 @@ const Box box2_98 = Box(box2_97, box2_97);
217217
const Box box2_99 = Box(box2_98, box2_98);
218218

219219
Object confuse(Box x) {
220-
try { throw x; } catch (e) { return e; }
220+
try { throw x; } catch (e) { return e; } // ignore: only_throw_errors
221221
}
222222

223223
void main() {

tools/const_finder/test/fixtures/lib/consts.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// ignore_for_file: prefer_const_constructors, unused_local_variable
5+
// ignore_for_file: prefer_const_constructors, unused_local_variable, depend_on_referenced_packages
66
import 'dart:core';
77

88
import 'package:const_finder_fixtures_package/package.dart';

tools/const_finder/test/fixtures/lib/consts_and_non.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// ignore_for_file: prefer_const_constructors, unused_local_variable
5+
// ignore_for_file: prefer_const_constructors, unused_local_variable, depend_on_referenced_packages
66
import 'dart:core';
77

88
import 'package:const_finder_fixtures_package/package.dart';

tools/const_finder/test/fixtures/pkg/package.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// ignore_for_file: prefer_const_constructors
5+
// ignore_for_file: prefer_const_constructors, depend_on_referenced_packages
66
import 'package:const_finder_fixtures/target.dart';
77

88
void createTargetInPackage() {

tools/gen_locale.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// TODO(goderbauer): Migrate this to null safety, https://github.com/flutter/flutter/issues/108933
6+
// @dart = 2.7
7+
58
// This file is used to generate the switch statements in the Locale class.
69
// See: ../lib/ui/window.dart
710

@@ -30,7 +33,7 @@ Map<String, List<String>> parseSection(String section) {
3033
}
3134
final int colon = line.indexOf(':');
3235
if (colon <= 0) {
33-
throw 'not sure how to deal with "$line"';
36+
throw StateError('not sure how to deal with "$line"');
3437
}
3538
final String name = line.substring(0, colon);
3639
final String value = line.substring(colon + 2);

web_sdk/pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: web_sdk_tests
2-
author: Flutter Authors <flutter-dev@googlegroups.com>
32

43
# Keep the SDK version range in sync with lib/web_ui/pubspec.yaml
54
environment:
65
sdk: ">=2.12.0-0 <3.0.0"
76

7+
dependencies:
8+
args: 2.3.1
9+
path: 1.8.2
10+
811
dev_dependencies:
912
analyzer: 4.3.1
1013
test: 1.21.4

web_sdk/sdk_rewriter.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import 'package:path/path.dart' as path;
1010
final ArgParser argParser = ArgParser()
1111
..addOption('output-dir')
1212
..addOption('input-dir')
13-
..addFlag('ui', defaultsTo: false)
14-
..addFlag('engine', defaultsTo: false)
13+
..addFlag('ui')
14+
..addFlag('engine')
1515
..addMultiOption('input')
1616
..addOption('stamp');
1717

@@ -170,7 +170,7 @@ String _preprocessEnginePartFile(String source) {
170170
// Do nothing.
171171
} else {
172172
// Insert the part directive at the beginning of the file.
173-
source = 'part of engine;\n' + source;
173+
source = 'part of engine;\n$source';
174174
}
175175
return source;
176176
}

web_sdk/test/api_conform_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// ignore_for_file: avoid_print
6+
57
import 'dart:io';
68

79
import 'package:analyzer/dart/analysis/features.dart';
810
import 'package:analyzer/dart/analysis/results.dart';
911
import 'package:analyzer/dart/analysis/utilities.dart';
1012
import 'package:analyzer/dart/ast/ast.dart';
11-
import 'package:pub_semver/pub_semver.dart';
1213

1314
// Ignore members defined on Object.
1415
const Set<String> _kObjectMembers = <String>{
@@ -187,8 +188,8 @@ void main() {
187188
// check nullability
188189
if (uiParam is SimpleFormalParameter &&
189190
webParam is SimpleFormalParameter) {
190-
bool isUiNullable = uiParam.type?.question != null;
191-
bool isWebNullable = webParam.type?.question != null;
191+
final bool isUiNullable = uiParam.type?.question != null;
192+
final bool isWebNullable = webParam.type?.question != null;
192193
if (isUiNullable != isWebNullable) {
193194
failed = true;
194195
print('Warning: lib/ui/ui.dart $className.$methodName parameter $i '
@@ -263,8 +264,8 @@ void main() {
263264
'${uiParam.identifier!.name} is named, but not in lib/web_ui/ui.dart.');
264265
}
265266

266-
bool isUiNullable = uiParam.type?.question != null;
267-
bool isWebNullable = webParam.type?.question != null;
267+
final bool isUiNullable = uiParam.type?.question != null;
268+
final bool isWebNullable = webParam.type?.question != null;
268269
if (isUiNullable != isWebNullable) {
269270
failed = true;
270271
print('Warning: lib/ui/ui.dart $typeDefName parameter $i '

web_sdk/test/js_access_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// ignore_for_file: avoid_print
6+
57
/// Checks that JavaScript API is accessed properly.
68
///
79
/// JavaScript access needs to be audited to make sure it follows security best

web_sdk/test/sdk_rewriter_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export 'engine/file3.dart';
7878
'$caught',
7979
'Exception: on line 3: unexpected code in /path/to/lib/web_ui/lib/src/engine.dart. '
8080
'This file may only contain comments and exports. Found:\n'
81-
'import \'dart:something\';',
81+
"import 'dart:something';",
8282
);
8383
});
8484

web_sdk/web_engine_tester/lib/golden_tester.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'dart:convert';
77

88
import 'package:test/test.dart';
99
// ignore: implementation_imports
10-
import 'package:ui/src/engine.dart' show operatingSystem, OperatingSystem, useCanvasKit;
10+
import 'package:ui/src/engine.dart' show OperatingSystem, operatingSystem, useCanvasKit;
1111
// ignore: implementation_imports
1212
import 'package:ui/src/engine/dom.dart';
1313
import 'package:ui/ui.dart';

web_sdk/web_engine_tester/lib/static/host.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// ignore_for_file: avoid_dynamic_calls
6+
57
@JS()
68
library test.host;
79

@@ -22,7 +24,7 @@ class _TestRunner {
2224

2325
/// Returns the current content shell runner, or `null` if none exists.
2426
@JS()
25-
external _TestRunner? get testRunner;
27+
external _TestRunner? get testRunner; // ignore: library_private_types_in_public_api
2628

2729
/// A class that exposes the test API to JS.
2830
///
@@ -31,15 +33,15 @@ external _TestRunner? get testRunner;
3133
@JS()
3234
@anonymous
3335
class _JSApi {
36+
external factory _JSApi({void Function() resume, void Function() restartCurrent});
37+
3438
/// Causes the test runner to resume running, as though the user had clicked
3539
/// the "play" button.
3640
external Function get resume;
3741

3842
/// Causes the test runner to restart the current test once it finishes
3943
/// running.
4044
external Function get restartCurrent;
41-
42-
external factory _JSApi({void Function() resume, void Function() restartCurrent});
4345
}
4446

4547
/// Sets the top-level `dartTest` object so that it's visible to JS.
@@ -160,7 +162,7 @@ void main() {
160162
}));
161163
},
162164
(dynamic error, StackTrace stackTrace) {
163-
print('$error\n${Trace.from(stackTrace).terse}');
165+
print('$error\n${Trace.from(stackTrace).terse}'); // ignore: avoid_print
164166
},
165167
);
166168
}

web_sdk/web_engine_tester/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ dependencies:
99
stream_channel: 2.1.0
1010
test: 1.17.7
1111
webkit_inspection_protocol: 1.0.0
12+
stack_trace: 1.10.0
1213
ui:
1314
path: ../../lib/web_ui

web_sdk/web_test_utils/lib/environment.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ class Environment {
3636
return _prepareEnvironmentFromEngineDir(script, directory);
3737
}
3838

39+
Environment._({
40+
required this.self,
41+
required this.webUiRootDir,
42+
required this.engineSrcDir,
43+
required this.engineToolsDir,
44+
required this.outDir,
45+
required this.hostDebugUnoptDir,
46+
required this.dartSdkDir,
47+
});
48+
3949
static Environment _prepareEnvironmentFromEngineDir(
4050
io.File self, io.Directory engineSrcDir) {
4151
final io.Directory engineToolsDir =
@@ -72,16 +82,6 @@ class Environment {
7282
);
7383
}
7484

75-
Environment._({
76-
required this.self,
77-
required this.webUiRootDir,
78-
required this.engineSrcDir,
79-
required this.engineToolsDir,
80-
required this.outDir,
81-
required this.hostDebugUnoptDir,
82-
required this.dartSdkDir,
83-
});
84-
8585
/// The Dart script that's currently running.
8686
final io.File self;
8787

0 commit comments

Comments
 (0)