《Go / JSON / Shell 代码格式化》

《Go / JSON / Shell 代码格式化》

一个用于格式化项目内 Go / JSON / Shell 脚本的一键脚本,可纳入 CI 或本地提交流程。

1. 格式化脚本

#!/bin/bash set -e # format go file for file in $(find . -type f -regex ".*\.go"); do go fmt $file done # format json file for file in $(find . -type f -regex ".*\.json"); do cat $file | python -m json.tool >/tmp/xxx cat /tmp/xxx >$file done # install shfmt if not present if [ ! -x `which shfmt` ]; then go get -u mvdan.cc/sh/cmd/shfmt fi # format shell scripts shfmt -w scripts/control.sh shfmt -w scripts/matrix/bin/noah_control

2. 工具说明

工具 用途 安装方式
go fmt 格式化 Go 代码 Go 自带
python -m json.tool 格式化 JSON Python 自带
shfmt 格式化 Shell go get mvdan.cc/sh/cmd/shfmt
阅读 — · 全站 —
🎸 我的歌单 0 首