【问题标题】:how to run SwiftLint on uncommitted files for m1如何在 m1 的未提交文件上运行 SwiftLint
【发布时间】:2021-12-29 11:31:05
【问题描述】:

我找到了这个 shell 脚本

# 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."

这里 https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062

在我将计算机更新为 m1 芯片之前效果很好。

根据这个博客 https://www.anotheriosdevblog.com/installing-swiftlint-on-a-m1/ 我们应该改变路径的位置。 我怀疑这与安装 SwiftLint 的位置有关:

但是我不熟悉自制程序或 shell 脚本来使其正常工作。

【问题讨论】:

  • 有什么理由不在整个项目上运行 lint?
  • 警告太多,错误需要立即处理。也没有时间,因为功能/错误修复比修复 lint 警告具有更高的优先级。一旦我们修复了大多数警告,我们就可以在整个项目上运行 lint。
  • 你可以手动运行 swiftlint 吗?一般来说,没有必要把swiftlint的整个路径。使用SWIFT_LINT=swiftlint 应该就够了
  • SwiftLint 手动运行,所以如果我在终端中说 swiftlint,那么它就可以工作。不知道为什么我们必须给出它的安装路径,但是说 SWIFT_LINT=swiftlint 会破坏它,而说 SWIFT_LINT=/opt/homebrew/bin/swiftlint 让它工作。

标签: xcode swiftlint


【解决方案1】:

新 Mac 上的 Home-brew 位置已更改。

变化

SWIFT_LINT=/usr/local/bin/swiftlint

SWIFT_LINT=/opt/homebrew/bin/swiftlint

修复了问题

【讨论】:

    猜你喜欢
    • 2019-09-21
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 2015-04-02
    相关资源
    最近更新 更多