From 6d2861a993328289c9ab061203c6e2e279b71b5f Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Fri, 1 Dec 2023 10:41:47 +0400 Subject: [PATCH] fix style guide and move taplo config to .config --- .taplo.toml => .config/taplo.toml | 0 .gitlab/pipeline/check.yml | 4 ++-- docs/CONTRIBUTING.md | 19 ----------------- docs/STYLE_GUIDE.md | 34 ++++++++----------------------- 4 files changed, 11 insertions(+), 46 deletions(-) rename .taplo.toml => .config/taplo.toml (100%) diff --git a/.taplo.toml b/.config/taplo.toml similarity index 100% rename from .taplo.toml rename to .config/taplo.toml diff --git a/.gitlab/pipeline/check.yml b/.gitlab/pipeline/check.yml index 09e9e77bd42d..98435248eb4c 100644 --- a/.gitlab/pipeline/check.yml +++ b/.gitlab/pipeline/check.yml @@ -97,8 +97,8 @@ check-toml-format: - .common-refs script: - cargo install taplo-cli --locked --version 0.8.1 - - taplo format --check - - echo "Please run `taplo format` to fix any toml formatting issues" + - taplo format --check --config .config/taplo.toml + - echo "Please run `taplo format --config .config/taplo.toml` to fix any toml formatting issues" # More info can be found here: https://github.com/paritytech/polkadot/pull/5865 .check-runtime-migration: diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index d57ab8623ae2..1f68e2979f21 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -157,25 +157,6 @@ will run the tests for the specified rust version and specified image We use [zepter](https://github.com/ggwpez/zepter) to enforce features are propagated between crates correctly. -## Rust Code Style - -We use the nightly version of rustfmt to enforce consistent code formatting. - -You should format your code with `cargo +nightly fmt`. - -To see exactly which nightly version is used, check our CI job logs. - -## TOML Code Style - -We use [taplo](https://taplo.tamasfe.dev/) to enforce consistent TOML formatting. - -You can install it with `cargo install taplo-cli` and format your code with `taplo format`. - -You may find useful - -- [Taplo VSCode extension](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) -- For NeoVim, [taplo is avaliable with Mason](https://github.com/williamboman/mason-lspconfig.nvim#available-lsp-servers) - ## Command Bot If you're member of **paritytech** org - you can use command-bot to run various of common commands in CI: diff --git a/docs/STYLE_GUIDE.md b/docs/STYLE_GUIDE.md index 1ae9bc5003f6..3df65d9699a0 100644 --- a/docs/STYLE_GUIDE.md +++ b/docs/STYLE_GUIDE.md @@ -2,9 +2,11 @@ title: Style Guide for Rust in the Polkadot-SDK --- -Where possible these styles are enforced by settings in `rustfmt.toml` so if you run `cargo fmt` +Where possible these styles are enforced by settings in `rustfmt.toml` so if you run `cargo +nightly fmt` then you will adhere to most of these style guidelines automatically. +To see exactly which nightly version is used, check our CI job logs. + # Formatting - Indent using tabs. @@ -150,31 +152,13 @@ let mut target_path = # Manifest Formatting -> **TLDR** -> You can use the CLI tool [Zepter](https://crates.io/crates/zepter) to -> format the files: `zepter format features --fix` (or `zepter f f -f`). +We use [taplo](https://taplo.tamasfe.dev/) to enforce consistent TOML formatting. -Rust `Cargo.toml` files need to respect certain formatting rules. All entries -need to be alphabetically sorted. This makes it easier to read them and insert -new entries. The exhaustive list of rules is enforced by the CI. The general -format looks like this: +You can install it with `cargo install taplo-cli` and format your code with `taplo format --config .config/taplo.toml`. -- The feature is written as a single line if it fits within 80 chars: +See the config file for the exact rules. -```toml -[features] -default = [ "std" ] -``` +You may find useful -- Otherwise the feature is broken down into multiple lines with one entry per - line. Each line is padded with one tab and no trailing spaces but a trailing - comma. - -```toml -[features] -default = [ - "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong", - # Comments go here as well ;) - "std", -] -``` +- [Taplo VSCode extension](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) +- For NeoVim, [taplo is avaliable with Mason](https://github.com/williamboman/mason-lspconfig.nvim#available-lsp-servers)