Invisible Character

Disallows invisible characters like zero-width space (U+200B), zero-width non-joiner (U+200C), and FEFF formatting character (U+FEFF) in string literals as they can cause hard-to-debug issues.

  • Identifier: invisible_character
  • Enabled by default: Yes
  • Supports autocorrection: Yes
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity error
    additional_code_points [“200B”, “200C”, “FEFF”]

Non Triggering Examples

let s = "HelloWorld"
let s = "Hello World"
let url = "https://example.com/api"
let s = #"Hello World"#
let multiline = """
Hello
World
"""
let empty = ""
let tab = "Hello\tWorld"
let newline = "Hello\nWorld"
let unicode = "Hello 👋 World"

Triggering Examples

let s = "Hello↓​World" // U+200B zero-width space
let s = "Hello↓‌World" // U+200C zero-width non-joiner
let s = "Hello↓World" // U+FEFF formatting character
let url = "https://example↓​.com" // U+200B in URL
// U+200B in multiline string
let multiline = """
Hello↓​World
"""
let s = "Test↓​String↓Here" // Multiple invisible characters
let s = "Hel↓‌lo" + "World" // string concatenation with U+200C
let s = "Hel↓‌lo \(name)" // U+200C in interpolated string
//
// additional_code_points: ["AD", "200B", "200C", "FEFF"]
//

//
// additional_code_points: ["00AD"]
//
let s = "Hello↓­World"

//
// additional_code_points: ["200B", "200C", "200D", "FEFF"]
//

//
// additional_code_points: ["200D"]
//
let s = "Hello↓‍World"