美文网首页
SwiftLint 技术分享

SwiftLint 技术分享

作者: 黑色茄子 | 来源:发表于2022-08-07 21:40 被阅读0次
    一、前言

    项目越来越大,仅靠人工代码review可能有时候会比较费时费力,所以这时就有必要借助于一种自动化的代码审查工具:程序静态分析

    程序静态分析(Program Static Analysis)

    是指在不运行代码的方式下,通过词法分析、语法分析、控制流、数据流分析等技术对程序代码进行扫描,验证代码是否满足规范性、安全性、可靠性、可维护性等指标的一种代码分析技术

    在项目中引进第三方程序静态分析框架来规范代码风格,做到尽量统一,不管是对团队还是对个人都有不少的益处,个人来说可以对自己的编码进行规范,写出比较不"难看"的代码,对于团队来说,把风格统一了,后期维护也可以减少一定量的难度.

    二、目的

    规范代码风格第三方框架 SwiftlLint 使用说明和评估

    三、介绍

    SwiftLint 是 realm 公司开发的一个插件,专门用于管理 Swift 代码的规范,Swift 中也规定了基本的编码规范,用于定义采用 Swift 编程时, 对于「美」的倾向。基本标准已经在git 开源Swift 编程官网规范,而SwiftLint用来规范开发者在编程时对 Swift 规范进行贯彻执行。
    SwiftLint 的工作原理是检查 Swift 代码编译过程中的 AST 和 SourceKit 环节,从而可以摆脱不同版本 Swift 语法变化的影响。AST 是编译前端形成的抽象语法书(Abstract Symbolic Tree), SourceKit 过程用来对 AST 进行代码优化,减少内存开销,提高执行效率。如果对编译过程理解不太清楚,可以参考:ASTLLVM优点
    AST
    SwiftLint 是一个用于强制检查 Swift 代码风格和规定的一个工具。它的实现是 Hook 了 Clang 和 SourceKit 从而能够使用AST来表示源代码文件的更多精确结果。Clange我们了解了,那SourceKit是干什么用的?
    SourceKit包含在Swift项目的主仓库,它是一套工具集,支持Swift的大多数源代码操作特性:源代码解析、语法突出显示、排版、自动完成、跨语言头生成等工作。

    四、安装

    可以通过homebrew 或者 CocoaPods

    homebrew

    在安装好homebrew的前提下,在终端下输入

    brew install SwiftLint 
    

    更新到最新版本

    brew upgrade SwiftLint
    

    查看当前版本号

    swiftlint version
    

    查看所有命令

    swiftlint help
    

    忽略空格导致的警告和错误

    swiftlint autocorrect
    

    输出所有的警告和错误

    swiftlint lint
    

    查看所有可获得的规则以及对应的 ID

    swiftlint rules
    

    如果我们想将此次分析生成一份报告,也是可以的(该命令是通过homebrew安装的swiftlint

    swiftlint lint--reporter html>swiftlint.html
    
    CocoaPods
    pod  ’SwiftLint’
    
    五、使用

    homebrew 安装的话 可以在xcode添加脚本 全局配置


    1496356018654447.png
    if which swiftlint >/dev/null; then
      swiftlint
    else
      echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
    fi
    

    CocoaPods安装的话 就添加脚本如下


    1496356072529718.png
    "${PODS_ROOT}/SwiftLint/swiftlint"
    
    六、规则

    截止我写这篇的时候, default rules 90条, Opt-In Rules 123条

    Default Rules
        •   block_based_kvo: Block Based KVO   使用 Swift 3.2 或更高版本时,使用KVO时优先使用block。
        •   class_delegate_protocol: Class Delegate Protocol  delegate protocol 应该被设定为 class-only,才能被弱引用
        •   closing_brace: Closing Brace Spacing  小括号内包含函数(大括号)的时候,之间没有空格
        •   closure_parameter_position: Closure Parameter Position 闭包参数位置, 闭包参数应该 { 左边在同一行
        •   colon: Colon Spacing  冒号左边没有空格, 右边有且只有一个空格
        •   comma: Comma Spacing  逗号左边没有空格, 右边有空格
        •   comma_inheritance: Comma Inheritance Rule 使用逗号分隔继承列表中的类型
        •   comment_spacing: Comment Spacing  建议在斜线后至少留一个空格作为注释。
        •   compiler_protocol_init: Compiler Protocol Init  不应该直接调用字面量转换的初始化方法,诸如编译器协议中声明的初始化程序ExpressibleByArrayLiteral不应直接调用
        •   computed_accessors_order: Computed Accessors Order  计算的属性和下标中的Getter和setter应该保持一致的顺序。
        •   control_statement: Control Statement if while 等判断条件不要用括号 括起来,另外注意条件处的空格
        •   custom_rules: Custom Rules  user-defined 通过提供正则表达式字符串来创建自定义规则
        •   cyclomatic_complexity: Cyclomatic Complexity  代码复杂度,默认为10,循环复杂度。函数体的复杂度的限制,这个属性主要约束条件句、循环句中的循环嵌套问题, 当嵌套太多的循环时,则会触发swiftlint中的warning和error,当达到10个循环嵌套时就会报warning,达到20个循环嵌套时就会报error,强烈推荐这个属性。嵌套太多,可读性差
        •   deployment_target: Deployment Target  可用性检查或属性不应使用部署目标满足的旧版本
        •   discouraged_direct_init: Discouraged Direct Initialization  不鼓励直接初始化并声明的类型 warning:types: ["Bundle", "Bundle.init", "UIDevice", "UIDevice.init"]
        •   duplicate_enum_cases: Duplicate Enum Cases  枚举不能设置两个或者以上相同的名字
        •   duplicate_imports: Duplicate Imports  重复导入
        •   duplicated_key_in_dictionary_literal: Duplicated Key in Dictionary Literal 具有重复键的字典文字将在运行时崩溃。
        •   dynamic_inline: Dynamic Inline  避免同时使用'dynamic'和'@inline(__ always)'
        •   empty_enum_arguments: Empty Enum Arguments  如果将枚举与关联的类型匹配(如果不使用),则可以忽略参数
        •   empty_parameters: Empty Parameters  使用 `() -> ` 代替 `Void ->
        •   empty_parentheses_with_trailing_closure: Empty Parentheses with Trailing Closure  尾闭包避免空参数括号
        •   file_length: File Length  文件长度
        •   for_where: For Where  使用 `for where` 代替 简单的 `for { if }`
        •   force_cast: Force Cast  避免强制的类型转化,这里表示强解类型警告
        •   force_try: Force Try  对会抛出异常(throws)的方法,不建议try,强解, 避免 `try!`
        •   function_body_length: Function Body Length    函数体长度限制 warning: 40, error: 100
        •   function_parameter_count: Function Parameter Count  函数参数个数 默认5 warning 8 error
        •   generic_type_name: Generic Type Name   类型命名规则限制,以大写字母开头,且长度在1到20个字符之间,(min_length) w/e: 1/0, (max_length) w/e: 20/1000, excluded: [], allowed_symbols: [], validates_start_with_lowercase: true
        •   identifier_name: Identifier Name  命名规则必须按照驼峰原则,与后台传的Json字段命名冲突,建议排除掉
        •   implicit_getter: Implicit Getter  read-only  参数不应该有getter方法
        •   inclusive_language: Inclusive Language  标识符应使用包容性语言,避免基于种族、性别或社会经济地位对人群的歧视
        •   inert_defer: Inert Defer  如果defer在其父范围的末尾,则无论如何它都会被执行
        •   is_disjoint: Is Disjoint  优先:Set.isDisjoint(with:) 不建议:Set.intersection(_:).isEmpty
        •   large_tuple: Large Tuple  元祖成员 元组冲突:元组应该最多有2个成员,多余两个会报错
        •   leading_whitespace: Leading Whitespace  文件开始不应该存在空格符
        •   legacy_cggeometry_functions: Legacy CGGeometry Functions  避免使用 C 风格 的 CG 遗留函数, 使用 struct extension
        •   legacy_constant: Legacy Constant  避免使用 遗留的全局常量, 使用 struct 内定义的 常量
        •   legacy_constructor: Legacy Constructor  使用 swift 提供的 struct 构造函数, 避免使用 遗留的构造函数 比如 CGPointMake(10, 10)
        •   legacy_hashing: Legacy Hashing  优先使用函数而不是覆盖hashValue
        •   legacy_nsgeometry_functions: Legacy NSGeometry Functions  避免使用 C 风格 的 NS 遗留函数, 使用 struct extension
        •   legacy_random: Legacy Random 随机函数 优先使用type.random(in :),不建议使用旧版函数。
        •   line_length: Line Length  行的字符长度,这个强烈不推荐使用。官方的规定是超过120字符就给warning,
        •   mark: Mark  //MARK: - 正确使用 mark 的格式 `// MARK: - message`
        •   multiple_closures_with_trailing_closure: Multiple Closures with Trailing Closure  当函数有多个闭包时, 不建议使用尾随闭包语法/多个闭包与尾随闭包冲突:在传递多个闭包参数时不应该使用尾随关闭语法。
        •   nesting: Nesting  类型定义嵌套不要超过1层 , 声明嵌套不要超过5层
        •   no_fallthrough_only: No Fallthrough Only  仅当case包含至少一个其他语句时,才能使用穿透
        •   no_space_in_method_call: No Space in Method Call  不要在方法名称和括号之间添加空格
        •   notification_center_detachment: Notification Center Detachment  移除通知要在 'deinit'中
        •   nsobject_prefer_isequal: NSObject Prefer isEqual  NSObject子类应实现isEqual而不是==
        •   opening_brace: Opening Brace Spacing  右括号之前应有一个空格,并与声明在同一行
        •   operator_whitespace: Operator Function Whitespace 当定义空格操作符的时候,被定义的名字或类型两边应该各有一个单行空格操作符
        •   orphaned_doc_comment: Orphaned Doc Comment 注释要写在声明中
        •   private_over_fileprivate: Private over fileprivate  推荐:private 不建议:fileprivate; warning:validate_extensions: false
        •   private_unit_test: Private Unit Test  单元测试方法 不能设置为 private
        •   protocol_property_accessors_order: Protocol Property Accessors Order   在协议中声明属性  要按顺序先写 get set方法
        •   reduce_boolean: Reduce Boolean  优先使用.allSatisfy()或.contains() 不建议使用:reduce(true)或reduce(false)
        •   redundant_discardable_let: Redundant Discardable Let    使用 `_ = foo()` 代替 `let _ = foo()`
        •   redundant_objc_attribute: Redundant @objc Attribute  Objective-C属性(@objc)在声明中是多余的,warning
        •   redundant_optional_initialization: Redundant Optional Initialization  默认值赋值为nil
        •   redundant_set_access_control: Redundant Set Access Control Rule  如果属性设置程序访问级别与变量访问级别相同,则不应明确
        •   redundant_string_enum_value: Redundant String Enum Value 在定义字符串枚举的时候, 当字符串枚举值等于枚举名称时,可以不用赋值
        •   redundant_void_return: Redundant Void Return  在不必要的时候, 不需要写 ->() and -> Void
        •   return_arrow_whitespace: Returning Whitespace  前后要有空格,函数定义返回的 -> 前后有空格, 不换行
        •   self_in_property_initialization: Self in Property Initialization   闭包参数 调用self要用lazy
        •   shorthand_operator: Shorthand Operator   使用+= , -=, *=, /= 222222 代替 a = a + 1
        •   statement_position: Statement Position  应该与 } 在同一行,以空格间隔
        •   superfluous_disable_command: Superfluous Disable Command  当禁用规则不会在禁用区域触发违规时,SwiftLint的“禁用”命令是多余的。如果要记录命令,请使用“-”,warning  
        •   switch_case_alignment: Switch and Case Statement Alignment  Case语句应与其封闭的switch语句垂直对齐,如果没有其他配置,则缩进
        •   syntactic_sugar: Syntactic Sugar   语法糖[Int] 代替Array / 例:要使用 [] ? 等数组字典可选项的语法糖
        •   todo: Todo    避免 TODOs and FIXMEs 标识
        •   trailing_comma: Trailing Comma  数组末尾不要加空格,warning mandatory_comma: false
        •   trailing_newline: Trailing Newline   末尾空行,文件末尾应该有一个空行
        •   trailing_semicolon: Trailing Semicolon   末尾跟分号
        •   trailing_whitespace: Trailing Whitespace   每一个空行不能有空格,会与Xcode换行后自动对齐生成的空格冲突,建议排除掉
        •   type_body_length: Type Body Length   类型体长度。类型体长度不应该跨越太多行,超过200行给warning,超过350行给error,可自定义enum或struct
        •   type_name: Type Name   类型名应该只包含字母数字字符, 并且以大写字母开头,长度在3-40个字符
        •   unavailable_condition: Unavailable Condition  不可用条件
        •   unneeded_break_in_switch: Unneeded Break in Switch  在switch-case语句中, 有方法调用或操作时,避免使用break语句
        •   unused_capture_list: Unused Capture List   闭包中没有被使用的参数应该删除
        •   unused_closure_parameter: Unused Closure Parameter   函数的参数必须被使用
        •   unused_control_flow_label: Unused Control Flow Label    未使用的控制流标签应被删除
        •   unused_enumerated: Unused Enumerated   默认-当参数没有被全部使用的时候, 不要使用容器的 enumerated 方法
        •   unused_optional_binding: Unused Optional Binding   在使用if判断某变量是否为nil的时候, 不建议使用下划线(_)
        •   unused_setter_value: Unused Setter Value  不使用设定值
        •   valid_ibinspectable: Valid IBInspectable   默认-IBInspectable   必须是可变参数
        •   vertical_parameter_alignment: Vertical Parameter Alignment   函数参数分为多行书写的时候, 头部(小括号后面一位)必须对齐
        •   vertical_whitespace: Vertical Whitespace  垂直方向上的空格行,限制为一行(注释除外)
        •   void_return: Void Return   返回值为空,推荐用 ” -> Void “, 而不是 ” -> ()
        •   xctfail_message: XCTFail Message   XCTFail调用应包括断言的描述,描述不能为空
    
    Opt-In Rules
        •   accessibility_label_for_image: Accessibility Label for Image  图像的可访问性标签
        •   anonymous_argument_in_multiline_closure: Anonymous Argument in Multiline Closure   多行闭包中的匿名参数
        •   anyobject_protocol: AnyObject Protocol  对于纯类协议,建议AnyObject 不推荐 class
        •   array_init: Array Init   推荐使用 Array(seq) 不推荐语法: seq.map { $0 } 将序列转换为Array
        •   attributes: Attributes  属性应该在函数和类型中自己的行上,与变量和 imports 在同一行上
        •   balanced_xctest_lifecycle: Balanced XCTest life-cycle  平衡单元测试声明周期
        •   capture_variable: Capture Variable  捕获变量
        •   closure_body_length: Closure Body Length  封包不应跨越太多行
        •   closure_end_indentation: Closure End Indentation   闭包前后缩进应相同
        •   closure_spacing: Closure Spacing  闭包表达式在每个大括号 { } 内前后应有一个空格
        •   collection_alignment: Collection Element Alignment   集合文字中的所有元素应垂直对齐
        •   conditional_returns_on_newline: Conditional Returns on Newline  条件语句与结果不建议写在一行 ,例如:guard true else { return } ;if true { return "YES" } else { return "NO" } 会有 warning提示
        •   contains_over_filter_count: Contains Over Filter Count   推荐使用 contains,避免使用 filter(where:).count 与 0 相比较
        •   contains_over_filter_is_empty: Contains Over Filter Is Empty  推荐使用 contains,避免使用 filter(where:).isEmpty
        •   contains_over_first_not_nil: Contains over first not nil   推荐使用 contains,避免使用 first(where:) != nil 与 firstIndex(where:) != nil
        •   contains_over_range_nil_comparison: Contains over range(of:) comparison to nil  推荐使用 contains,不建议使用与nil的比较
        •   convenience_type: Convenience Type  用于检测静态成员的类型应实现为无大小写的枚举,以避免实例化
        •   discarded_notification_center_observer: Discarded Notification Center Observer  当使用 block 注册通知中心 observer 的时候, 应该存储函数返回的 observer, 以便之后的删除
        •   discouraged_assert: Discouraged Assert 避免使用断言
        •   discouraged_none_name: Discouraged None Name  避免使用none 做变量名
        •   discouraged_object_literal: Discouraged Object Literal   避免使用图片和颜色的字面量(Ltiteral),尽量使用初始化的方式
        •   discouraged_optional_boolean: Discouraged Optional Boolean  推荐使用非可选的bool值
        •   discouraged_optional_collection: Discouraged Optional Collection  优先选择空集合而不是可选集合
        •   empty_collection_literal: Empty Collection Literal  优先使用isEmpty 空数组或字典文字进行值的比较
        •   empty_count: Empty Count   建议使用isEmpty判断,而不是使用count==0判断
        •   empty_string: Empty String   优先使用isEmpty判断,而不是将字符串与空字符串文字进行比较
        •   empty_xctest_method: Empty XCTest Method   应避免使用空的XCTest方法
        •   enum_case_associated_values_count: Enum Case Associated Values Count   枚举情况下的关联值数量应少
        •   expiring_todo: Expiring Todo   TODO和FIXME应该在其到期日之前解决
        •   explicit_acl: Explicit ACL   所有声明都应明确指定访问控制级别关键字
        •   explicit_enum_raw_value: Explicit Enum Raw Value   枚举应设置默认值
        •   explicit_init: Explicit Init   避免直接调用 init 方法
        •   explicit_self: Explicit Self   实例变量和函数应使用“self”显式访问
        •   explicit_top_level_acl: Explicit Top Level ACL   顶级声明应明确指定访问控制级别关键字
        •   explicit_type_interface: Explicit Type Interface   需要跑明确参数的类型定义
        •   extension_access_modifier: Extension Access Modifier   优先使用扩展名访问修饰符
        •   fallthrough: Fallthrough   避免在 case语句中使用 fallthrough
        •   fatal_error_message: Fatal Error Message   必须拥有一个 message
        •   file_header: File Header   标头注释应与项目模式一致
        •   file_name: File Name    文件名应与文件中声明的类型或扩展名匹配(如果有
        •   file_name_no_space: File Name No Space    文件名无空格
        •   file_types_order: File Types Order   指定如何排序文件中的类型
        •   first_where: First Where  使用 .first(where:) 代替 .filter { }.first
        •   flatmap_over_map_reduce: FlatMap over map and reduce  推荐使用 flatMap,避免使用 map 的 reduce([], +)
        •   force_unwrapping: Force Unwrapping   避免强制解包
        •   function_default_parameter_at_end: Function Default Parameter at End   方法中参数列表,应将带有默认值的参数放在最后面
        •   ibinspectable_in_extension: IBInspectable in Extension   扩展不应添加@IBInspectable属性
        •   identical_operands: Identical Operands   比较两个相同的操作数可能是一个错误
        •   implicit_return: Implicit Return    在闭包,函数和getter中更喜欢隐式返回
        •   implicitly_unwrapped_optional: Implicitly Unwrapped Optional    避免隐式解析可选类型的使用 / 避免隐式解包(定义 ! 类型)
        •   indentation_width: Indentation Width   缩进长度
        •   joined_default_parameter: Joined Default Parameter    不推荐显式使用默认分隔符
        •   last_where: Last Where    推荐在集合中使用:.last(where:) 不推荐使用: .filter { }.last
        •   legacy_multiple: Legacy Multiple   推荐使用isMultiple(of:)函数,不推荐使用余数运算符(%)
        •   legacy_objc_type: Legacy Objective-C Reference Type   旧版 Objective-C 引用类型
        •   let_var_whitespace: Variable Declaration Whitespace   let和var应该用空白行与其他语句分开
        •   literal_expression_end_indentation: Literal Expression End Indentation    数组和字典文字的结尾应与开始它的行具有相同的缩进
        •   lower_acl_than_parent: Lower ACL than parent   确保定义的访问控制级别低于其父级
        •   missing_docs: Missing Docs  声明应记录在案
        •   modifier_order: Modifier Order   修饰符顺序应一致
        •   multiline_arguments: Multiline Arguments   参数应该在同一行,或者每行一个
        •   multiline_arguments_brackets: Multiline Arguments Brackets   多行参数应在其新行中包含方括号 []
        •   multiline_function_chains: Multiline Function Chains   链接的函数调用应该在同一行上,或者每行一个
        •   multiline_literal_brackets: Multiline Literal Brackets   多行文字应在其新行中包含方括号 []
        •   multiline_parameters: Multiline Parameters   函数和方法参数应该在同一行上,或者每行一个
        •   multiline_parameters_brackets: Multiline Parameters Brackets   多行参数应在其新行中包含方括号
        •   nimble_operator: Nimble Operator   避免 expect 一个确定的判断
        •   no_extension_access_modifier: No Extension Access Modifier    禁止使用扩展访问修饰符
        •   no_grouping_extension: No Grouping Extension   扩展名不应用于对同一源文件中的代码进行分组
        •   nslocalizedstring_key: NSLocalizedString Key   应将静态字符串用作NSLocalizedString中的键
        •   nslocalizedstring_require_bundle: NSLocalizedString Require Bundle    调用NSLocalizedString应该指定包含字符串文件的捆绑软件
        •   number_separator: Number Separator    使用 _ 分割大数, 让数字更清晰
        •   object_literal: Object Literal    避免 image and color 使用字面量初始化, 需要把相关图片名,颜色RGB 等参数定义为 enum struct 或者常量
        •   operator_usage_whitespace: Operator Usage Whitespace    操作符需要使用一个空格间隔
        •   optional_enum_case_matching: Optional Enum Case Match   将枚举大小写与不带'?'的可选枚举匹配 在Swift 5.1及更高版本中受支持
        •   overridden_super_call: Overridden methods call super   方法需要调用 super method
        •   override_in_extension: Override in Extension    扩展不应覆盖声明
        •   pattern_matching_keywords: Pattern Matching Keywords   通过将关键字移出元组来组合多个模式匹配绑定
        •   prefer_nimble: Prefer Nimble   建议使用函数式调用
        •   prefer_self_in_static_references: Prefer Self in Static References   在静态引用中首选 Self
        •   prefer_self_type_over_type_of_self: Prefer Self Type Over Type of Self    访问属性或调用方法时,最好将“自类型”设置为(of:self)
        •   prefer_zero_over_explicit_init: Prefer Zero Over Explicit Init  首选零而不是显式初始化
        •   prefixed_toplevel_constant: Prefixed Top-Level Constant   顶级常量的前缀应为k
        •   private_action: Private Actions   IBActions应该是私有的
        •   private_outlet: Private Outlets    IBOutlets 应该设置为 private, 来避免泄露
        •   private_subject: Private Combine Subject
        •   prohibited_interface_builder: Prohibited Interface Builder  禁止用interface Builder 创建视图
        •   prohibited_super_call: Prohibited calls to super   某些特殊的 override 方法, 禁止调用 super method excluded: [[]], included: [["*"]]
        •   quick_discouraged_call: Quick Discouraged Call   不鼓励在“describe”和/或“context” 框中进行调用
        •   quick_discouraged_focused_test: Quick Discouraged Focused Test    不鼓励重点测试。专注于此测试时,其他测试将不会运行
        •   quick_discouraged_pending_test: Quick Discouraged Pending Test    不推荐:未开始的测试。标记为待定时,该测试不会运行
        •   raw_value_for_camel_cased_codable_enum: Raw Value For Camel Cased Codable Enum  设置枚举建议设置默认值
        •   reduce_into: Reduce Into  对于 copy-on-write 类型,推荐使用 reduce(into::) 不建议使用 reduce(:_:)
        •   redundant_nil_coalescing: Redundant Nil Coalescing   #避免使用 object ?? nil 仅当lhs为nil时才评估nil合并运算符,而n为rhs则合并nil合并运算符
        •   redundant_type_annotation: Redundant Type Annotation   变量不应具有冗余类型注释 建议 var url = URL() 不建议 var url : URL = URL()
        •   required_deinit: Required Deinit  类应具有显式的deinit方法
        •   required_enum_case: Required Enum Case    符合指定协议的枚举必须实现特定情况
        •   return_value_from_void_function: Return Value from Void Function    应避免从 Void 函数返回值。
        •   single_test_class: Single Test Class   测试文件应只包含一个QuickSpec或XCTestCase类
        •   sorted_first_last: Min or Max over Sorted First or Last   优先使用min()或max() 不建议使用 sorted().first或sorted().last 
        •   sorted_imports: Sorted Imports    Imports 应排序
        •   static_operator: Static Operator    应该将运算符声明为静态函数,而不是自由函数
        •   strict_fileprivate: Strict fileprivate   fileprivate 应该避免
        •   strong_iboutlet: Strong IBOutlet   @IBOutlets不应被声明为weak 应该为 strong
        •   switch_case_on_newline: Switch Case on Newline   switch 的 case 需要新启一行
        •   test_case_accessibility: Test case accessibility  测试用例应该只包含私有的非测试成员。
        •   toggle_bool: Toggle Bool   不让使用 A = !A 建议使用 A.toggle(
        •   trailing_closure: Trailing Closure   尽可能使用尾随闭包语法
        •   type_contents_order: Type Contents Order   指定类型内子类型,属性,方法及更多内容的顺序
        •   typesafe_array_init: Type-safe Array Init   优先使用 Array(seq) 而不是 seq.map { $0 } 将序列转换为数组。
        •   unavailable_function: Unavailable Function   未实现的功能应标记为不可用
        •   unneeded_parentheses_in_closure_argument: Unneeded Parentheses in Closure Argument    声明闭包参数时,不需要括号
        •   unowned_variable_capture: Unowned Variable Capture    最好将引用捕获为弱引用以避免潜在的崩溃
        •   untyped_error_in_catch: Untyped Error in Catch   没有类型转换,catch语句不应声明错误变量
        •   unused_declaration: Unused Declaration     在所有被删除的文件中,声明至少应被引用一次
        •   unused_import: Unused Import    import 的文件要被使用
        •   vertical_parameter_alignment_on_call: Vertical Parameter Alignment On Call     如果函数参数在方法调用中位于多行中,则应垂直对齐
        •   vertical_whitespace_between_cases: Vertical Whitespace Between Cases     在 switch cases 之间包括一条空行
        •   vertical_whitespace_closing_braces: Vertical Whitespace before Closing Braces    在关闭大括号之前,请勿包括垂直空格(空行)
        •   vertical_whitespace_opening_braces: Vertical Whitespace after Opening Braces   打开花括号后,请勿包括垂直空格(空行)
        •   weak_delegate: Weak Delegate   代理要设置为弱引用
        •   xct_specific_matcher: XCTest Specific Matcher   优先使用特定的XCTest匹配器,XCTAssertEqual而不是XCTAssertNotEqual
        •   yoda_condition: Yoda condition rule    变量应位于比较运算符的左侧,常数应位于右侧
    
    

    相关文章

      网友评论

          本文标题:SwiftLint 技术分享

          本文链接:https://www.haomeiwen.com/subject/ohabwrtx.html