IllegalSymbol
Since Checkstyle 13.1.0
Description
Checks that specified symbols (by Unicode code points or ranges) are not used in code.
Rationale: This check helps prevent emoji symbols in code, enforce ASCII-only source files, or forbid specific Unicode characters.
Properties
| name | description | type | default value | since |
|---|---|---|---|---|
| asciiOnly | Control whether only ASCII characters are allowed. | boolean | false |
13.1.0 |
| symbolCodes | Specify the symbols to check for. Format: comma-separated list of hex codes or ranges (e.g., "0x2705, 0xd83c-0xd83e"). | String | |
13.1.0 |
| tokens | tokens to check | subset of tokens COMMENT_CONTENT , STRING_LITERAL , CHAR_LITERAL , TEXT_BLOCK_CONTENT , IDENT . | COMMENT_CONTENT . | 13.1.0 |
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="IllegalSymbol"/>
</module>
</module>
Example:
public class Example1 {
// ✅ Enhancement completed
// 😀 Happy coding
int value = 1;
}
To configure the check to forbid emoji ranges:
<module name="Checker">
<module name="TreeWalker">
<module name="IllegalSymbol">
<property name="symbolCodes" value="0x1F300-0x1F5FF, 0x1F680-0x1F6FF"/>
</module>
</module>
</module>
Example:
public class Example2 {
int x = 1;
// 🌟 Star // violation 'Illegal Unicode symbol detected'
int star = 3;
// 🚀 Rocket // violation 'Illegal Unicode symbol detected'
int fast = 3;
}
To configure the check for ASCII-only mode:
<module name="Checker">
<module name="TreeWalker">
<module name="IllegalSymbol">
<property name="asciiOnly" value="true"/>
</module>
</module>
</module>
Example:
public class Example3 {
// Regular ASCII comment
int x = 1;
// café // violation 'Illegal Unicode symbol detected'
int coffee = 2;
// • bullet point // violation 'Illegal Unicode symbol detected'
int item = 3;
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.coding






