-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
Labels
rule-requestRequests for a new rules.Requests for a new rules.
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New Rule Request
We recently faced an issue when some string literals (URLs) were containing a zero-width whitespace (\u200B). The URLs were copypasted from a Confluence document, and the URLs in Confluence, in turn, were copypasted from Swagger specification. This resulted in network request errors in our application. We had to add a custom rule to avoid such situations:
no_zero_width_spaces:
name: "No Zero Width Spaces"
regex: '\u200B'
message: "Avoid using zero width space characters (U+200B) in your code."
severity: errorI don't know what other invisible characters exist, but application bugs in such situations are hard to track down.
I think it would be useful to add a default rule that would disallow some characters, at least in string literals, and perhaps in all code.
I know at least 3 characters that are not displayed:
- Zero-width space: \u200B
- NULL control character: \u0000
- FEFF Formatting character: \uFEFF
Triggering Examples
let s = "HelloWorld" // This is a string with a \u200B character between Hello and World
// \u0048\u0065\u006c\u006c\u006f\u200b\u0057\u006f\u0072\u006c\u0064
let s = "HelloWorld" // This is a string with a \ufeff character between Hello and World
// \u0048\u0065\u006c\u006c\u006f\ufeff\u0057\u006f\u0072\u006c\u0064
Non-triggering examples
let s = "HelloWorld" // This is a string without invisible characters
// \u0048\u0065\u006c\u006c\u006f\u0057\u006f\u0072\u006c\u0064
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
rule-requestRequests for a new rules.Requests for a new rules.