Skip to content

Commit 6179ac6

Browse files
authored
fix up analysis for Dart in Engine (flutter#7404)
* fix up analysis for Dart in Engine, particularly for tests
1 parent bec12d8 commit 6179ac6

24 files changed

+208
-189
lines changed

analysis_options.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
# private fields, especially on the Window object):
1111

1212
analyzer:
13-
language:
14-
enableStrictCallChecks: true
15-
enableSuperMixins: true
1613
strong-mode:
1714
implicit-dynamic: false
1815
errors:
1916
# treat missing required parameters as a warning (not a hint)
2017
missing_required_param: warning
2118
# treat missing returns as a warning (not a hint)
2219
missing_return: warning
20+
native_function_body_in_non_sdk_code: ignore
2321
# allow having TODOs in the code
2422
todo: ignore
2523
# `flutter analyze` (without `--watch`) just ignores directories
@@ -94,7 +92,6 @@ linter:
9492
# - parameter_assignments # we do this commonly
9593
- prefer_adjacent_string_concatenation
9694
- prefer_asserts_in_initializer_lists
97-
- prefer_bool_in_asserts
9895
- prefer_collection_literals
9996
- prefer_conditional_assignment
10097
- prefer_const_constructors

ci/analyze.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ RESULTS=`dartanalyzer \
44
--options flutter/analysis_options.yaml \
55
out/host_debug_unopt/gen/sky/bindings/dart_ui/ui.dart \
66
2>&1 \
7-
| grep -v "Native functions can only be declared in the SDK and code that is loaded through native extensions" \
8-
| grep -Ev "The function '.+' (is not|isn't) used" \
9-
| grep -Ev "The top level variable '.+' isn't used" \
10-
| grep -Ev "Undefined name 'main'" \
11-
| grep -v "The library 'dart:_internal' is internal" \
12-
| grep -Ev "Unused import.+ui\.dart" \
13-
| grep -Ev "[0-9]+ errors.*found\." \
7+
| grep -Ev "No issues found!" \
148
| grep -Ev "Analyzing.+out/host_debug_unopt/gen/sky/bindings/dart_ui/ui\.dart"`
159

1610
echo "$RESULTS"

lib/ui/hooks.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
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(dnfield): Remove unused_import ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.
6+
57
part of dart.ui;
68

9+
// ignore: unused_element
710
String _decodeUTF8(ByteData message) {
811
return message != null ? utf8.decoder.convert(message.buffer.asUint8List()) : null;
912
}
1013

14+
// ignore: unused_element
1115
dynamic _decodeJSON(String message) {
1216
return message != null ? json.decode(message) : null;
1317
}
1418

1519
@pragma('vm:entry-point')
20+
// ignore: unused_element
1621
void _updateWindowMetrics(double devicePixelRatio,
1722
double width,
1823
double height,
@@ -50,9 +55,11 @@ String _localeClosure() {
5055
}
5156

5257
@pragma('vm:entry-point')
58+
// ignore: unused_element
5359
_LocaleClosure _getLocaleClosure() => _localeClosure;
5460

5561
@pragma('vm:entry-point')
62+
// ignore: unused_element
5663
void _updateLocales(List<String> locales) {
5764
const int stringsPerLocale = 4;
5865
final int numLocales = locales.length ~/ stringsPerLocale;
@@ -71,6 +78,7 @@ void _updateLocales(List<String> locales) {
7178
}
7279

7380
@pragma('vm:entry-point')
81+
// ignore: unused_element
7482
void _updateUserSettingsData(String jsonData) {
7583
final Map<String, dynamic> data = json.decode(jsonData);
7684
if (data.isEmpty) {
@@ -90,12 +98,14 @@ void _updateAlwaysUse24HourFormat(bool alwaysUse24HourFormat) {
9098
}
9199

92100
@pragma('vm:entry-point')
101+
// ignore: unused_element
93102
void _updateSemanticsEnabled(bool enabled) {
94103
window._semanticsEnabled = enabled;
95104
_invoke(window.onSemanticsEnabledChanged, window._onSemanticsEnabledChangedZone);
96105
}
97106

98107
@pragma('vm:entry-point')
108+
// ignore: unused_element
99109
void _updateAccessibilityFeatures(int values) {
100110
final AccessibilityFeatures newFeatures = new AccessibilityFeatures._(values);
101111
if (newFeatures == window._accessibilityFeatures)
@@ -122,12 +132,14 @@ void _dispatchPlatformMessage(String name, ByteData data, int responseId) {
122132
}
123133

124134
@pragma('vm:entry-point')
135+
// ignore: unused_element
125136
void _dispatchPointerDataPacket(ByteData packet) {
126137
if (window.onPointerDataPacket != null)
127138
_invoke1<PointerDataPacket>(window.onPointerDataPacket, window._onPointerDataPacketZone, _unpackPointerDataPacket(packet));
128139
}
129140

130141
@pragma('vm:entry-point')
142+
// ignore: unused_element
131143
void _dispatchSemanticsAction(int id, int action, ByteData args) {
132144
_invoke3<int, SemanticsAction, ByteData>(
133145
window.onSemanticsAction,
@@ -139,11 +151,13 @@ void _dispatchSemanticsAction(int id, int action, ByteData args) {
139151
}
140152

141153
@pragma('vm:entry-point')
154+
// ignore: unused_element
142155
void _beginFrame(int microseconds) {
143156
_invoke1<Duration>(window.onBeginFrame, window._onBeginFrameZone, new Duration(microseconds: microseconds));
144157
}
145158

146159
@pragma('vm:entry-point')
160+
// ignore: unused_element
147161
void _drawFrame() {
148162
_invoke(window.onDrawFrame, window._onDrawFrameZone);
149163
}
@@ -177,6 +191,7 @@ void _invoke1<A>(void callback(A a), Zone zone, A arg) {
177191
}
178192

179193
/// Invokes [callback] inside the given [zone] passing it [arg1] and [arg2].
194+
// ignore: unused_element
180195
void _invoke2<A1, A2>(void callback(A1 a1, A2 a2), Zone zone, A1 arg1, A2 arg2) {
181196
if (callback == null)
182197
return;

lib/ui/natives.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+
// TODO(dnfield): remove unused_element ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.
6+
57
part of dart.ui;
68

79
// Corelib 'print' implementation.
@@ -28,7 +30,7 @@ Future<developer.ServiceExtensionResponse> _scheduleFrame(
2830
}
2931

3032
@pragma('vm:entry-point')
31-
void _setupHooks() {
33+
void _setupHooks() { // ignore: unused_element
3234
assert(() {
3335
// In debug mode, register the schedule frame extension.
3436
developer.registerExtension('ext.ui.window.scheduleFrame', _scheduleFrame);
@@ -67,9 +69,9 @@ int _getCallbackHandle(Function closure) native 'GetCallbackHandle';
6769
Function _getCallbackFromHandle(int handle) native 'GetCallbackFromHandle';
6870

6971
// Required for gen_snapshot to work correctly.
70-
int _isolateId;
72+
int _isolateId; // ignore: unused_element
7173

7274
@pragma('vm:entry-point')
73-
Function _getPrintClosure() => _print;
75+
Function _getPrintClosure() => _print; // ignore: unused_element
7476
@pragma('vm:entry-point')
75-
Function _getScheduleMicrotaskClosure() => _scheduleMicrotask;
77+
Function _getScheduleMicrotaskClosure() => _scheduleMicrotask; // ignore: unused_element

lib/ui/ui.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
/// text, layout, and rendering subsystems.
1212
library dart.ui;
1313

14-
import 'dart:_internal' hide Symbol;
14+
import 'dart:_internal' hide Symbol; // ignore: import_internal_library, unused_import
1515
import 'dart:async';
1616
import 'dart:collection' as collection;
1717
import 'dart:convert';
1818
import 'dart:developer' as developer;
19-
import 'dart:io';
19+
import 'dart:io'; // ignore: unused_import
2020
import 'dart:isolate' show SendPort;
2121
import 'dart:math' as math;
2222
import 'dart:nativewrappers';

runtime/fixtures/simple_main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// found in the LICENSE file.
44

55
void main() {
6-
print("Hello");
6+
print('Hello');
77
}

testing/dart/canvas_test.dart

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

5-
import 'dart:ui';
65
import 'dart:typed_data';
6+
import 'dart:ui';
77

88
import 'package:test/test.dart';
99

10-
typedef void CanvasCallback(Canvas canvas);
10+
typedef CanvasCallback = void Function(Canvas canvas);
1111

1212
void testCanvas(CanvasCallback callback) {
1313
try {
1414
callback(Canvas(PictureRecorder(), Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)));
15-
} catch (error) { }
15+
} catch (error) { } // ignore: empty_catches
1616
}
1717

1818
void main() {
19-
test("canvas APIs should not crash", () {
20-
Paint paint = Paint();
21-
Rect rect = Rect.fromLTRB(double.nan, double.nan, double.nan, double.nan);
22-
RRect rrect = RRect.fromRectAndCorners(rect);
23-
Offset offset = Offset(double.nan, double.nan);
24-
Path path = Path();
25-
Color color = Color(0);
26-
Paragraph paragraph = ParagraphBuilder(ParagraphStyle()).build();
19+
test('canvas APIs should not crash', () {
20+
final Paint paint = Paint();
21+
final Rect rect = Rect.fromLTRB(double.nan, double.nan, double.nan, double.nan);
22+
final RRect rrect = RRect.fromRectAndCorners(rect);
23+
const Offset offset = Offset(double.nan, double.nan);
24+
final Path path = Path();
25+
const Color color = Color(0);
26+
final Paragraph paragraph = ParagraphBuilder(ParagraphStyle()).build();
2727

28-
PictureRecorder recorder = PictureRecorder();
29-
Canvas recorderCanvas = Canvas(recorder);
30-
Picture picture = recorder.endRecording();
31-
Image image = picture.toImage(1, 1);
28+
final PictureRecorder recorder = PictureRecorder();
29+
final Canvas recorderCanvas = Canvas(recorder);
30+
recorderCanvas.scale(1.0, 1.0);
31+
final Picture picture = recorder.endRecording();
32+
final Image image = picture.toImage(1, 1);
3233

33-
try { Canvas(null, null); } catch (error) { }
34-
try { Canvas(null, rect); } catch (error) { }
35-
try { Canvas(PictureRecorder(), null); } catch (error) { }
36-
try { Canvas(PictureRecorder(), rect); } catch (error) { }
34+
try { Canvas(null, null); } catch (error) { } // ignore: empty_catches
35+
try { Canvas(null, rect); } catch (error) { } // ignore: empty_catches
36+
try { Canvas(PictureRecorder(), null); } catch (error) { } // ignore: empty_catches
37+
try { Canvas(PictureRecorder(), rect); } catch (error) { } // ignore: empty_catches
3738

3839
try {
3940
PictureRecorder()
4041
..endRecording()
4142
..endRecording()
4243
..endRecording();
43-
} catch (error) { }
44+
} catch (error) { } // ignore: empty_catches
4445

4546
testCanvas((Canvas canvas) => canvas.clipPath(path));
4647
testCanvas((Canvas canvas) => canvas.clipRect(rect));
4748
testCanvas((Canvas canvas) => canvas.clipRRect(rrect));
4849
testCanvas((Canvas canvas) => canvas.drawArc(rect, 0.0, 0.0, false, paint));
49-
testCanvas((Canvas canvas) => canvas.drawAtlas(image, [], [], [], BlendMode.src, rect, paint));
50+
testCanvas((Canvas canvas) => canvas.drawAtlas(image, <RSTransform>[], <Rect>[], <Color>[], BlendMode.src, rect, paint));
5051
testCanvas((Canvas canvas) => canvas.drawCircle(offset, double.nan, paint));
5152
testCanvas((Canvas canvas) => canvas.drawColor(color, BlendMode.src));
5253
testCanvas((Canvas canvas) => canvas.drawDRRect(rrect, rrect, paint));
@@ -59,15 +60,15 @@ void main() {
5960
testCanvas((Canvas canvas) => canvas.drawParagraph(paragraph, offset));
6061
testCanvas((Canvas canvas) => canvas.drawPath(path, paint));
6162
testCanvas((Canvas canvas) => canvas.drawPicture(picture));
62-
testCanvas((Canvas canvas) => canvas.drawPoints(PointMode.points, [], paint));
63+
testCanvas((Canvas canvas) => canvas.drawPoints(PointMode.points, <Offset>[], paint));
6364
testCanvas((Canvas canvas) => canvas.drawRawAtlas(image, Float32List(0), Float32List(0), Int32List(0), BlendMode.src, rect, paint));
6465
testCanvas((Canvas canvas) => canvas.drawRawPoints(PointMode.points, Float32List(0), paint));
6566
testCanvas((Canvas canvas) => canvas.drawRect(rect, paint));
6667
testCanvas((Canvas canvas) => canvas.drawRRect(rrect, paint));
6768
testCanvas((Canvas canvas) => canvas.drawShadow(path, color, double.nan, null));
6869
testCanvas((Canvas canvas) => canvas.drawShadow(path, color, double.nan, false));
6970
testCanvas((Canvas canvas) => canvas.drawShadow(path, color, double.nan, true));
70-
testCanvas((Canvas canvas) => canvas.drawVertices(Vertices(VertexMode.triangles, []), null, paint));
71+
testCanvas((Canvas canvas) => canvas.drawVertices(Vertices(VertexMode.triangles, <Offset>[]), null, paint));
7172
testCanvas((Canvas canvas) => canvas.getSaveCount());
7273
testCanvas((Canvas canvas) => canvas.restore());
7374
testCanvas((Canvas canvas) => canvas.rotate(double.nan));

0 commit comments

Comments
 (0)