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

Commit

Permalink
[various] Enable avoid_print (#6842)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
stuartmorgan committed Dec 14, 2022
1 parent b2cdcb6 commit 3a093e4
Show file tree
Hide file tree
Showing 60 changed files with 94 additions and 93 deletions.
4 changes: 2 additions & 2 deletions analysis_options.yaml
Expand Up @@ -81,7 +81,7 @@ linter:
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
- avoid_null_checks_in_equality_operators
# - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
# - avoid_print # LOCAL CHANGE - Needs to be enabled and violations fixed.
- avoid_print
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
- avoid_redundant_argument_values
- avoid_relative_lib_imports
Expand Down Expand Up @@ -204,7 +204,7 @@ linter:
- recursive_getters
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
- secure_pubspec_urls
- sized_box_for_whitespace
- sized_box_for_whitespace
# - sized_box_shrink_expand # not yet tested
- slash_for_doc_comments
- sort_child_properties_last
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.10.0+5

* Updates code for stricter lint checks.

## 0.10.0+4

* Removes usage of `_ambiguate` method in example.
Expand Down
4 changes: 2 additions & 2 deletions packages/camera/camera/README.md
Expand Up @@ -141,10 +141,10 @@ class _CameraAppState extends State<CameraApp> {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
// Handle access errors here.
break;
default:
print('Handle other errors.');
// Handle other errors here.
break;
}
}
Expand Down
Expand Up @@ -55,8 +55,6 @@ void main() {
Future<bool> testCaptureImageResolution(
CameraController controller, ResolutionPreset preset) async {
final Size expectedSize = presetExpectedSizes[preset]!;
print(
'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');

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

// Take Video
await controller.startVideoRecording();
Expand Down
7 changes: 2 additions & 5 deletions packages/camera/camera/example/lib/main.dart
Expand Up @@ -37,11 +37,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
}

void _logError(String code, String? message) {
if (message != null) {
print('Error: $code\nError Message: $message');
} else {
print('Error: $code');
}
// ignore: avoid_print
print('Error: $code${message == null ? '' : '\nError Message: $message'}');
}

class _CameraExampleHomeState extends State<CameraExampleHome>
Expand Down
4 changes: 2 additions & 2 deletions packages/camera/camera/example/lib/readme_full_example.dart
Expand Up @@ -40,10 +40,10 @@ class _CameraAppState extends State<CameraApp> {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
// Handle access errors here.
break;
default:
print('Handle other errors.');
// Handle other errors here.
break;
}
}
Expand Down
Expand Up @@ -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

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.0+4
version: 0.10.0+5

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
Expand Up @@ -55,8 +55,6 @@ void main() {
Future<bool> testCaptureImageResolution(
CameraController controller, ResolutionPreset preset) async {
final Size expectedSize = presetExpectedSizes[preset]!;
print(
'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');

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

// Take Video
await controller.startVideoRecording();
Expand Down
7 changes: 2 additions & 5 deletions packages/camera/camera_android/example/lib/main.dart
Expand Up @@ -41,11 +41,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
}

void _logError(String code, String? message) {
if (message != null) {
print('Error: $code\nError Message: $message');
} else {
print('Error: $code');
}
// ignore: avoid_print
print('Error: $code${message == null ? '' : '\nError Message: $message'}');
}

class _CameraExampleHomeState extends State<CameraExampleHome>
Expand Down
Expand Up @@ -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

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand Down
Expand Up @@ -56,8 +56,6 @@ void main() {
Future<bool> testCaptureImageResolution(
CameraController controller, ResolutionPreset preset) async {
final Size expectedSize = presetExpectedSizes[preset]!;
print(
'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}');

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

// Take Video
await controller.startVideoRecording();
Expand Down
7 changes: 2 additions & 5 deletions packages/camera/camera_avfoundation/example/lib/main.dart
Expand Up @@ -41,11 +41,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
}

void _logError(String code, String? message) {
if (message != null) {
print('Error: $code\nError Message: $message');
} else {
print('Error: $code');
}
// ignore: avoid_print
print('Error: $code${message == null ? '' : '\nError Message: $message'}');
}

class _CameraExampleHomeState extends State<CameraExampleHome>
Expand Down
Expand Up @@ -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

import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down
Expand Up @@ -56,7 +56,7 @@ class SaveTextPage extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand All @@ -67,7 +67,7 @@ class SaveTextPage extends StatelessWidget {
),
),
),
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand Down
Expand Up @@ -42,7 +42,7 @@ class SaveTextPage extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand All @@ -53,7 +53,7 @@ class SaveTextPage extends StatelessWidget {
),
),
),
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand Down
Expand Up @@ -42,7 +42,7 @@ class SaveTextPage extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand All @@ -53,7 +53,7 @@ class SaveTextPage extends StatelessWidget {
),
),
),
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand Down
Expand Up @@ -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

import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down
Expand Up @@ -42,7 +42,7 @@ class SaveTextPage extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand All @@ -53,7 +53,7 @@ class SaveTextPage extends StatelessWidget {
),
),
),
Container(
SizedBox(
width: 300,
child: TextField(
minLines: 1,
Expand Down
Expand Up @@ -72,7 +72,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> {
// Add a block at the bottom of this list to allow validation that the visible region of the map
// does not change when scrolled under the safe view on iOS.
// https://github.com/flutter/flutter/issues/107913
Container(
const SizedBox(
width: 300,
height: 1000,
),
Expand Down
Expand Up @@ -180,8 +180,7 @@ void main() {
testWidgets('Update non platform related attr', (WidgetTester tester) async {
Circle c1 = const Circle(circleId: CircleId('circle_1'));
final Set<Circle> prev = <Circle>{c1};
c1 = Circle(
circleId: const CircleId('circle_1'), onTap: () => print('hello'));
c1 = Circle(circleId: const CircleId('circle_1'), onTap: () {});
final Set<Circle> cur = <Circle>{c1};

await tester.pumpWidget(_mapWithCircles(prev));
Expand Down
Expand Up @@ -185,8 +185,8 @@ void main() {
final Set<Marker> prev = <Marker>{m1};
m1 = Marker(
markerId: const MarkerId('marker_1'),
onTap: () => print('hello'),
onDragEnd: (LatLng latLng) => print(latLng));
onTap: () {},
onDragEnd: (LatLng latLng) {});
final Set<Marker> cur = <Marker>{m1};

await tester.pumpWidget(_mapWithMarkers(prev));
Expand Down
Expand Up @@ -208,8 +208,7 @@ void main() {
testWidgets('Update non platform related attr', (WidgetTester tester) async {
Polygon p1 = const Polygon(polygonId: PolygonId('polygon_1'));
final Set<Polygon> prev = <Polygon>{p1};
p1 = Polygon(
polygonId: const PolygonId('polygon_1'), onTap: () => print(2 + 2));
p1 = Polygon(polygonId: const PolygonId('polygon_1'), onTap: () {});
final Set<Polygon> cur = <Polygon>{p1};

await tester.pumpWidget(_mapWithPolygons(prev));
Expand Down
Expand Up @@ -202,8 +202,7 @@ void main() {
testWidgets('Update non platform related attr', (WidgetTester tester) async {
Polyline p1 = const Polyline(polylineId: PolylineId('polyline_1'));
final Set<Polyline> prev = <Polyline>{p1};
p1 = Polyline(
polylineId: const PolylineId('polyline_1'), onTap: () => print(2 + 2));
p1 = Polyline(polylineId: const PolylineId('polyline_1'), onTap: () {});
final Set<Polyline> cur = <Polyline>{p1};

await tester.pumpWidget(_mapWithPolylines(prev));
Expand Down
Expand Up @@ -74,7 +74,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> {
// Add a block at the bottom of this list to allow validation that the visible region of the map
// does not change when scrolled under the safe view on iOS.
// https://github.com/flutter/flutter/issues/107913
Container(
const SizedBox(
width: 300,
height: 1000,
),
Expand Down
Expand Up @@ -74,7 +74,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> {
// Add a block at the bottom of this list to allow validation that the visible region of the map
// does not change when scrolled under the safe view on iOS.
// https://github.com/flutter/flutter/issues/107913
Container(
const SizedBox(
width: 300,
height: 1000,
),
Expand Down
Expand Up @@ -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

import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down
Expand Up @@ -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: public_member_api_docs
// ignore_for_file: public_member_api_docs, avoid_print

import 'dart:async';
import 'dart:convert' show json;
Expand Down
Expand Up @@ -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: public_member_api_docs
// ignore_for_file: public_member_api_docs, avoid_print

import 'dart:async';
import 'dart:convert' show json;
Expand Down
Expand Up @@ -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: public_member_api_docs
// ignore_for_file: public_member_api_docs, avoid_print

import 'dart:async';
import 'dart:convert' show json;
Expand Down
Expand Up @@ -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

import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down
Expand Up @@ -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

import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down
Expand Up @@ -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

import 'dart:async';

import 'package:flutter/material.dart';
Expand Down

0 comments on commit 3a093e4

Please sign in to comment.