Skip to content

Files

Latest commit

 

History

History
47 lines (32 loc) · 1.36 KB

IllegalTokenText.md

File metadata and controls

47 lines (32 loc) · 1.36 KB

Pattern: Illegal token text

Issue: -

Description

Checks specified tokens text for matching an illegal pattern from format property.

By default Google Java Style Guide is applied: For any character that has a special escape sequence, that sequence should be used rather than the corresponding octal (e.g. \012) or Unicode (e.g. \u000a) escape.

Default configuration

<module name="IllegalTokenText">
    <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
    <property name="format" value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
    <property name="message" value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>

Examples

Example of incorrect code:

string newLine = "\015\012";

Example of correct code:

string newLine = "\r\n";

To configure the check to forbid String literals containing "a href":

<module name="IllegalTokenText">
    <property name="tokens" value="STRING_LITERAL"/>
    <property name="format" value="a href"/>
</module>

Further Reading