【问题标题】:Mandatory empty line after function definition SwiftLintSwiftLint 函数定义后的强制空行
【发布时间】:2021-07-14 17:19:58
【问题描述】:

我正在我的 xcode 项目中集成 swiftlint 并设置它的配置。但我无法获得在函数定义后强制空行的规则

func test1() {
}
func test2() {
}

如果我在两个函数之间添加多个空格,则有一个规则。

是否有任何规则可用于在两个函数之间启用空行或者我需要编写自定义一个

【问题讨论】:

    标签: swift swiftlint


    【解决方案1】:

    执行 swiftlint 规则将为您提供可用规则列表。为了找到适用的规则,我通常会做的是更改 yaml 文件中的不同规则,直到找到符合我要求的规则。

    如果您的规则不存在,我建议使用正则表达式编写自定义规则,例如:

     custom_rules:
      pirates_beat_ninjas: # rule identifier
        included: ".*\\.swift" # regex that defines paths to include during linting. optional.
        excluded: ".*Test\\.swift" # regex that defines paths to exclude during linting. optional
        name: "Pirates Beat Ninjas" # rule name. optional.
        regex: "([nN]inja)" # matching pattern
        capture_group: 0 # number of regex capture group to highlight the rule violation at. optional.
        match_kinds: # SyntaxKinds to match. optional.
          - comment
          - identifier
        message: "Pirates are better than ninjas." # violation message. optional.
        severity: error # violation severity. optional.
      no_hiding_in_strings:
        regex: "([nN]inja)"
        match_kinds: string
    

    这条规则使得每次你看到忍者这个词都会导致违规

    【讨论】:

      猜你喜欢
      • 2013-09-25
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多