2024-07-23




・C/C++/C#/Objective-C/Java
clang-format
apt install clang-format clang-format <filename> clang-format -i <filename> # 上書き </filename></filename>
uncrustify
apt install uncrustify uncrustify -c uncrustify.conf --no-backup *.c
などとして使う。--no-backupをつけると既存ファイル上書き。
confは整形コンフィグファイル。ぐぐると色々な場所に様々な設定が落ちている。
当サイトのuncrustify.conf
・HTML/JavaScript
tidy、Node.jsのprettier、どちらもHTML/JavaScript両方フォーマットしてくれるが、個人的にはHTMLはtidy、JavaScriptはprettierが見栄えが良いと思う。
なので自分の場合ログインファイルでprettier→tidyにパイプしている。
apt install tidy tidy -config tidy.conf -m index.html #上書き保存オプション-m npm install prettier -g prettier --write index.html #上書き保存オプション--write
tidy.conf サンプル
Shell | tidy.conf | GitHub Source |
//bare: yes //clean: yes //drop-proprietary-attributes: yes //indent: auto indent: yes indent-spaces: 2 wrap: 0 newline: LF quiet: yes tidy-mark: no //tidy-mark: yes
・PHP
php-cs-fixer PHPをダウンロードしてそのまま使う。
wget http://get.sensiolabs.org/php-cs-fixer.phar php php-cs-fixer.phar fix sample.php #ディレクトリ指定も可能
・Python
yapf
pip3.7 install yapf yapf test.py > test.new.py # デフォルトは標準出力 yapf test.py -d # 差分を表示 yapf test.py -i # 上書き保存 yapf testdir -i -r # ディレクトリ内のPythonファイルを一括置換+上書き保存
・Android/Java
Android Studioメニューの Reformat Code 一択。
あと自動でインポート文を生成してくれるオプションがすごく便利。
File→Settins→Editor→General→Auto Import
・Add unambiguous imports on the fly
・Optimize imports on the fly (for current project)
にチェックを入れる。
この設定のうえで、Reformat Codeですべてのチェックを入れてRunする。
・Cleanup code
・Scope → All Places
・File mask → Javaなら*.java、リソースなら*.xml
なお、現時点でオートインポートは完璧ではなく、なぜか完全スルーされてしまうクラスあり。
例)android.os.Handler
・Swift Swimat
※本記事内容の無断転載を禁じます。
ご連絡は以下アドレスまでお願いします★
オープンソースリップシンクエンジンSadTalkerをDebianで動かす
ファイアウォール内部のOpenAPI/FastAPIのdocsを外部からProxyPassで呼ぶ
Debian 12でsshからshutdown -h nowしても電源が切れない場合
【Windows&Mac】アプリのフルスクリーンを解除する方法
Debian 12でtsコマンドが見つからないcommand not found
Debian 12でsyslogやauth.logが出力されない場合
Debian 12で固定IPアドレスを使う設定をする
Debian 12 bookwormでNVIDIA RTX4060Ti-OC16GBを動かす
【Debian】apt updateでCD-ROMがどうのこうの言われエラーになる場合
Windows11+WSL2でUbuntuを使う【2】ブリッジ接続+固定IPの設定
【Windows10】リモートデスクトップ間のコピー&ペーストができなくなった場合の対処法
【Apache】サーバーに同時接続可能なクライアント数を調整する
【C/C++】小数点以下の切り捨て・切り上げ・四捨五入
【ひかり電話+VoIPアダプタ】LANしか通ってない環境でアナログ電話とFAXを使う
GitLabにHTTPS経由でリポジトリをクローン&読み書きを行う
Intel Macbook2020にBootCampで入れたWindows11 Pro 23H2のBluetoothを復活させる
VirtualBoxの仮想マシンをWindows起動時に自動起動し終了時に自動サスペンドする
Windows11でMacのキーボードを使うには