【问题标题】:iOS SwiftLint Identifier Name doesn't workiOS SwiftLint 标识符名称不起作用
【发布时间】:2021-10-27 19:41:58
【问题描述】:

https://realm.github.io/SwiftLint/identifier_name.html

你好。 我最近遇到了 swiftlint 并学到了这一点。但是有一个问题。我修改了 swiftlint 的 Identifier Name 来维护 CalmelCase 语法,但是没有用。

这是我的 .swiftlint.yml 文本。

identifier_name:
    allowed_symbols: ["_"]
    validates_start_with_lowercase: false
    min_length:
        warning: 1

disabled_rules: # rule identifiers to exclude from running
    - 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.
    - Source

excluded: # paths to ignore during linting. Takes precedence over `included`.
    - Carthage
    - Pods
    - Source/ExcludedFolder
    - Source/ExcludedFile.swift

enter image description here

import UIKit

class timeVC: UIViewController {

    @IBOutlet weak var timePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func clickDone(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
}

enter image description here

无论“validates_start_with_lowercase”是真还是假,都会出现错误。 我犯了什么错误?

【问题讨论】:

  • 请不要有代码图片。

标签: ios swift xcode swiftlint


【解决方案1】:

您已更改标识符的规则,但触发的规则是针对 type names

类型名称应以大写字母开头。

将您的班级名称更改为TimeVC

import UIKit

class TimeVC: UIViewController {

    @IBOutlet weak var timePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func clickDone(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
}

您也不应该更改identifier_name 规则。如果您要违反 Swift 风格的这样一个基本元素,那么即使使用 linter 也可能没有多大意义。

【讨论】:

  • 哦!我认为“identifier_name”负责一切。 “类型名称”的选项是我想要的。非常感谢您的回答。
  • 好的,但是不要改变它!
  • 是的。我明白你的意思。谢谢。
猜你喜欢
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 2014-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-06
  • 2021-11-22
相关资源
最近更新 更多