Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[camera] Ignore implementation imports outside of lib #6191

Merged
merged 3 commits into from
May 7, 2024

Conversation

srawlins
Copy link
Contributor

Work towards dart-lang/linter#4859

There are libraries outside a lib/ directory, which violate implementation_imports. The fix here is to always add an 'ignore' exception, as the "implementation" being imported is the very package being exemplified.

(Maybe that's a perfect reason to re-examine the public API of the package; can you create a good example / example test without importing the private implementation libraries?)

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

There are libraries outside a `lib/` directory, which violate
`implementation_imports`. The fix here is to always add an 'ignore' exception,
as the "implementation" being imported is the very package being exemplified.

(Maybe that's a perfect reason to re-examine the public API of the package; can
you create a good example / example test without importing the private
implementation libraries?)
@srawlins
Copy link
Contributor Author

I have many more PRs like this to mail; please let me know how I can proceed; I can keep just adding // ignore: and // ignore_for_file: comments. I can put comments at the end of the line, above all imports, whatever. LMK.

@ditman
Copy link
Member

ditman commented Feb 24, 2024

@srawlins if you're finding these inside integration_tests of web packages, I think you should be able to just //ignore_for_file. The analyzer doesn't understand that these tests belong to the parent package, but we need an example app to flutter drive them (so they look like bad imports).

I'm not sure that redoing the exposed API of the package to expose things "visibleForTesting" is worth it (but we could have a top-level library that reexports what we need just for testing, I guess? It could be done, the implementation packages are private for the users' of a plugin, so they should not be importing from these APIs directly)

If you find any of these outside of integration_tests, those probably do need revisiting, though!

WDYT @stuartmorgan?

@stuartmorgan
Copy link
Contributor

Yes, there's a very specific pattern for plugins in particular, where the only way to do end-to-end testing of even most individual methods is to run it in the integration_test of an app (because the native code that is half of the code under test doesn't exist in Dart unit tests or widget tests), so we do a lot of what is functionally more like unit testing of the package in example/integration_test instead.

So I agree that we should just treat anything in example/integration_test/ of a plugin just like we would test/, and then look closely at anything else (if there are other things) that violate the lint.

@srawlins
Copy link
Contributor Author

Sounds good! I can follow that pattern; thanks so much for the guidance.

@ditman
Copy link
Member

ditman commented Feb 26, 2024

Thanks @srawlins! Also, if you want to make one big PR with all the changes, I'll get it reviewed and merged as soon as I see it! (or maybe I can create the super big PR if you want)

@srawlins
Copy link
Contributor Author

Here is the file with all of the lines that need changing (~60) across this repo: https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8756626596148228113/+/u/analyze_flutter_packages/stdout?format=raw

WDYT about fixing them? I was going to do it more incrementally, and on the back burner. But I'd love if you wanted to clean them up 😁

@ditman
Copy link
Member

ditman commented Feb 26, 2024

Yep, I'll try to get this later tonight.

@stuartmorgan
Copy link
Contributor

Why is it flagging things in test/legacy/?

@srawlins
Copy link
Contributor Author

@stuartmorgan Do you mean these lines?

   info - test/legacy/webview_flutter_test.dart:7:8 - Import of a library in the 'lib/src' directory of another package. Try importing a public library that exports this library, or removing the import. - implementation_imports
   info - test/legacy/webview_flutter_test.dart:8:8 - Import of a library in the 'lib/src' directory of another package. Try importing a public library that exports this library, or removing the import. - implementation_imports
   info - test/legacy/webview_flutter_test.dart:14:8 - Import of a library in the 'lib/src' directory of another package. Try importing a public library that exports this library, or removing the import. - implementation_imports

These correspond to these source lines:

import 'package:flutter/src/foundation/basic_types.dart';
import 'package:flutter/src/gestures/recognizer.dart';
...
import 'package:webview_flutter/src/webview_flutter_legacy.dart';

Those imports are considered "implementation imports." Should test/legacy be considered differently?

@stuartmorgan
Copy link
Contributor

Is test/ not exempt from this lint? I would have thought unit tests importing from src/ would be pretty common.

@srawlins
Copy link
Contributor Author

Oh I see you mean the third import there. That does seem odd. I can look into that.

@ditman
Copy link
Member

ditman commented Feb 27, 2024

It seems the implementation_imports lint is already enabled:

But my analyzer is not picking any of those up:

dit@dit:/work/flutter/packages/packages/camera/camera_web/example/integration_test$ flutter analyze .
Analyzing integration_test...                                           
No issues found! (ran in 2.8s)
dit@dit:/work/flutter/packages/packages/camera/camera_web/example/integration_test$ dart analyze .
Analyzing ....                         1.3s
No issues found!

How can I modify our analysis_options.yaml so I can generate my list of affected files?

@srawlins
Copy link
Contributor Author

I think it would be quite a bit of effort, to re-create the fix for dart-lang/linter#4859 in a custom Dart SDK and use that to analyze this repo. The only way I know how is with the bot that generated that report. 😁

@ditman
Copy link
Member

ditman commented Feb 27, 2024

Ahhh oof, didn't realize this was a change in the behavior of the lint itself!

(PS: will try again tomorrow, it's a little bit late now in PT!)

@srawlins
Copy link
Contributor Author

My bad, the third violating import is this one:

import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart';

line-off-by-one human-error 😁

@stuartmorgan
Copy link
Contributor

Thanks, that makes more sense. That one we can ignore since it's a very weird special case (upstream testing of something that's a use case that's only allowed within google3).

The flutter includes seem weird; we'll need to look into those.

@stuartmorgan
Copy link
Contributor

From triage: What's the status of this PR?

@srawlins
Copy link
Contributor Author

Ready to go 😄

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label May 7, 2024
@srawlins srawlins merged commit 8df8b5f into main May 7, 2024
79 checks passed
@srawlins srawlins deleted the impl_imps_camera_web branch May 7, 2024 15:42
@ditman
Copy link
Member

ditman commented May 7, 2024

Agh, totally forgot about this one. Thanks @srawlins! 🙇

@srawlins
Copy link
Contributor Author

srawlins commented May 7, 2024

No worries! Not high priority

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 8, 2024
flutter/packages@5ccddfc...8de142d

2024-05-07 [email protected] [path_provider] Add Swift Package Manager support (flutter/packages#6680)
2024-05-07 [email protected] [go_router] guard context access in then clauses (flutter/packages#6685)
2024-05-07 [email protected] Roll Flutter from 04424e1 to 7920a52 (27 revisions) (flutter/packages#6683)
2024-05-07 [email protected] [camera] Ignore implementation imports outside of lib (flutter/packages#6191)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
Work towards dart-lang/linter#4859

There are libraries outside a `lib/` directory, which violate
`implementation_imports`. The fix here is to always add an 'ignore'
exception, as the "implementation" being imported is the very package
being exemplified.

(Maybe that's a perfect reason to re-examine the public API of the
package; can you create a good example / example test without importing
the private implementation libraries?)



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [x] I [linked to at least one issue that this PR fixes] in the
description above.
- [x] 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 `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
Work towards dart-lang/linter#4859

There are libraries outside a `lib/` directory, which violate
`implementation_imports`. The fix here is to always add an 'ignore'
exception, as the "implementation" being imported is the very package
being exemplified.

(Maybe that's a perfect reason to re-examine the public API of the
package; can you create a good example / example test without importing
the private implementation libraries?)



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [x] I [linked to at least one issue that this PR fixes] in the
description above.
- [x] 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 `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-web
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants