Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"Variable Name" rules don't handle multibyte characters #279

Closed
Sega-Zero opened this issue Dec 19, 2015 · 6 comments
Closed

"Variable Name" rules don't handle multibyte characters #279

Sega-Zero opened this issue Dec 19, 2015 · 6 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@Sega-Zero
Copy link
Contributor

Having a warning:

warning: Variable Name Min Length Rule Violation: Variable name should be 3 characters or more: currently 2 characters (variable_name_min_length)

The warning appears on several lines of code in my swift file, but I was able to reproduce this warning only on one code sample in a separate swift file:

protocol SampleProtocol {
    func longMethodNameWithCompletion(completion: () -> Void)
    func longMethodNameWithCompletionAndId(id: Int, completion: () -> Void)
    func longMethodNameWithParameters(param1: Int, param2: Int, strParam: String, completion: () -> Void)
    func yetAnotherMethodNameWithSomeParameters(fromTime: NSDate, toTime: NSDate, accountKey: AccountKey, completion: () -> Void)
}

The warning is on the longMethodNameWithParameters line.

.swiftlint.yml:

disabled_rules: 
  - line_length
  - trailing_newline

The file contains only structs and protocols with markdown comments. Removing line_length form .swiftlint.ymldoesn't help.
Any thoughts?

@jpsim
Copy link
Collaborator

jpsim commented Dec 24, 2015

The variable_name_min_length rule considers function parameters as variables, and you have one named id, which violates the rule. So this is behaving as expected.

@jpsim jpsim closed this as completed Dec 24, 2015
@Sega-Zero
Copy link
Contributor Author

Then why the warning points to the next function?
wrong warning line

@norio-nomura
Copy link
Collaborator

Potentially there is multi byte character issue in most of rules.

@jpsim
Copy link
Collaborator

jpsim commented Dec 24, 2015

When I copy the text from your sample above, and run SwiftLint on it, the violation occurs on line 3, character 44, which is correct:

$ pbpaste | swiftlint lint --use-stdin
<nopath>:6: warning: Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
<nopath>:4: warning: Line Length Violation: Line should be 100 characters or less: currently 105 characters (line_length)
<nopath>:5: warning: Line Length Violation: Line should be 100 characters or less: currently 129 characters (line_length)
<nopath>:3:44: warning: Variable Name Min Length Rule Violation: Variable name should be 3 characters or more: currently 2 characters (variable_name_min_length)
Done linting! Found 4 violations, 0 serious in 1 file.

So I suspect that @norio-nomura is right, as always 😉, that there are some multibyte characters in your file that you have not shared with us. Could you please share a complete reproducible sample with us so we can repro and fix this? Thanks!

@jpsim jpsim reopened this Dec 24, 2015
@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Dec 24, 2015
@Sega-Zero
Copy link
Contributor Author

//
//  Experiments.swift
//  Project
//
//  Created by Сергей Галездинов on 17.12.15.
//  Copyright © 2015 Сергей Галездинов. All rights reserved.
//

import Foundation
import UIKit

protocol SampleProtocol {
    func longMethodNameWithCompletion(completion: () -> Void)
    func longMethodNameWithCompletionAndId(id: Int, completion: () -> Void)
    func longMethodNameWithParameters(param1: Int, param2: Int, strParam: String, completion: () -> Void)
    func yetAnotherMethodNameWithSomeParameters(fromTime: NSDate, toTime: NSDate, accountKey: AccountKey, completion: () -> Void)
}

The file contains russian symbols

@jpsim
Copy link
Collaborator

jpsim commented Dec 24, 2015

From what I can tell, it seems like Location.init(file:offset:) uses NSString.lineAndCharacterForCharacterOffset(_:) although the offset it's getting for the variable name family of rules is a byte offset, not a character offset.

@jpsim jpsim changed the title Weird variable_name_min_length warning "Variable Name" rules don't handle multibyte characters Dec 24, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

3 participants