Search code examples
iosswiftxcodeswiftlint

iOS SwiftLint Identifier Name doesn't work


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

Hello. I recently encountered swiftlint and learned this. But there's a problem. I modified the Identifier Name of swiftlint to maintain the CalmelCase grammar, but it didn't work.

this is my .swiftlint.yml text.

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

An error is still occurring whether 'validates_start_with_lowercase' is true or false. What kind of mistake did I make?


Solution

  • You have changed the rules for identifiers but the rule that is triggering is for type names.

    Type names should start with an uppercase letter.

    Change your class name to 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)
        }
    }
    

    You shouldn't change the identifier_name rules either. If you are going to violate such a basic element of Swift style there probably isn't much point in even using the linter.