C#のコードフォーマットをastyleでやったときのメモ

Posted on 2018年03月06日(火) in articles • Tagged with Unity, C#

astyleを使用してcodeformatを行う. http://astyle.sourceforge.net/

インストールはHomebrew経由でできた

brew install astyle

以下のようにすれば指定したディレクトリ以下のcsファイルに対してフォーマットがかけられる.

# findとgrepでフォーマットかけたいファイルを抽出.
# xargsで引数としてastyleを実行.
find Assets -type f | grep  \.cs$ | xargs -I@ astyle --options=.astyleoption @

オプションファイルの中身は以下の通り.:

# c#のファイルとして認識する
mode=cs
# allmanスタイルにする
style=allman
# インデントにタブを使う
indent=tab=4
# 継続行のインデントにもタブを使う(但し偶数個のタブでないときはwhite spaceで埋められる)
indent=force-tab=4
# namespace文の中をインデントする
indent-namespaces
# switch文の中をインデントする
indent-switches
# case文の中をインデントする
indent-cases
# 1行ブロックを許可する
keep-one-line-blocks
# 1行文を許可する ...

Continue reading