美文网首页
SwiftLint 使用

SwiftLint 使用

作者: 云涌海啸 | 来源:发表于2020-03-27 17:22 被阅读0次

    SwiftLint:源码

    安装配置

    使用 Homebrew 安装

    brew install swiftlint
    

    使用 CocoaPods 安装

    pod 'SwiftLint'
    

    使用安装包

    SwiftLint 还支持使用 pkg 安装包进行安装,在官方的 Github 页面可以找到最新发布的安装包

    编译源代码

    SwiftLint 完全使用 Swift 开发,并且它是基于 MIT License 开源的,所以你可以下载它的源代码,然后通过以下命令编译安装:

    git submodule update --init --recursive; make install
    

    安装完成

    ➜  ~ swiftlint help
    Available commands:
    
       autocorrect   Automatically correct warnings and errors
       help          Display general or command-specific help
       lint          Print lint warnings and errors (default command)
       rules         Display the list of rules and their identifiers
       version       Display the current version of SwiftLint
    

    自定义配置

    disabled_rules: # rule identifiers to exclude from running
      - force_cast
      - trailing_whitespace
      - cyclomatic_complexity
      - unused_closure_parameter
    #   - colon
    #   - comma
    #   - control_statement
    # opt_in_rules: # some rules are only opt-in
    #   - empty_count
    #   - missing_docs
    #   # Find all the available rules by running:
    #   # swiftlint rules
    # included: # paths to include during linting. `--path` is ignored if present.
    #   - Docs.M/*/*.swift
    excluded: # paths to ignore during linting. Takes precedence over `included`.
      - Carthage
      - Pods
      # - Source/ExcludedFolder
      # - Source/ExcludedFile.swift
    
    # configurable rules can be customized from this configuration file
    # binary rules can set their severity level
    # force_cast: warning # implicitly
    force_try:
      severity: warning # explicitly
    # rules that have both warning and error levels, can set just the warning level
    # implicitly
    line_length:
      warning: 200
      ignores_function_declarations: true
      ignores_comments: true
    
    # they can set both implicitly with an array
    type_body_length:
      - 300 # warning
      - 400 # error
    # or they can set both explicitly
    file_length:
      warning: 500
      error: 1200
    # naming rules can set warnings/errors for min_length and max_length
    # additionally they can set excluded names
    # type_name:
    #   min_length: 4 # only warning
    #   max_length: # warning and error
    #     warning: 40
    #     error: 50
    #   excluded: iPhone # excluded via string
    identifier_name:
      min_length: # only min_length
        error: 3 # only error
      excluded: # excluded via string array
        - id
    #     - URL
    #     - GlobalAPIKey
    reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)
    

    相关文章

      网友评论

          本文标题:SwiftLint 使用

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