-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add TOML formatting with Taplo #784
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's bump the column width to 100 and the indentation size to 4 spaces. Both of these values are exactly what rustfmt
does with Rust code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to get a second opinion from @xStrom on the actions design, but otherwise this looks right to me.
.github/workflows/ci.yml
Outdated
@@ -81,6 +81,14 @@ jobs: | |||
- name: Run cargo fmt | |||
run: cargo fmt --all --check | |||
|
|||
- name: Install Taplo | |||
uses: uncenter/setup-taplo@v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of using another third party actions provider, but I see that wgpu also uses this.
It doesn't seem like the maintainer of this action actually uses it, which is slightly concerning.
If we just depended on a specific hash rather than just @v1
, the security concern goes away
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, this wouldn't have been my immediate reaction if we used the taiki-e/install-action
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just looked into adding taplo to the install-action list, but the format of taplo's release artifacts seems to change from release to release, so I'm not comfortable taking on that work.
Using a specific hash for uncenter's action seems easy enough.
.github/workflows/ci.yml
Outdated
with: | ||
version: "0.9.3" | ||
|
||
- name: run `taplo fmt` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: run `taplo fmt` | |
- name: Run taplo fmt |
would be consistent with the other projects.
.taplo.toml
Outdated
|
||
[formatting] | ||
# This is a matter of taste, but expanded inline arrays make tables harder to read. | ||
array_auto_collapse = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to already be the default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah not much point in defining array_auto_collapse
here as it matches the default.
|
||
# Aligning comments with the largest line creates | ||
# diff noise when neighboring lines are changed. | ||
align_comments = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
.taplo.toml
Outdated
# This is a matter of taste, but expanded inline arrays make tables harder to read. | ||
array_auto_collapse = true | ||
inline_table_expand = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about setting inline_table_expand
to false
. The expansion only happens when the line exceeds the length defined in column_width
(which we should have at 100).
With it false
, the following happens:
winapi = { version = "0.3.9", features = [
"winbase",
"libloaderapi",
"errhandlingapi",
"winuser",
"shellscalingapi",
"shobjidl",
"combaseapi",
"dxgi1_3",
"dwmapi",
"wincon",
"fileapi",
"processenv",
"winbase",
"winerror",
"handleapi",
"shellapi",
"winnls",
] }
# .. gets converted into:
winapi = { version = "0.3.9", features = ["winbase", "libloaderapi", "errhandlingapi", "winuser", "shellscalingapi", "shobjidl", "combaseapi", "dxgi1_3", "dwmapi", "wincon", "fileapi", "processenv", "winbase", "winerror", "handleapi", "shellapi", "winnls"] }
Also, just so I understand your claim, are you saying that the following expansion that we currently have makes the [workspace.lints]
table hard to read?
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(FALSE)',
'cfg(tarpaulin_include)',
] }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found while testing it that the formatter was really eager to break up inline tables even when it didn't seem needed to stay below the column limit. I'll give it another look.
Add Taplo config. Format TOM config files. Add Taplo step to CI.
Add CI step
I've addressed review comments. Taplo with a column width of 100 seems to mostly leave inline tables be, so I've removed the |
The config options look good now. Still two things though:
|
Huh, I really thought I'd fixed both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Why go with something different than what cargo itself generates? That's just going to be an ongoing conflict with other tools. TOML is not Rust, I would suggest 2 space indent to match other tools that edit the manifest and lock files in the Rust toolchain. |
Well we had far more 4 spaces already for one. I am curious though which cargo command generates indents? I know I tried tokio = { version = "1.42.0", features = ["bytes", "fs", "full", "io-std", "io-util", "libc", "macros", "mio", "net", "parking_lot", "process", "rt", "signal", "socket2", "sync", "test-util", "time", "tokio-macros", "tracing"] } |
The Rust Style Guide has a page called Cargo.toml conventions. It states:
So there you go, the Rust docs seem to agree with our chosen options of 100 and 4 spaces. |
Indeed. I guess I'll take my beef upstream to In any event if that's what the Rust style guide suggests, then unless/until that gets changed upstream I'd say carry on! I'll likely adjust my own |
Add Taplo config.
Format TOM config files.
Add Taplo step to CI.