realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.67k stars 2.22k forks source link

Operator Usage Whitespace Violation with Range Operator "..." #2344

Closed nicolas-miari closed 6 years ago

nicolas-miari commented 6 years ago

New Issue Checklist

Bug Report

I can't get rid of this warning after migrating to Swift4 and adopting rrange operators for substrings (slices).

Complete output when running SwiftLint, including the stack trace and command used

(Can't paste complete output; source file names are confidential)

warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)

Environment

# Swift 4.1, SwiftLint 0.25.1
reporter: xcode
opt_in_rules:
  - force_unwrapping
  - vertical_whitespace
  - closure_end_indentation
  - closure_spacing
  - explicit_init
  - first_where
  - nimble_operator
  - number_separator
  - object_literal
  - operator_usage_whitespace
  - overridden_super_call
  - prohibited_super_call
  - redundant_nil_coalescing
disabled_rules:
  - xctfail_message
  - trailing_whitespace
  - cyclomatic_complexity
  - todo
excluded:
  - Carthage
  - Pods
  - vendor
  - FRCircleTests
cyclomatic_complexity:
  warning: 17
line_length: 200
file_length: 900
force_unwrapping: error
function_parameter_count:
  - 6
  - 8
function_body_length:
  - 80
  - 100
type_body_length:
  - 400
  - 500
type_name:
  min_length:
    warning: 2
  max_length:
    warning: 40
    error: 60
identifier_name:
  min_length:
    warning: 1
  max_length:
    warning: 40
    error: 60
identifier_name:
  min_length:
    warning: 1
  max_length:
    warning: 40
    error: 60
custom_rules:
  disable:
    name: "Disable Rule In Code"
    regex: "(swiftlint:disable)"
    message: "Please do not disable rule in code. "
    severity: error
    match_kinds: comment
  outlet_collection:
    name: "outlet_collection"
    regex: "(@IBOutletCollection)"
    message: "IBOutletCollection is not permitted. "
    severity: error
  comments_space:
    name: "Add Space After Comment"
    regex: "(^\\s*//\\w+)"
    message: "There should be a space after //"
    severity: warning
    match_kinds: comment
let length = text.length
let startIndex = text.index(text.startIndex, offsetBy: length - 1)

// This does NOT trigger a violation:
let first = String(text[..<startIndex]) 
// Was: text.substring(to: startIndex) in Swift3

// This triggers a violation:
let last =  String(text[startIndex...])  
// Was: text.substring(from: startIndex) in Swift3
nicolas-miari commented 6 years ago

(Of course, adding space around ... triggers a Swift syntax error)

marcelofabri commented 6 years ago

@nicolas-miari are you sure the violation is not because of the extra space between = and String?

marcelofabri commented 6 years ago

Changed here to let last = String(text[startIndex...]) and the violation went away. I'm closing this, but feel free to reopen if you have any other questions.