[go: nahoru, domu]

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

Commit

Permalink
[various] More analysis_options alignment (#6949)
Browse files Browse the repository at this point in the history
* Change the way local changes are handled to match packages

* only_throw_errors

* Enable no_default_cases

* Fix violations in camera

* Fix violations in webview

* Fix url_launcher violation

* Fix violations in shared_preferences

* Fix violations in maps

* Version bumps

* Fix image_picker violations

* Fix video_player violations

* New version bumps

* Update excerpts

* Address review feedback
  • Loading branch information
stuartmorgan committed Jan 20, 2023
1 parent ffb36e0 commit 783ce6d
Show file tree
Hide file tree
Showing 89 changed files with 281 additions and 128 deletions.
13 changes: 4 additions & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ linter:
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
# - no_default_cases # LOCAL CHANGE - Needs to be enabled and violations fixed.
- no_default_cases
- no_duplicate_case_values
- no_leading_underscores_for_library_prefixes
- no_leading_underscores_for_local_identifiers
- no_logic_in_create_state
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
- no_runtimeType_toString # DIFFERENT FROM FLUTTER/FLUTTER
- non_constant_identifier_names
- noop_primitive_operations
- null_check_on_nullable_type_parameter
- null_closures
# - omit_local_variable_types # opposite of always_specify_types
# - one_member_abstracts # too many false positives
# - only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al # LOCAL CHANGE - Needs to be enabled and violations fixed.
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
- overridden_fields
- package_api_docs
- package_names
Expand Down Expand Up @@ -200,7 +200,7 @@ linter:
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- provide_deprecation_message
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
- public_member_api_docs # DIFFERENT FROM FLUTTER/FLUTTER
- recursive_getters
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
- secure_pubspec_urls
Expand Down Expand Up @@ -261,8 +261,3 @@ linter:
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
- valid_regexps
- void_checks
### Local flutter/plugins additions ###
# These are from flutter/flutter/packages, so will need to be preserved
# separately when moving to a shared file.
- no_runtimeType_toString # use objectRuntimeType from package:foundation
- public_member_api_docs # see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-dartdocs-javadocs-etc
6 changes: 5 additions & 1 deletion packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.2+1

* Updates code for stricter lint checks.

## 0.10.2

* Implements option to also stream when recording a video.
Expand Down Expand Up @@ -31,7 +35,7 @@
## 0.10.0

* **Breaking Change** Bumps default camera_web package version, which updates permission exception code from `cameraPermission` to `CameraAccessDenied`.
* **Breaking Change** Bumps default camera_android package version, which updates permission exception code from `cameraPermission` to
* **Breaking Change** Bumps default camera_android package version, which updates permission exception code from `cameraPermission` to
`CameraAccessDenied` and `AudioAccessDenied`.
* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316).

Expand Down
6 changes: 4 additions & 2 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
return Icons.camera_front;
case CameraLensDirection.external:
return Icons.camera;
default:
throw ArgumentError('Unknown lens direction');
}
// This enum is from a different package, so a new value could be added at
// any time. The example should keep working if that happens.
// ignore: dead_code
return Icons.camera;
}

void _logError(String code, String? message) {
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
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.2
version: 0.10.2+1

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
6 changes: 5 additions & 1 deletion packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.10.2+3

* Updates code for stricter lint checks.

## 0.10.2+2

* Fixes zoom computation for virtual cameras hiding physical cameras in Android 11+.
* Removes the unused CameraZoom class from the codebase.
* Removes the unused CameraZoom class from the codebase.

## 0.10.2+1

Expand Down
6 changes: 4 additions & 2 deletions packages/camera/camera_android/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
return Icons.camera_front;
case CameraLensDirection.external:
return Icons.camera;
default:
throw ArgumentError('Unknown lens direction');
}
// This enum is from a different package, so a new value could be added at
// any time. The example should keep working if that happens.
// ignore: dead_code
return Icons.camera;
}

void _logError(String code, String? message) {
Expand Down
19 changes: 15 additions & 4 deletions packages/camera/camera_android/lib/src/android_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class AndroidCamera extends CameraPlatform {
// ignore: body_might_complete_normally_catch_error
(Object error, StackTrace stackTrace) {
if (error is! PlatformException) {
// ignore: only_throw_errors
throw error;
}
completer.completeError(
Expand Down Expand Up @@ -520,9 +521,14 @@ class AndroidCamera extends CameraPlatform {
return 'always';
case FlashMode.torch:
return 'torch';
default:
throw ArgumentError('Unknown FlashMode value');
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'off';
}

/// Returns the resolution preset as a String.
Expand All @@ -540,9 +546,14 @@ class AndroidCamera extends CameraPlatform {
return 'medium';
case ResolutionPreset.low:
return 'low';
default:
throw ArgumentError('Unknown ResolutionPreset value');
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'max';
}

/// Converts messages received from the native platform into device events.
Expand Down
9 changes: 7 additions & 2 deletions packages/camera/camera_android/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ String serializeDeviceOrientation(DeviceOrientation orientation) {
return 'landscapeRight';
case DeviceOrientation.landscapeLeft:
return 'landscapeLeft';
default:
throw ArgumentError('Unknown DeviceOrientation value');
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'portraitUp';
}

/// Returns the device orientation for a given String.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android
description: Android implementation of the camera plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.2+2
version: 0.10.2+3

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.10+2

* Updates code for stricter lint checks.

## 0.9.10+1

* Updates code for stricter lint checks.
Expand Down
6 changes: 4 additions & 2 deletions packages/camera/camera_avfoundation/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
return Icons.camera_front;
case CameraLensDirection.external:
return Icons.camera;
default:
throw ArgumentError('Unknown lens direction');
}
// This enum is from a different package, so a new value could be added at
// any time. The example should keep working if that happens.
// ignore: dead_code
return Icons.camera;
}

void _logError(String code, String? message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class AVFoundationCamera extends CameraPlatform {
// ignore: body_might_complete_normally_catch_error
(Object error, StackTrace stackTrace) {
if (error is! PlatformException) {
// ignore: only_throw_errors
throw error;
}
completer.completeError(
Expand Down Expand Up @@ -526,9 +527,14 @@ class AVFoundationCamera extends CameraPlatform {
return 'always';
case FlashMode.torch:
return 'torch';
default:
throw ArgumentError('Unknown FlashMode value');
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'off';
}

/// Returns the resolution preset as a String.
Expand All @@ -546,9 +552,14 @@ class AVFoundationCamera extends CameraPlatform {
return 'medium';
case ResolutionPreset.low:
return 'low';
default:
throw ArgumentError('Unknown ResolutionPreset value');
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'max';
}

/// Converts messages received from the native platform into device events.
Expand Down
9 changes: 7 additions & 2 deletions packages/camera/camera_avfoundation/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ String serializeDeviceOrientation(DeviceOrientation orientation) {
return 'landscapeRight';
case DeviceOrientation.landscapeLeft:
return 'landscapeLeft';
default:
throw ArgumentError('Unknown DeviceOrientation value');
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'portraitUp';
}

/// Returns the device orientation for a given String.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.10+1
version: 0.9.10+2

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.4

* Updates code for stricter lint checks.

## 2.3.3

* Updates code for stricter lint checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class MethodChannelCamera extends CameraPlatform {
// ignore: body_might_complete_normally_catch_error
(Object error, StackTrace stackTrace) {
if (error is! PlatformException) {
// ignore: only_throw_errors
throw error;
}
completer.completeError(
Expand Down Expand Up @@ -519,8 +520,6 @@ class MethodChannelCamera extends CameraPlatform {
return 'always';
case FlashMode.torch:
return 'torch';
default:
throw ArgumentError('Unknown FlashMode value');
}
}

Expand All @@ -539,8 +538,6 @@ class MethodChannelCamera extends CameraPlatform {
return 'medium';
case ResolutionPreset.low:
return 'low';
default:
throw ArgumentError('Unknown ResolutionPreset value');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ String serializeExposureMode(ExposureMode exposureMode) {
return 'locked';
case ExposureMode.auto:
return 'auto';
default:
throw ArgumentError('Unknown ExposureMode value');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ String serializeFocusMode(FocusMode focusMode) {
return 'locked';
case FocusMode.auto:
return 'auto';
default:
throw ArgumentError('Unknown FocusMode value');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ extension ImageFormatGroupName on ImageFormatGroup {
case ImageFormatGroup.jpeg:
return 'jpeg';
case ImageFormatGroup.unknown:
default:
return 'unknown';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ String serializeDeviceOrientation(DeviceOrientation orientation) {
return 'landscapeRight';
case DeviceOrientation.landscapeLeft:
return 'landscapeLeft';
default:
throw ArgumentError('Unknown DeviceOrientation value');
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.3.3
version: 2.3.4

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.1+1

* Updates code for stricter lint checks.

## 0.3.1

* Updates to latest camera platform interface, and fails if user attempts to use streaming with recording (since streaming is currently unsupported on web).
Expand Down
8 changes: 7 additions & 1 deletion packages/camera/camera_web/lib/src/camera_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,15 @@ class CameraService {
case ResolutionPreset.medium:
return const Size(720, 480);
case ResolutionPreset.low:
default:
return const Size(320, 240);
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return const Size(320, 240);
}

/// Maps the given [deviceOrientation] to [OrientationType].
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_web
description: A Flutter plugin for getting information about and controlling the camera on Web.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.3.1
version: 0.3.1+1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.4.3

* Updates code for stricter lint checks.

## 2.4.2

* Updates code for stricter lint checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
preferredRenderer = 'legacy';
break;
case AndroidMapRenderer.platformDefault:
default:
case null:
preferredRenderer = 'default';
}

Expand Down
Loading

0 comments on commit 783ce6d

Please sign in to comment.