Skip to content

Missing violations on Unicode and Octal values of \s #17551

@mohitsatr

Description

@mohitsatr

https://google.github.io/styleguide/javaguide.html#s2.3.2-special-escape-sequences

2.3.2 Special escape sequences
For any character that has a special escape sequence (\b, \t, \n, \f, \r, \s, ", ' and \), that sequence is used rather than the corresponding octal (e.g. \012) or Unicode (e.g. \u000a) escape.

I have read check documentation: https://checkstyle.org/checks/coding/illegaltokentext.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

Code:

$ cat EscapedCodes.java
class EscapedCodes {
  public void unicode() {
    final String r0 = "\s";
    final String r1 = "\u000b"; // Expected violation
    final String r2 = "\u000c"; // OK 
    final String r3 = "\u001c";  // Expected violation
    final String r4 = "\u001D"; // Expected violation
    final String r5 = "\u001E";  // Expected violation
    final String r6 = "\u001F"; // Expected violation 
    final String r7 = "\u1680"; // Expected violation 
    final String r8 = "\u2000"; // Expected violation 
    final String r9 = "\u200A"; // Expected violation 
    final String r10 = "\u2028"; // Expected violation 
    final String r12 = "\u2029"; // Expected violation 
    final String r13 = "\u202F"; // Expected violation 
    final String r14 = "\u205F"; // Expected violation 
    final String r15 = "\u3000"; // Expected violation 
  }

  public void octal() {
    final String r1 = "\040"; // Expected violation
    final String r2 = "\011"; // ok
    final String r3 = "\012"; // ok
  }
}

Cli:

$ java -jar checkstyle-10.26.1-all.jar -c google_checks.xml EscapedCodes.java 
Starting audit...
[WARN] /mnt/5D92528E6B945467/test/testing/EscapedCodes.java:5:23: Consider using special escape sequence instead of octal value or Unicode escaped value. [IllegalTokenText]
[WARN] /mnt/5D92528E6B945467/test/testing/EscapedCodes.java:22:23: Consider using special escape sequence instead of octal value or Unicode escaped value. [IllegalTokenText]
[WARN] /mnt/5D92528E6B945467/test/testing/EscapedCodes.java:23:23: Consider using special escape sequence instead of octal value or Unicode escaped value. [IllegalTokenText]
Audit done.

https://en.wikipedia.org/wiki/Whitespace_character

For example, a space character (U+0020 SPACE, ASCII 32) represents blank space such as a word divider in a Western script.

The 040 part is the octal (base-8) representation of the ASCII code for the space character, which is decimal 32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions