Skip to content

Rule Request: invisible_characters #6045

@kapitoshka438

Description

@kapitoshka438

New Issue Checklist

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: error

I 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 = "Hello​World" // 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions