locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
497 stars 131 forks source link

Reformat all the code using cargo fmt โ€”all #75

Closed svanharmelen closed 3 years ago

svanharmelen commented 3 years ago

This is a potential solution for issue #74, so trying to make all the code formatting consistent. Really hope this format (the default) works for you, but if not then please let me know what you would like to have changed. Thanks!

locka99 commented 3 years ago

Can you send me a merge with just the rustfmt changed? I'll incorporate that, although traditionally I've used the built-in formatter in IntelliJ so I need to see what impact it has on auto-generated code before I apply it to the rest of the source.

svanharmelen commented 3 years ago

If you really want I will remove the second commit... But to be honest it doesn't do anything else then formatting and cleaning up the imports. There were some strange (unneeded) imports like use tokio::{self} or use std::{self, ...}. And there were a couple of places were primitives like u32 or u64 were specifically imported, while in other places they were not (which makes sense as they are already available through the std::prelude).

So sure you want me to delete that second commit?

As for Intelij, I use that as well (CLion). In one of the latest plugin updates they added this one:

image

So that makes it easy to follow the community styling ๐Ÿ˜‰

Thanks for the quick reaction by the way! These types of PR's are usually nasty to keep in sync, so thanks for not letting that happen!

locka99 commented 3 years ago

u32 and u64 were imported for some min/max stuff which at the time required the import and maybe don't now. What I'll do today is bring the rustfmt in from your req and run it locally and hopefully that will reduce this request to zero

locka99 commented 3 years ago

I have done the following in master and will close this request:

  1. Taken the rustfmt.toml from here (blank)
  2. Changed all the autogenerated files to say #![rustfmt:skip] at the top because changing the scripts to output rustfmt friendly code is a pain
  3. Run "cargo fmt" on the handwritten files

Concerning rustfmt I'm not sure I like the default formatting rules for a few things, especially the way an else doesn't start on a new line but appears as "} else {" for the time being I'll leave it this way.

svanharmelen commented 3 years ago

Super nice! Thanks @locka99 ๐Ÿ‘๐Ÿป

As for the defaults, you can of course always tweak the rustfmt.toml config to your preferences. Since the rustfmt.toml file is now in this repo, it will be used automatically by most (if not all) editors out there. So it will be much easier to keep the formatting consistent. Thanks again for doing this!