rust-lang/rustc_codegen_gcc

Enable Rustfmt & Clippy for cg_gcc

tempdragon opened this issue · 11 comments

It takes a long time to manually adjust the code format and style, so I advice to enable the Rustfmt for this project to avoid potential bad styling.
As for clippy, it may be a good idea to reduce the poorly behaved code in Rust to improve code quality.

Tasks

Yes, good idea, I'll accept a PR doing that. Ideally, we should use the same rustfmt config used by the rust project, if any.

What about using your rustfmt?(Since you contribute the most code).
It seems that you can simply add your rustfmt.toml there? Or maybe I can upload my but it will just be a mare copy of the default one.

I tried once to get the formatting I wanted with rustfmt, but I was unable to because some settings were missing.
Using a different config than rustc will still cause issues to some people because VS Code sometimes ignore the config, so it seems best to use the same config as the Rust project.
It seems we'd only need to add a few lines to .rustfmt.toml to use the same config as the Rust project: https://github.com/rust-lang/rust/blob/master/rustfmt.toml#L2-L4

I once noticed that in some cases, Rustfmt may behave differently on different machines. A friend of mine used VSCode and our rustfmt seemed to behaved differently, causing our code to be reformatted over and over again. Still not sure about why and how.

Apparently, one cause is because formatting a selection of code only sends the code to be formatted to rustfmt, not the filename, so it cannot find the config.

By the way, have you switched back to vim? Is VSCode rustfmt-related behavior still a problem for you?

Oh, I never used VS Code. It's some people contributing to cg_gcc via the Rust repo that have this issue.

I've been using neovim (and vim before) for many years.

I formatted the code in #458.

By the way, is adding a full rustfmt specification useful?
Customized Conf

You probably want to use the same file as upstream https://github.com/rust-lang/rust/blob/6f435eb0eb2926cdb6640b3382b9e3e21ef05f07/rustfmt.toml, the ignore section isn't needed.

Fyi, if these wind up being large changes it's often a good idea to crosscheck. Two people run the same rustfmt commands then git ls-files -s . | git hash-object --stdin to make sure their hashes line up.

Adding the hash of the formatting commit to .git-blame-ignore-revs gets the noise out of blame views (automatic on GH, need to pass --ignore-revs-file via CLI)

Completed by #469.