首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SwiftLint不识别对.swiftlint.yml的更改

SwiftLint不识别对.swiftlint.yml的更改
EN

Stack Overflow用户
提问于 2016-12-29 11:28:38
回答 1查看 6.7K关注 0票数 2

我在Xcode中的自定义构建阶段使用SwiftLint:

代码语言:javascript
复制
if which swiftlint >/dev/null; then
    swiftlint autocorrect --format
    swiftlint
else
    echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

Xcode自我创建项目文件夹以来,在过去一个月中肯定已经识别了项目文件夹中的.swiftlint.yml,因为它警告了我添加的自定义规则。现在,我已经从yml文件中删除了两个自定义规则,但是Xcode继续警告我。

我尝试了以下几种方法,但没有线索可以尝试:

  • 卸载和安装Swiftlint (使用国产)
  • 将删除的规则名称添加到disabled_rules中的.swiftlint.yml中
  • 删除.swiftlint.yml并再次添加它

我能找到的唯一解决办法是在每个文件中添加一行// swiftlint:disable <rule1> <rule2> <rule3>,但这不能被认为是一个真正的解决方案,所以现在我在Xcode构建阶段注释掉了迅捷。任何建议都非常感谢..。

编辑: swiftlint.yml内容

代码语言:javascript
复制
disabled_rules: # rule identifiers to exclude from running
  - colon # exaclty one space after the : >>> let abc: Void\n
  - todo # TODO can be written in the code but should be linked to a ticket on JIRA.
  - nesting # func nesting max 1 level
  - weak_delegate
  - empty_parentheses_with_trailing_closure
  - empty_commented_line
  - missing_brackets_unwrap

excluded: # paths to ignore during linting. overridden by `included`.
  - Carthage
  - Pods
  - External
  - Submodules

# rule parameters
cyclomatic_complexity:
  - 20 #warning
  - 35 #error

file_length:
  - 600 #warning
  - 800 #error

function_body_length:
  - 40 #warning
  - 80 #error

line_length:
  - 300 #warning
  - 350 #error

type_body_length:
  - 400 #warning
  - 500 #error

variable_name:
  min_length: 2 #warning
  max_length: #warning or error
    warning: 40
    error: 50

opt_in_rules:
 # - missing_docs
  - force_unwrapping
  - control_statement
  - private_outlet
  - vertical_whitespace

custom_rules:
  extra_whitespace:
    name: "Extra whitespaces"
    regex: "([a-zA-Z0-9=?.\(\),><!'\"][ ]{2,}[a-zA-Z0-9?.\(\),><!'\"])"
    message: "Remove extra whitespaces"
    severity: warning
  comments_space:
    name: "Space After Comment"
    regex: "(^ *//\w+)"
    message: "There should be a space after //"
    severity: warning
  empty_first_line:
    name: "Empty First Line"
    regex: "(^[ a-zA-Z ]*(?:protocol|extension|class|struct) (?!(?:var|let))[ a-zA-Z:]*\{\n *\S+)"
    message: "There should be an empty line after a declaration"
    severity: warning
  empty_line_after_guard:
    name: "Empty Line After Guard"
    regex: "(^ *guard[ a-zA-Z0-9=?.\(\),><!]*\{[ a-zA-Z0-9=?.\(\),><!]*\}\n *(?!(?:return|guard))\S+)"
    message: "There should be an empty line after a guard"
    severity: warning
  empty_line_after_super:
    name: "Empty Line After Super"
    regex: "(^ *super\.[ a-zA-Z0-9=?.\(\)\{\}:,><!]*\n *(?!(?:\}|return))\S+)"
    message: "There should be an empty line after super"
    severity: warning
  multiple_empty_lines:
    name: "Multiple Empty Lines"
    regex: "((?:\s*\n){3,})"
    message: "There are too many empty lines"
    severity: warning
  unnecessary_leading_void_in:
    name: "Unnecessary -> Void in at the end of the line"
    regex: "(-> (Void|\(\)) in$)"
    message: "Unnecessary '-> Void in' at the end of the line. Use only 'in'"
    severity: warning
  unnecessary_type:
    name: "Unnecessary Type"
    regex: "(?sm)[ \ta-zA-Z0-9]?(?:let|var){1} [ \ta-zA-Z0-9]+?:[ \t]+?([a-zA-Z0-9]+?)[\t ]+?=[\t ]?\1"
    message: "Type Definition Not Needed"
    severity: warning
  empty_closure_params:
    name: "Empty closure params"
    regex: "\{ (\(\) -> Void in)$"
    message: "`() -> Void in` should be avoided"
    severity: warning
  invalid_mark_format:
    name: "Invalid MARK Format"
    regex: "(?m-s)(\/\/[\s]*?MARK(?!(\:[\s]{1}\-[\s]{1}){1}))"
    message: "Use format: MARK: - Your Info"
    severity: warning
EN

回答 1

Stack Overflow用户

发布于 2017-09-01 09:50:46

检查您的.swiftlint.yml文件路径。应该将其添加到项目的根目录中。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41378805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档