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

Apply linter suggestions for cleaner code #43

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

Lingepumpe
Copy link
Contributor

@Lingepumpe Lingepumpe commented Aug 11, 2024

This PR is on top of the FitSDK 21.141.00 branch.

In this PR additionally to the SDK update, I fixed issues that the linter (clippy) was pointing out. This also involved fixes in autogenerated profile/decode.rs and profile/field_types.rs files - for this I adapted the code that generates them. Additionally I added cargo clippy --fix and cargo fmt to the update_profile.sh shell script, as for profile/field_types.rs this leads to a nice collapsing of huge match "|" cascades into simple ranges, which is much more readable (and maybe even faster, I am not sure what the compiler does).

@stadelmanma
Copy link
Owner

Thanks for looking at this, I'm fine with the clippy fixes in the main "human written" code base, those are good. However, I don't think I want to apply them to the auto-generated code at the tail end of the shell script. Clippy re-writes things in a nontrivial way at times, and that will make it harder to track down bugs since the code we see getting written in the generation step doesn't exist 1:1 in the code being run anymore.

That being said, using clippy to suggest ways we can improve code generation does seem like a very good idea, especially if they would be trivial to implement like where it changed .map().flatten() to an .and_then()

Also I call "rustfmt" via code in the main script,

Command::new("rustfmt")
so the extra call in the shell script isn't needed. But maybe it was the application of clippy that required that to be done again.

@Lingepumpe
Copy link
Contributor Author

Lingepumpe commented Aug 12, 2024

Yes, exactly, the final "cargo fmt" was needed due to the auto-fixes. If you prefer I will just remove the automatic fixing after autogeneration entirely, but I really do like the changes it makes (it is only one change, fixing the clippy::manual_range_patterns lint). So for now I have adjusted the cargo clippy call to be restricted to only fixing manual_range_patterns.
The fix it applies always looks like this:
image

But I am also fine dropping the auto fixing part of my PR if you prefer, let me know.

@stadelmanma
Copy link
Owner

I think for now I'd like to drop any automatic code changes (other than the programmatically called rustfmt), so more or less removing the changes to bin/update_profile.sh. The profile code is impossible to fully validate at this time so I'd like to keep it's creation as straight forward as possible instead of adding another layer of complexity.

I love the other changes, and wouldn't be opposed to updating the codegen script to create the desired output for matches! on large ranges directly. Same for anything else suggested by clippy that makes sense, although I'm not sure how far down the rabbit hole we should go, since those files aren't really meant to be "read" by humans.

@Lingepumpe
Copy link
Contributor Author

As requested, I have dropped the automatic code changes (clippy fix + cargo fmt) from update_profile.sh. Instead, I changed the code that generates profile/field_types.rs to detect ranges and generate the first..=last syntax in this case.

Also, I rebased the branch on master, as the FitSDK 21.141.00 branch was merged.

@stadelmanma
Copy link
Owner

This looks great now, I'll do some local testing probably tomorrow and get it merged in!

@stadelmanma stadelmanma merged commit a2e5fca into stadelmanma:master Aug 16, 2024
1 check passed
@stadelmanma
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants