IllegalSymbol

Since Checkstyle 13.4.0

Description

Checks that specified symbols (by Unicode code points or ranges) are not used in code. By default, blocks common symbol ranges.

Rationale: This check helps prevent emoji symbols and special characters in code (commonly added by AI tools), enforce coding standards, or forbid specific Unicode characters.

Default ranges cover:

  • U+2190–U+27BF: Arrows, Mathematical Operators, Box Drawing, Geometric Shapes, Miscellaneous Symbols, and Dingbats
  • U+1F600–U+1F64F: Emoticons
  • U+1F680–U+1F6FF: Transport and Map Symbols
  • U+1F700–U+10FFFF: Alchemical Symbols and other pictographic symbols

For a complete list of Unicode characters and ranges, see: List of Unicode characters

  • Property symbolCodes - Specify the symbols to check for, as Unicode code points or ranges. Format: comma-separated list of hex codes or ranges (e.g., "0x2705, 0x1F600-0x1F64F"). To allow only ASCII characters, use "0x0080-0x10FFFF". Type is java.lang.String. Default value is "0x2190-0x27BF, 0x1F600-0x1F64F, 0x1F680-0x1F6FF, 0x1F700-0x10FFFF".

Properties

name description type default value since
symbolCodes Specify the symbols to check for. String 0x2190-0x27BF, 0x1F600-0x1F64F, 0x1F680-0x1F6FF, 0x1F700-0x10FFFF 13.4.0
tokens tokens to check subset of tokens COMMENT_CONTENT , STRING_LITERAL , CHAR_LITERAL , TEXT_BLOCK_CONTENT , IDENT . COMMENT_CONTENT . 13.4.0

Examples

To configure the check:


<module name="Checker">
  <module name="TreeWalker">
    <module name="IllegalSymbol"/>
  </module>
</module>

Example:


public class Example1 {
  // ✅ Enhancement completed // violation 'Illegal symbol detected: '✅''
  // 😀 Happy coding // violation 'Illegal symbol detected: '😀''
  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 {
  // 🌟 Star // violation 'Illegal symbol detected: '🌟''
  int value = 1;
}

To configure the check for ASCII-only mode:


<module name="Checker">
  <module name="TreeWalker">
    <module name="IllegalSymbol">
      <property name="symbolCodes" value="0x0080-0x10FFFF"/>
    </module>
  </module>
</module>

Example:


public class Example3 {
  // café // violation 'Illegal symbol detected: 'é''
  int value = 1;
}

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.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.coding.IllegalSymbolCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker