首页 文章

正则表达式为SwiftLint自定义规则不匹配

提问于
浏览
0

我创建了正则表达式来确定一个类后面是否有一个空行 . 在xcode中搜索时,这非常有效 . 但是,swiftlint似乎不能正常工作 .

规则是:

custom_rules:
  space_after_class:
    name: "No Space After Class"
    message: "Empty line required after class declarations"
    regex: '(^(open|internal|private|public)*class\s(?!func).*\{$\n(?!^\s*$))'
    severity: error

在xcode / sublime / whatever中搜索时这很好用,但由于某种原因,在swiftlint中返回所有类声明(即使是那些带有新行的声明)

搜索示例:
enter image description here

规则示例(注意空白行 - 使用ctrl f找不到相同的正则表达式):
enter image description here

导致这种情况的swiftlint正则表达式有何不同?

1 回答

  • 0

    您的yml文件需要正确格式化 . 尝试在线使用任何yaml验证器进行验证 . 似乎你的正则表达式需要引号“而不是` .

相关问题