我如何创建.swiftlint.yml文件&我需要把它放在哪里?

时间:2017-03-30 05:54:32

标签: swiftlint

我想在我的Swift项目中使用Swiftlint。 我按照Realm指令并按.swiftlint.yml安装了Swiftlint。我还要面对创建{{1}}文件的问题。

那么请建议我如何进行?

5 个答案:

答案 0 :(得分:14)

如果您使用的是终端:

    cd your_project_directory
    touch .swiftlint.yml

答案 1 :(得分:7)

我发现此视频很有帮助: https://www.youtube.com/watch?v=3MAlqOVIAwI

您可以在XCode中创建.swiftlint.yml并将其保存在项目目录中。只需选择文件 - >新 - >档案 - >空

答案 2 :(得分:4)

我通过cocoapods安装swift lint,然后在根项目目录中添加名为.swiftlint.yml的新文件。有关更多详细信息,请访问youtube链接 我发现此视频很有用:https://www.youtube.com/watch?v=cEA9BDVbjfIhttps://www.youtube.com/watch?v=3MAlqOVIAwI

答案 3 :(得分:2)

在您的项目主目录中创建此文件,名称应为.swiftlint.yml

文件示例

disabled_rules: # rule identifiers to exclude from running
  - colon
  - comma
  - control_statement
  - identifier_name #rule for checking variable conditions (Upper case , lower case , underscore )
  - force_cast
  - shorthand_operator

cyclomatic_complexity:
  warning: 25 # two nested ifs are acceptable
  error: 50   # six nested ifs shows warning, 6 causes compile error


opt_in_rules: # some rules are only opt-in
  # - empty_count
  # Find all the available rules by running:
  # swiftlint rules

#included: # paths to include during linting. `--path` is ignored if present.
#  - Source

excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
  - AppFolder\ App/Class/*
 # - AppFolder\ App/ViewController/* //Enabled for this

analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
  - explicit_self

# configurable rules can be customised 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: 200
# they can set both implicitly with an array

type_body_length:
  - 300 # warning
  - 600 # error
# or they can set both explicitly

file_length:
  warning: 500
  error: 2500

function_body_length:
  - 200 #warning
  - 300 #error

# 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
  allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
  min_length: # only min_length
    error: 4 # only error
  excluded: # excluded via string array
    - id
    - URL
    - GlobalAPIKey

identifier_name:
#  allowed_symbols: "_"
  max_length:
    warning: 45
    error: 60
  min_length:
    warning: 1


reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)

答案 4 :(得分:-2)

我建议你阅读documentation

  

通过从您运行SwiftLint的目录中添加.swiftlint.yml文件来配置SwiftLint。

我建议你的项目或源根。

随后是一个广泛的示例文件;从那里开始。

至于可用的规则和默认值,除了运行

之外似乎没有好的文档
  

swiftlint规则> swiftlint_rules.txt

并且屏幕非常宽。

相关问题