LoginSignup
3
1

More than 5 years have passed since last update.

VSCodeでHaxeをAutoformat

Last updated at Posted at 2018-08-11
  1. VSCode に AStyle拡張機能をインストール
  2. setting.jsonに以下を記述
"astyle.additional_languages": ["haxe"],
"astyle.cmd_options": ["--mode=cs", "-f", "-U", "-Y", "-o", "-xe", "-xg", "-xL", "-S", "-t", "-xj", "-xt1", "-xW", "-z2"]

3.コマンドパレット等からフォーマットを実行

オプション(Short) オプション(Full) 説明
--mode=cs インデントのパターン
デフォルトだと、C,C++でも見られるキーワード(ex: アクセス修飾子public/private)を含む行のインデントがずれる
-o --keep-one-line-statements 1行内の複数の式を改行しない
-j --add-braces 1行の条件文を{}で囲む
-S --indent-switches switch式のブロック内をインデント
-s
-s#
--indent=space
--indent-space=#
スペースでインデント
#は1インデントあたりの文字幅(未設定:4文字分)
-t
-t#
--indent=tab
--indent-tab=#
タブ文字でインデント
#は-s#と同じ
-f --break-blocks コードブロックやクラス記述の前後に空行を挿入
-xe --delete-empty-lines 関数内の空行を削除
-xg --pad-comma カンマの後ろにスペースを1つ挿入
-p ---pad-oper 演算子の前後にスペースを1つ挿入
-U --unpad-paren 丸括弧の内側に隣接するスペースを削除
-xC# --max-code-length=# 1行の文字数が#文字以下になるよう、
論理演算子、セミコロン等で改行
-xL --break-after-logical -xC#とセットで使用
論理演算子を複数含む行を改行するとき、演算子より後ろで改行(オプションなし:演算子の前で改行)
-z1
-z2
-z3
--lineend=windows
--lineend=linux
--lineend=macold
改行コードの設定
-z1(=windows): CRLF(Windows)
-z2(=linux): LF(Linux, Mac OSX)
-z3(=macold): CR(Mac 9まで)

オプションはまだまだあるので、
使用に際しては公式を読むことをおすすめします。

参考:

Is there a code formatter tool for Haxe code?
https://stackoverflow.com/questions/41648474/is-there-a-code-formatter-tool-for-haxe-code

Artistic Style 3.1
http://astyle.sourceforge.net/astyle.html

3
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
3
1