swift-foundations/swift-institute-linter-rules

GitHub: swift-foundations/swift-institute-linter-rules

面向 Swift 开发者的 Institute 级别 lint 规则集,基于 SwiftSyntax 提供命名、内存安全、typed throws、平台分层等多维度代码规范检查。

Stars: 0 | Forks: 0

# swift-institute-linter-rules ![开发状态](https://img.shields.io/badge/status-active--development-blue.svg) 面向 Institute 级别的 lint 规则包,专为 [swift-linter](https://github.com/swift-foundations/swift-linter) 设计 —— 包含基于 SwiftSyntax 的规则,涵盖命名、typed throws、字节规范、内存安全、平台分层和代码结构,并统一打包发布为 `Lint.Rule.Bundle.institute`。 ## 快速开始 使用者只需在包根目录下(紧挨着 `Package.swift`)放置一个单独的 `Lint.swift` 文件,即可激活完整的 institute 规则集: ``` // swift-linter-tools-version: 0.1 import Linter import Linter_Institute_Rules Lint.run(dependencies: [ .package( url: "https://github.com/swift-foundations/swift-institute-linter-rules.git", branch: "main", products: ["Linter Institute Rules"] ), ]) { Lint.Rule.Bundle.institute } ``` bundle 名称本身就是全部配置:`Lint.Rule.Bundle.institute` 将通用层 bundle 与本包中的所有 institute 层规则包组合在一起。因此,使用者只需引用一个标识符,就能在添加新包时自动获取新规则——无需同步维护逐条规则的枚举。 每个规则包也作为独立的库产品发布(参见下文的架构说明),方便只需使用部分规则集而非完整 bundle 的使用者。 ## 安装说明 如果要在 Swift 代码中直接使用规则定义(例如组合自定义 bundle),请将该包添加到您的 `Package.swift` 中: ``` dependencies: [ .package(url: "https://github.com/swift-foundations/swift-institute-linter-rules.git", branch: "main") ] ``` ``` .target( name: "YourTarget", dependencies: [ .product(name: "Linter Institute Rules", package: "swift-institute-linter-rules") ] ) ``` ### 前置条件 - Swift 6.3+ - macOS 26.0+, iOS 26.0+, tvOS 26.0+, watchOS 26.0+, visionOS 26.0+ ## 架构 | 产品 | 何时导入 | |---------|----------------| | `Linter Institute Rules` | 默认选项。发布 `Lint.Rule.Bundle.institute` —— 包含通用层 bundle 以及下方的所有 institute 规则包。 | | `Institute Linter Rule ` | 在不需要完整 bundle 时,用于有选择地采用单个规则包。 | 规则包,每个对应一个库产品: | 包 | 涵盖范围 | |------|--------| | `Naming` | 复合标识符和类型名、命名空间采用、标签后缀、冗余前缀、临时 box 类 | | `Foundation` | 无 Foundation 目标中的 Foundation 导入 | | `Framework` | XCTest 导入、swift-testing 套件分类 | | `Byte` | 字节域边界的 UInt8/Byte 区分:conformance、witness、forwarder、ASCII 扩展 | | `Cardinal` | Cardinal 类型字面量构造、`.count - 1` 边界运算 | | `Conformance` | Leaf body 中 typealias 的存在性 | | `Closure` | 闭包参数位置、生命周期闭包的顺序和标签、配置放置 | | `Idiom` | 迭代意图、enumerated-with-subscript、有界索引、UTF-8 字符串扫描 | | `Manifest` | Package manifest 的依赖声明形式 | | `Memory` | Noncopyable 扩展约束、指针运算、Sendable 结构形状、unsafe-assignment 粒度、unchecked-Sendable 锚点 | | `Platform` | 公共 API 中的 C 类型、平台条件语句、各平台的死分支、平台命名空间分层 | | `RawValue` | `.rawValue` 链式调用和位模式转换的反模式、Tagged-newtype 公共初始化器和 unchecked-construction 形式 | | `Structure` | 每个文件单一类型、raw-value 访问、wrapper 形式、最小化类型主体、提取的协议别名 | | `Testing` | 测试函数命名、性能套件序列化 | | `Throws` | Typed-throws 采用:无类型和存在型 throws、typed do-catch、提取的错误、result-shim 模式 | | `Try` | Optional-try 用法 | | `Unchecked` | Unchecked 调用点 | 每条规则的诊断消息都旨在说明默认处理方式(如何修复发现的问题)以及已知的豁免情况,因此发现的问题无需查阅外部文档即可直接处理——审查时偶尔会发现个别消息未能达到此要求,并将其作为针对该规则的缺陷进行提交。 ## 相关包 - [swift-linter](https://github.com/swift-foundations/swift-linter) —— 通过 `Lint.swift` 使用这些包的 lint 引擎。 - [swift-linter-primitives](https://github.com/swift-primitives/swift-linter-primitives) —— 构建这些规则所基于的 `Lint.Rule` 和源码模型基元。 - swift-linter-rules(待公开发布)—— 通用层规则包;`Lint.Rule.Bundle.institute` 包含了它的通用 bundle。 ## 许可证 Apache 2.0。详见 [LICENSE](LICENSE.md)。
标签:Lint规则, SOC Prime, Swift, SwiftSyntax, 代码规范, 开发工具, 静态检查