fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

v2.4.0 runs `dart fix` thus modifies codes not generated by frb #2316

Closed lbhfuture closed 1 month ago

lbhfuture commented 1 month ago

Describe the bug

I run flutter_rust_bridge_codegen integrate to add frb to my existed project, and it modified my codes which is not generated by frb.

The console shows:

[2024-09-26T06:14:49.361Z INFO .../flutter_rust_bridge_codegen-2.4.0/src/library/integration/integrator.rs:79] Apply Dart fixes
[2024-09-26T06:15:00.092Z INFO .../flutter_rust_bridge_codegen-2.4.0/src/library/integration/integrator.rs:82] Format Dart code

The formatter above should only modify dart code in lib/src/rust, but it seems not works well, and my flutter_rust_bridge.yaml is below:

rust_input: crate::api
rust_root: rust/
dart_output: lib/src/rust
enable_lifetime: true

frb version is 2.4.0

Steps to reproduce

  1. Run flutter_rust_bridge_codegen integrate to add frb to a existed project.

Logs

[2024-09-26T06:14:49.361Z INFO .../flutter_rust_bridge_codegen-2.4.0/src/library/integration/integrator.rs:79] Apply Dart fixes
[2024-09-26T06:15:00.092Z INFO .../flutter_rust_bridge_codegen-2.4.0/src/library/integration/integrator.rs:82] Format Dart code

Expected behavior

No response

Generated binding code

No response

OS

MacOS

Version of flutter_rust_bridge_codegen

2.4.0

Flutter info

No response

Version of clang++

No response

Additional context

No response

welcome[bot] commented 1 month ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 1 month ago
  1. Firstly, you can go back to older 2.3.0 version without the "auto run dart fix" feature, before this is handled
  2. No worries, it will not harm your code by modifying arbitrarily; instead, it only runs dart fix
  3. cc @AlexV525 who introduced the "auto run dart fix" feature (which is quite useful in some scenarios) - maybe we should at least make a bool flag for this feature?
AlexV525 commented 1 month ago

The tricky part is that dart fix does not support for fixing a single file. We can support opt-out of the feature first, then consider further support with handling a specific batch of files.

fzyzcjy commented 1 month ago

Totally agree!

AlexV525 commented 1 month ago

Oh, I just ran dart fix --apply ./dir_name and it works.

fzyzcjy commented 1 month ago

I tried it a bit:

dart fix --apply ./lib/main.dart ./lib/src/rust/frb_generated.dart 
Only one file or directory is expected.

Usage: dart fix [arguments]
-h, --help                      Print this usage information.
-n, --dry-run                   Preview the proposed changes but make no changes.
    --apply                     Apply the proposed changes.
    --code=<code1,code2,...>    Apply fixes for one (or more) diagnostic codes.

Run "dart help" to see global options

But we should not run dart fix one time for each file/folder, otherwise it may be slow... (not tested though; if running multiple ones does not have overhead, then this looks pretty reasonable)

Maybe we can also create/find an issue at Dart repo asking for supporting multiple file/folders

AlexV525 commented 1 month ago

We can only apply to dart_output, don't we?

fzyzcjy commented 1 month ago

Yes and no. Yes because usually that folder should only be touched by frb and not but normal users; no because theoretically we did not forbid users from adding any extra files there...

So I guess a workaround is to only apply to that folder, and if there rare latter case happens, we can tell users to move their files or to accept the fix.

AlexV525 commented 1 month ago

no because theoretically we did not forbid users from adding any extra files there...

Fair enough. We can improve our guides and warnings to tell users not to put extra files into the output path as the best practice.

fzyzcjy commented 1 month ago

Related: https://github.com/fzyzcjy/flutter_rust_bridge/discussions/2328

(manually add this comment since github does not auto backlink between discussion and issues)

Ferry-200 commented 1 month ago

Just upgraded from flutter_rust_bridge 2.0.0 to 2.4.0 and this issue surprised me lol

Anyway, it's time to make Dart analyzer happy.

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.