当.swiftlint.yml文件与project.xcodeproj不在同一文件夹中时,如何使用swiftlint命令和Xcode脚本?

时间:2019-03-07 02:59:26

标签: xcode swiftlint

我使用SwiftLint来控制项目的代码样式,它几乎一直都能正常工作。但是我遇到了一个麻烦:当.swiftlint.yml文件与项目文件'.xcodeproj'不在同一文件夹中时,如果我使用命令swiftlint autocorrect或使用Xcode build来使用SwiftLint每次都需要更改.swiftlint.yml。下面是详细信息:

  1. 我的项目结构如下:
> SampleProject
>     ├── .swiftlint.yml
>     ├── SampleProject
>     │   ├── Frameworks
>     │   ├── Info.plist
>     │   ├── SampleProject
>     │   ├── SampleProject.xcodeproj
>     │   └── SampleProjectTests
>     ├── SampleProject.xcworkspace
>     ├── Configuration
>     ├── CommonFoundation
>     │   ├── CommonFoundation
>     │   ├── CommonFoundation.xcodeproj
>     │   └── CommonFoundationTests
>     ├── Gemfile
>     ├── Gemfile.lock
>     ├── Podfile
>     ├── Podfile.lock
>     ├── Pods
>     ├── README.md
>     ├── fastlane
>     └── release.sh

根路径中的.swiftlint.yml,但子文件夹中的SampleProject.xcodeproj

  1. 我已经通过brew install swiftlint安装了SwiftLint;
  2. 我在项目SwiftLint Script的Xcode中用以下代码添加了SampleProject.xcodeproj

    if which swiftlint >/dev/null; then
    swiftlint --config ../.swiftlint.yml
    else
    echo "warning: SwiftLint not installed, 'brew install swiftlint' or download from https://github.com/realm/SwiftLint"
    fi
    

enter image description here

  1. .swiftlint.yml代码如下:

          disabled_rules: # rule identifiers to exclude from running
            - colon
            - comma
            - control_statement
            - line_length
            - type_body_length
            - function_body_length
            - cyclomatic_complexity
          opt_in_rules: # some rules are only opt-in
            - empty_count
          included: # paths to include during linting. `--path` is ignored if present.
              - ./SampleProject/Manager/Configs.swift
    
          excluded: # paths to ignore during linting. Takes precedence over `included`.
            - Carthage
            - Pods
          analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
            - explicit_self
    
          force_cast: warning # implicitly
          force_try:
            severity: warning # explicitly
          type_body_length:
            - 300 # warning
            - 400 # error
          # or they can set both explicitly
          file_length:
            warning: 1000
            error: 1500
          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
              - i
              - j
              - id
              - GlobalAPIKey
          reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
    
  2. 当我使用带有SwiftLint和文件SampleProject/SampleProject/Manager/Configs.swift的Xcode构建项目时,需要更新included中的.swiftlint.yml项目,如下所示:

      included: # paths to include during linting. `--path` is ignored if present.
          - ./SampleProject/Manager/Configs.swift
    
  3. 当我使用文件SampleProject/SampleProject/Manager/Configs.swift对SwiftLint运行命令'swiftlint autocorrect'时,我需要更新included中的.swiftlint.yml项目,如下所示:

      included: # paths to include during linting. `--path` is ignored if present.
          - SampleProject/SampleProject/Manager/Configs.swift
    

我想找到一种解决方法,那就是不要更改.swiftlint.yml文件,但命令'swiftlint autocorrect'和Xcode构建可以在SwiftLint上正常工作。

0 个答案:

没有答案