realm /SwiftLint
A tool to enforce Swift style and conventions.
★ 19,791⑂ 2,345👁 230⑃ 4,059● 2,871▤ 153
TA的项目
+0
日增长
19,791
stars
2,345
forks
230
watchers
4,059
prs
2,871
issues
153
releases
README
SwiftLint SwiftLint 是一个用于强制检查 Swift 代码风格和规定的一个工具,基本上以 Kodeco's Swift 代码风格指南为基础。 SwiftLint Hook 了 Clang 和 SourceKit 从而能够使用 AST 来表示源代码文件的更多精确结果。 ! 该项目遵守 贡献者契约行为守则。一旦参与,你将被视为支持这一守则。请将 不可接受的行为报告给 [email protected]。 安装 使用Swift Package Manager SwiftLint 可以用作命令插件或构建工具插件 添加 swift .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "") 到你的 Package.swift 文件中,以自动获取 SwiftLint 的最新版本,或者将依赖项固定到特定版本: swift .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: "") 其中,用所需的最低版本或精确版本替换 。 Xcode Package Dependency 使用以下链接将 SwiftLint 作为包依赖添加到 Xcode 项目中: bash https://github.com/SimplyDanny/SwiftLintPlugins 使用 Homebrew brew install swiftlint 使用 CocoaPods 将如下代码添加到你的 Podfile 即可: ruby pod 'SwiftLint' 在下一次执行 pod install 时将会把 SwiftLint 的二进制文件和依赖下载到 Pods/ 目录下并且将允许你通过 ${PODS_ROOT}/SwiftLint/swiftlint 在 Script Build Phases 中调用 SwiftLint。 自从 SwiftLint 支持安装某个特定版本后,安装一个指定版本的 SwiftLint 是目前推荐的做法相比较于简单地选择最新版本安装的话(比如通过 Homebrew 安装的话)。 请注意这会将 SwiftLint 二进制文件、所依赖的二进制文件和 Swift 二进制库安装到 Pods/ 目录下,所以不推荐将此目录添加到版本控制系统(如 git)中进行跟踪。 使用 Mint mint install realm/SwiftLint 使用安装包 你也可以通过从最新的 GitHub 发布地址下载 SwiftLint.pkg 然后执行的方式安装 SwiftLint。 编译源代码 你也可以通过 clone SwiftLint 的 Git 仓库到本地然后执行 make install (Xcode 15.0+) 以从源代码构建及安装。 使用 Bazel 把这个放到你的 MODULE.bazel: bzl bazel_dep(name = "swiftlint", version = "0.50.4", repo_name = "SwiftLint") 或把它放到你的 WORKSPACE: WORKSPACE bzl load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "build_bazel_rules_apple", sha256 = "390841dd5f8a85fc25776684f4793d56e21b098dfd7243cd145b9831e6ef8be6", url = "https://github.com/bazelbuild/rules_apple/releases/download/2.4.1/rules_apple.2.4.1.tar.gz", ) load( "@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies", ) apple_rules_dependencies() load( "@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies", ) swift_rules_dependencies() load( "@build_bazel_rules_swift//swift:extras.bzl", "swift_rules_extra_dependencies", ) swift_rules_extra_dependencies() http_archive( name = "SwiftLint", sha256 = "c6ea58b9c72082cdc1ada4a2d48273ecc355896ed72204cedcc586b6ccb8aca6", url = "https://github.com/realm/SwiftLint/releases/download/0.52.4/bazel.tar.gz", ) load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos") swiftlint_repos() load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps") swiftlint_deps() 然后你就可以在当前目录下使用这个命令运行 SwiftLint: console bazel run -c opt @SwiftLint//:swiftlint 用法 报告 我们鼓励你观看本次报告,来获得将 SwiftLint 整合到你的项目中的推荐方式的一个高层次概括: Xcode 整合 SwiftLint 到 Xcode 体系中去从而可以使警告和错误显示到 IDE 上,只需要在 Xcode 中添加一个新的“Run Script Phase”并且包含如下代码即可: ! Xcode 15 对 Build Settings 进行了重大更改,它将 ENABLE_USER_SCRIPT_SANDBOXING 的默认值从 NO 更改为 YES。 因此,SwiftLint 会遇到与缺少文件权限相关的错误,通常报错信息为:error: Sandbox: swiftlint(19427) deny(1) file-read-data. 要解决此问题,需要手动将 ENABLE_USER_SCRIPT_SANDBOXING 设置为 NO,以针对 SwiftLint 配置的特定目标。 如果你是在搭载 Apple 芯片的 Mac 上通过 H
Top issues
#4015Xcode 14 introduces new run script build phase warning for SwiftLint44 comments · 2022-07-05#319Add Rules to Support Ray Wenderlich's Swift Style Guide32 comments · 2016-01-06#27Support Xcode Fix-Its26 comments · 2015-05-22#3988Bus error18 comments · 2022-06-03#3046indentation_width warning on multiple cases of switch-case18 comments · 2020-01-17#5207Running lint without any code changes is still slow (30s vs 40s without cache)16 comments · 2023-09-07#1573Support tabs in vertical parameter alignment rule16 comments · 2017-05-26#4821Fatal error while scanning apple/swift repo15 comments · 2023-03-15
Latest release
0.65.1: Fresh Folded Fixtures 0.65.1 2026-08-21Breaking Configuration.IndentationStyle moved to SwiftLintCore.IndentationStyle. Rules can now read the global indentation setting via CurrentRule.configuration. GandaLF2006 Remove the deprecated allow_multiline_func option from the opening_brace rule. Use ignore_multiline_function_signatures instead. Brett-Best Enhancements Speed up the collection_alignment rule, which read the whole file's source lines once per element of a dictionary literal. Brett-Best Compare the two operands of a comparison by walking their token streams in the identical_ope