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

Conversation

@stuartmorgan-g
Copy link
Contributor

Small updates to analysis_options.yaml to better align with flutter/packages (and thus flutter/flutter, since it has more flutter/flutter options enabled than flutter/plugins currently does):

  • enable no_default_cases
  • enable only_throw_errors
  • change the way deliberate divergence from flutter/flutter is indicated; the flutter/packages way is easier to reason about than the current flutter/plugins approach, so this switches to match that (reducing diff in preparation for eventual repo merge)

no_default_cases required the most changes. I wrote up the approach I used at https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#enum-handling since we should have a consistent pattern across all plugins. I put an inline explanation for each ignore though so that it doesn't require jumping to a browser to understand it, and won't become mysterious if that link breaks someday.

Part of flutter/flutter#76229
Part of flutter/flutter#113764

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@stuartmorgan-g
Copy link
Contributor Author

This just needs one person to review the whole PR; there's nothing complex here that requires each plugin owner to review their slice.

@tarrinneal
Copy link
Contributor

Seems like you broke a couple tests in the process here. Also readme excerpts need an update

// ignore: body_might_complete_normally_catch_error
(Object error, StackTrace stackTrace) {
if (error is! PlatformException) {
// ignore: only_throw_errors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be addressed instead of ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice this is only a violation if invokeMapMethod is violating the lint, since we're just rethrowing the same object. That seemed unlikely enough that I didn't think it was worth worrying about given that the plan is to migrate all plugins to Pigeon over time, and this code would be eliminated in a Pigeon migration.

@stuartmorgan-g
Copy link
Contributor Author

The LUCI failures are infra problems. I do need to fix the excerpts though.

@stuartmorgan-g
Copy link
Contributor Author

It looks like some of the excerpts failures are false positives; I'll do a quick fix to flutter/flutter#111592 and then revisit this.

// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return 'max';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should just keep the old behavior of throwing? It seems like in most of these cases you can keep the same behavior by removing the exception outside of the default branch which would keep the same logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep the same logic, but I changed it because throwing seems very extreme to me when there's a reasonable fallback.

When these switches were first written, everything was one package and this case meant that we'd forgotten to implement something, so it was a bug. Now it means that a client is using an implementation version that doesn't support that option yet, so a fallback seems better to me.

@stuartmorgan-g
Copy link
Contributor Author

@tarrinneal or @bparrishMines could one of you take the review on this one?

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a question

return Icons.camera;
// 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: no_default_cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for here

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 20, 2023
@auto-submit auto-submit bot merged commit 783ce6d into flutter:main Jan 20, 2023
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants