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

Commit 3a093e4

Browse files
[various] Enable avoid_print (#6842)
* [various] Enable avoid_print Enables the `avoid_print` lint, and fixes violations (mostly by opting example files out of it). * Version bumps * Add tooling analysis option file that was accidentally omitted * Fix typo in analysis_options found by adding tool sub-options * Revert most version bumps * Fix ios_platform_images
1 parent b2cdcb6 commit 3a093e4

File tree

60 files changed

+94
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+94
-93
lines changed

analysis_options.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ linter:
8181
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
8282
- avoid_null_checks_in_equality_operators
8383
# - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
84-
# - avoid_print # LOCAL CHANGE - Needs to be enabled and violations fixed.
84+
- avoid_print
8585
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
8686
- avoid_redundant_argument_values
8787
- avoid_relative_lib_imports
@@ -204,7 +204,7 @@ linter:
204204
- recursive_getters
205205
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
206206
- secure_pubspec_urls
207-
- sized_box_for_whitespace
207+
- sized_box_for_whitespace
208208
# - sized_box_shrink_expand # not yet tested
209209
- slash_for_doc_comments
210210
- sort_child_properties_last

packages/camera/camera/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.0+5
2+
3+
* Updates code for stricter lint checks.
4+
15
## 0.10.0+4
26

37
* Removes usage of `_ambiguate` method in example.

packages/camera/camera/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ class _CameraAppState extends State<CameraApp> {
141141
if (e is CameraException) {
142142
switch (e.code) {
143143
case 'CameraAccessDenied':
144-
print('User denied camera access.');
144+
// Handle access errors here.
145145
break;
146146
default:
147-
print('Handle other errors.');
147+
// Handle other errors here.
148148
break;
149149
}
150150
}

packages/camera/camera/example/integration_test/camera_test.dart

-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ void main() {
5555
Future<bool> testCaptureImageResolution(
5656
CameraController controller, ResolutionPreset preset) async {
5757
final Size expectedSize = presetExpectedSizes[preset]!;
58-
print(
59-
'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');
6058

6159
// Take Picture
6260
final XFile file = await controller.takePicture();
@@ -104,8 +102,6 @@ void main() {
104102
Future<bool> testCaptureVideoResolution(
105103
CameraController controller, ResolutionPreset preset) async {
106104
final Size expectedSize = presetExpectedSizes[preset]!;
107-
print(
108-
'Capturing video at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');
109105

110106
// Take Video
111107
await controller.startVideoRecording();

packages/camera/camera/example/lib/main.dart

+2-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
3737
}
3838

3939
void _logError(String code, String? message) {
40-
if (message != null) {
41-
print('Error: $code\nError Message: $message');
42-
} else {
43-
print('Error: $code');
44-
}
40+
// ignore: avoid_print
41+
print('Error: $code${message == null ? '' : '\nError Message: $message'}');
4542
}
4643

4744
class _CameraExampleHomeState extends State<CameraExampleHome>

packages/camera/camera/example/lib/readme_full_example.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ class _CameraAppState extends State<CameraApp> {
4040
if (e is CameraException) {
4141
switch (e.code) {
4242
case 'CameraAccessDenied':
43-
print('User denied camera access.');
43+
// Handle access errors here.
4444
break;
4545
default:
46-
print('Handle other errors.');
46+
// Handle other errors here.
4747
break;
4848
}
4949
}

packages/camera/camera/example/test_driver/integration_test.dart

+2
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
import 'dart:async';
68
import 'dart:convert';
79
import 'dart:io';

packages/camera/camera/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
44
Dart.
55
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
7-
version: 0.10.0+4
7+
version: 0.10.0+5
88

99
environment:
1010
sdk: ">=2.14.0 <3.0.0"

packages/camera/camera_android/example/integration_test/camera_test.dart

-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ void main() {
5555
Future<bool> testCaptureImageResolution(
5656
CameraController controller, ResolutionPreset preset) async {
5757
final Size expectedSize = presetExpectedSizes[preset]!;
58-
print(
59-
'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');
6058

6159
// Take Picture
6260
final XFile file = await controller.takePicture();
@@ -105,8 +103,6 @@ void main() {
105103
Future<bool> testCaptureVideoResolution(
106104
CameraController controller, ResolutionPreset preset) async {
107105
final Size expectedSize = presetExpectedSizes[preset]!;
108-
print(
109-
'Capturing video at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');
110106

111107
// Take Video
112108
await controller.startVideoRecording();

packages/camera/camera_android/example/lib/main.dart

+2-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
4141
}
4242

4343
void _logError(String code, String? message) {
44-
if (message != null) {
45-
print('Error: $code\nError Message: $message');
46-
} else {
47-
print('Error: $code');
48-
}
44+
// ignore: avoid_print
45+
print('Error: $code${message == null ? '' : '\nError Message: $message'}');
4946
}
5047

5148
class _CameraExampleHomeState extends State<CameraExampleHome>

packages/camera/camera_android/example/test_driver/integration_test.dart

+2
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
import 'dart:async';
68
import 'dart:convert';
79
import 'dart:io';

packages/camera/camera_avfoundation/example/integration_test/camera_test.dart

-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ void main() {
5656
Future<bool> testCaptureImageResolution(
5757
CameraController controller, ResolutionPreset preset) async {
5858
final Size expectedSize = presetExpectedSizes[preset]!;
59-
print(
60-
'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');
6159

6260
// Take Picture
6361
final XFile file = await controller.takePicture();
@@ -102,8 +100,6 @@ void main() {
102100
Future<bool> testCaptureVideoResolution(
103101
CameraController controller, ResolutionPreset preset) async {
104102
final Size expectedSize = presetExpectedSizes[preset]!;
105-
print(
106-
'Capturing video at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');
107103

108104
// Take Video
109105
await controller.startVideoRecording();

packages/camera/camera_avfoundation/example/lib/main.dart

+2-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
4141
}
4242

4343
void _logError(String code, String? message) {
44-
if (message != null) {
45-
print('Error: $code\nError Message: $message');
46-
} else {
47-
print('Error: $code');
48-
}
44+
// ignore: avoid_print
45+
print('Error: $code${message == null ? '' : '\nError Message: $message'}');
4946
}
5047

5148
class _CameraExampleHomeState extends State<CameraExampleHome>

packages/camera/camera_web/test/more_tests_exist_elsewhere_test.dart

+2
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
import 'package:flutter_test/flutter_test.dart';
68

79
void main() {

packages/file_selector/file_selector/example/lib/save_text_page.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SaveTextPage extends StatelessWidget {
5656
child: Column(
5757
mainAxisAlignment: MainAxisAlignment.center,
5858
children: <Widget>[
59-
Container(
59+
SizedBox(
6060
width: 300,
6161
child: TextField(
6262
minLines: 1,
@@ -67,7 +67,7 @@ class SaveTextPage extends StatelessWidget {
6767
),
6868
),
6969
),
70-
Container(
70+
SizedBox(
7171
width: 300,
7272
child: TextField(
7373
minLines: 1,

packages/file_selector/file_selector_linux/example/lib/save_text_page.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SaveTextPage extends StatelessWidget {
4242
child: Column(
4343
mainAxisAlignment: MainAxisAlignment.center,
4444
children: <Widget>[
45-
Container(
45+
SizedBox(
4646
width: 300,
4747
child: TextField(
4848
minLines: 1,
@@ -53,7 +53,7 @@ class SaveTextPage extends StatelessWidget {
5353
),
5454
),
5555
),
56-
Container(
56+
SizedBox(
5757
width: 300,
5858
child: TextField(
5959
minLines: 1,

packages/file_selector/file_selector_macos/example/lib/save_text_page.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SaveTextPage extends StatelessWidget {
4242
child: Column(
4343
mainAxisAlignment: MainAxisAlignment.center,
4444
children: <Widget>[
45-
Container(
45+
SizedBox(
4646
width: 300,
4747
child: TextField(
4848
minLines: 1,
@@ -53,7 +53,7 @@ class SaveTextPage extends StatelessWidget {
5353
),
5454
),
5555
),
56-
Container(
56+
SizedBox(
5757
width: 300,
5858
child: TextField(
5959
minLines: 1,

packages/file_selector/file_selector_web/test/more_tests_exist_elsewhere_test.dart

+2
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
import 'package:flutter_test/flutter_test.dart';
68

79
void main() {

packages/file_selector/file_selector_windows/example/lib/save_text_page.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SaveTextPage extends StatelessWidget {
4242
child: Column(
4343
mainAxisAlignment: MainAxisAlignment.center,
4444
children: <Widget>[
45-
Container(
45+
SizedBox(
4646
width: 300,
4747
child: TextField(
4848
minLines: 1,
@@ -53,7 +53,7 @@ class SaveTextPage extends StatelessWidget {
5353
),
5454
),
5555
),
56-
Container(
56+
SizedBox(
5757
width: 300,
5858
child: TextField(
5959
minLines: 1,

packages/google_maps_flutter/google_maps_flutter/example/lib/map_coordinates.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> {
7272
// Add a block at the bottom of this list to allow validation that the visible region of the map
7373
// does not change when scrolled under the safe view on iOS.
7474
// https://github.com/flutter/flutter/issues/107913
75-
Container(
75+
const SizedBox(
7676
width: 300,
7777
height: 1000,
7878
),

packages/google_maps_flutter/google_maps_flutter/test/circle_updates_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ void main() {
180180
testWidgets('Update non platform related attr', (WidgetTester tester) async {
181181
Circle c1 = const Circle(circleId: CircleId('circle_1'));
182182
final Set<Circle> prev = <Circle>{c1};
183-
c1 = Circle(
184-
circleId: const CircleId('circle_1'), onTap: () => print('hello'));
183+
c1 = Circle(circleId: const CircleId('circle_1'), onTap: () {});
185184
final Set<Circle> cur = <Circle>{c1};
186185

187186
await tester.pumpWidget(_mapWithCircles(prev));

packages/google_maps_flutter/google_maps_flutter/test/marker_updates_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ void main() {
185185
final Set<Marker> prev = <Marker>{m1};
186186
m1 = Marker(
187187
markerId: const MarkerId('marker_1'),
188-
onTap: () => print('hello'),
189-
onDragEnd: (LatLng latLng) => print(latLng));
188+
onTap: () {},
189+
onDragEnd: (LatLng latLng) {});
190190
final Set<Marker> cur = <Marker>{m1};
191191

192192
await tester.pumpWidget(_mapWithMarkers(prev));

packages/google_maps_flutter/google_maps_flutter/test/polygon_updates_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ void main() {
208208
testWidgets('Update non platform related attr', (WidgetTester tester) async {
209209
Polygon p1 = const Polygon(polygonId: PolygonId('polygon_1'));
210210
final Set<Polygon> prev = <Polygon>{p1};
211-
p1 = Polygon(
212-
polygonId: const PolygonId('polygon_1'), onTap: () => print(2 + 2));
211+
p1 = Polygon(polygonId: const PolygonId('polygon_1'), onTap: () {});
213212
final Set<Polygon> cur = <Polygon>{p1};
214213

215214
await tester.pumpWidget(_mapWithPolygons(prev));

packages/google_maps_flutter/google_maps_flutter/test/polyline_updates_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ void main() {
202202
testWidgets('Update non platform related attr', (WidgetTester tester) async {
203203
Polyline p1 = const Polyline(polylineId: PolylineId('polyline_1'));
204204
final Set<Polyline> prev = <Polyline>{p1};
205-
p1 = Polyline(
206-
polylineId: const PolylineId('polyline_1'), onTap: () => print(2 + 2));
205+
p1 = Polyline(polylineId: const PolylineId('polyline_1'), onTap: () {});
207206
final Set<Polyline> cur = <Polyline>{p1};
208207

209208
await tester.pumpWidget(_mapWithPolylines(prev));

packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_coordinates.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> {
7474
// Add a block at the bottom of this list to allow validation that the visible region of the map
7575
// does not change when scrolled under the safe view on iOS.
7676
// https://github.com/flutter/flutter/issues/107913
77-
Container(
77+
const SizedBox(
7878
width: 300,
7979
height: 1000,
8080
),

packages/google_maps_flutter/google_maps_flutter_ios/example/lib/map_coordinates.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> {
7474
// Add a block at the bottom of this list to allow validation that the visible region of the map
7575
// does not change when scrolled under the safe view on iOS.
7676
// https://github.com/flutter/flutter/issues/107913
77-
Container(
77+
const SizedBox(
7878
width: 300,
7979
height: 1000,
8080
),

packages/google_maps_flutter/google_maps_flutter_web/test/tests_exist_elsewhere_test.dart

+2
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
import 'package:flutter_test/flutter_test.dart';
68

79
void main() {

packages/google_sign_in/google_sign_in/example/lib/main.dart

+1-1
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: public_member_api_docs
5+
// ignore_for_file: public_member_api_docs, avoid_print
66

77
import 'dart:async';
88
import 'dart:convert' show json;

packages/google_sign_in/google_sign_in_android/example/lib/main.dart

+1-1
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: public_member_api_docs
5+
// ignore_for_file: public_member_api_docs, avoid_print
66

77
import 'dart:async';
88
import 'dart:convert' show json;

packages/google_sign_in/google_sign_in_ios/example/lib/main.dart

+1-1
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: public_member_api_docs
5+
// ignore_for_file: public_member_api_docs, avoid_print
66

77
import 'dart:async';
88
import 'dart:convert' show json;

packages/google_sign_in/google_sign_in_web/test/tests_exist_elsewhere_test.dart

+2
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
import 'package:flutter_test/flutter_test.dart';
68

79
void main() {

packages/image_picker/image_picker_for_web/test/tests_exist_elsewhere_test.dart

+2
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
import 'package:flutter_test/flutter_test.dart';
68

79
void main() {

packages/in_app_purchase/in_app_purchase_android/example/lib/main.dart

+2
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
import 'dart:async';
68

79
import 'package:flutter/material.dart';

0 commit comments

Comments
 (0)