avoid-unicode-escape
What it does
Section titled “What it does”Reports a string or character literal that writes a visible character as a \uXXXX escape when the line has no trailing comment. Escapes of control, space and format characters are not reported.
Why it matters
Section titled “Why it matters”The escape hides the character: the reader has to decode é to know it is an é, and cannot see a typo in the code. The source file is UTF-8, so the character itself is safe. An escape stays useful when a comment explains it, which is why a comment on the line allows it.
To fix, write the character itself, or add a trailing comment that says what it is.
Example
Section titled “Example”class A { String a = "\u00e9"; String b = "\u00e9"; // c with acute String c = "\u0009\u200b"; char d = '\u2603'; String e = "plain";}Configuration
Section titled “Configuration”java: lint: rules: avoid-unicode-escape: warn # off (default), warn, errorEnabled by the presets: java/google.
Suppress one line with sudsy-disable-next-line avoid-unicode-escape in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| checkstyle | AvoidEscapedUnicodeCharacters |
partial | Printable-escape rule with control characters and tail comments allowed; no options. |