如何 运行 SwiftLint 处理 m1 的未提交文件
how to run SwiftLint on uncommitted files for m1
我找到了这个 shell 脚本
# Run SwiftLint
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
# Run SwiftLint for given filename
run_swiftlint() {
local filename=""
if [[ "${filename##*.}" == "swift" ]]; then
#${SWIFT_LINT} autocorrect --path "${filename}"
${SWIFT_LINT} lint --path "${filename}"
fi
}
if [[ -e "${SWIFT_LINT}" ]]; then
echo "SwiftLint version: $(${SWIFT_LINT} version)"
# Run for both staged and unstaged files
git diff --name-only | while read filename; do run_swiftlint "${filename}"; done
git diff --cached --name-only | while read filename; do run_swiftlint "${filename}"; done
else
echo "${SWIFT_LINT} is not installed."
exit 0
fi
END_DATE=$(date +"%s")
DIFF=$(($END_DATE - $START_DATE))
echo "SwiftLint took $(($DIFF / 60)) minutes and $(($DIFF % 60)) seconds to complete."
这边
https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
在我将计算机更新为 M1 芯片之前,它一直运行良好。
根据这篇博客
https://www.anotheriosdevblog.com/installing-swiftlint-on-a-m1/
我们应该改变路径的位置。
我怀疑这与 SwiftLint 的安装位置有关:
但是我不熟悉自制软件或 shell 脚本来让它工作。
新 Mac 上的自制软件位置已更改。
改变
SWIFT_LINT=/usr/local/bin/swiftlint
至
SWIFT_LINT=/opt/homebrew/bin/swiftlint
已解决问题
我找到了这个 shell 脚本
# Run SwiftLint
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
# Run SwiftLint for given filename
run_swiftlint() {
local filename=""
if [[ "${filename##*.}" == "swift" ]]; then
#${SWIFT_LINT} autocorrect --path "${filename}"
${SWIFT_LINT} lint --path "${filename}"
fi
}
if [[ -e "${SWIFT_LINT}" ]]; then
echo "SwiftLint version: $(${SWIFT_LINT} version)"
# Run for both staged and unstaged files
git diff --name-only | while read filename; do run_swiftlint "${filename}"; done
git diff --cached --name-only | while read filename; do run_swiftlint "${filename}"; done
else
echo "${SWIFT_LINT} is not installed."
exit 0
fi
END_DATE=$(date +"%s")
DIFF=$(($END_DATE - $START_DATE))
echo "SwiftLint took $(($DIFF / 60)) minutes and $(($DIFF % 60)) seconds to complete."
这边 https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
在我将计算机更新为 M1 芯片之前,它一直运行良好。
根据这篇博客 https://www.anotheriosdevblog.com/installing-swiftlint-on-a-m1/ 我们应该改变路径的位置。 我怀疑这与 SwiftLint 的安装位置有关:
但是我不熟悉自制软件或 shell 脚本来让它工作。
新 Mac 上的自制软件位置已更改。
改变
SWIFT_LINT=/usr/local/bin/swiftlint
至
SWIFT_LINT=/opt/homebrew/bin/swiftlint
已解决问题