iOS SwiftLint 标识符名称不起作用。

3

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

你好。我最近遇到了SwiftLint,并学习了相关知识。但是有一个问题。我修改了SwiftLint的标识符名称以保持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

在此输入图片描述

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)
    }
}

在此输入图像描述

无论 'validates_start_with_lowercase' 是 true 还是 false,仍然出现错误。 我犯了什么错误?


1
please no images of code. - Someone_who_likes_SE
1个回答

1
你已经更改了标识符的规则,但触发的规则是类型名称的规则。
类型名称应以大写字母开头。
将你的类名更改为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' 负责一切。 'type name' 的选项正是我想要的。 非常感谢您的回答。 - dortus47
1
好的,但是不要改变它! - Paulw11
是的,我明白你的意思。 谢谢。 - dortus47

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接