我有一个非常大的iOS(遗留)项目,我想在其中添加SwiftLint。所有我希望执行的规则,我只会在新创建的文件上执行。通过这种方式,我不必回去解决所有可能出现的问题,因为过去没有遵循这些规则(因为没有使用SwiftLint )。我不确定如何实现这一点?
发布于 2021-11-18 14:42:53
您可以像这样运行脚本
# Run SwiftLint
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
# Run SwiftLint for given filename
run_swiftlint() {
local filename="${1}"
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."只需使用以下代码将构建阶段运行脚本添加到Xcode
"${SRCROOT}/Scripts/swiftlint.sh"它来自这里https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
它在M1芯片上不起作用,因为你需要这样说
if test -d "/opt/homebrew/bin/"; then
PATH="/opt/homebrew/bin/:${PATH}"
fi
export PATH
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fine基于此博客的https://www.anotheriosdevblog.com/installing-swiftlint-on-a-m1/
https://stackoverflow.com/questions/68723113
复制相似问题