LoginSignup
4
1

More than 1 year has passed since last update.

rustfmtの設定ファイルってどう書くの???

Last updated at Posted at 2022-05-07

主題

rustfmtの設定ファイルの記述方法がパッとみてよくわからなかったので備忘録
基本はrustfmtのREADMEに書いてある。

設定ファイルの形式

rustfmt.tomlまたは.rustfmt.tomlを作ればOK。
あとはtomlの形式に沿って書く。

tomlって? ざっくり言うと、設定を簡単に書く用の形式。

下記みたいな感じで単純に左辺と右辺をイコールで結ぶだけ

max_width = 100

参考: https://toml.io/ja/v0.4.0

簡単に設定を記載する方法

READMEに書いてあるが、下記コマンドを叩くとデフォルト設定を勝手に吐き出してくれるので、それを書き換えるだけで良い

rustfmt --print-config default rustfmt.toml 

各設定項目の詳細

下記を参照
https://rust-lang.github.io/rustfmt/

no stableな設定

stable: Noである設定項目に関してはrustupをstableからnightlyへ変更する必要がある。
※rustupというかtoolchain?のversionを切り替えるイメージだろうか。
正直ここはちょっとよくわかってないので教えて欲しいです。

rustup toolchain install nightly

その上で、+nightlyをつけてフォーマットをかけると下記の様になる。

cargo +nightly fmt

# report_todo = "Always"に変更した場合のメッセージ
# 余談だけど、この機能結構便利

warning: found TODO
  --> /Users/ryoga/dev/git/rust_traning/src/main.rs:17
   |
17 | // TODO
   |

warning: rustfmt has failed to format. See previous 1 errors.

参考

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1