Skip to content

IllegalTokenText support for STRING_TEMPLATE_CONTENT #14289

@nrmancuso

Description

@nrmancuso

I have read check documentation: https://checkstyle.sourceforge.io/checks/coding/illegaltokentext.html#IllegalTokenText
I have built the latest checkstyle from https://github.com/checkstyle/checkstyle/pull/13991/files
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

➜  src cat Test.java
public class Test {
    void m0() {
        String s = STR."x"; // expected violation
    }

    void m1() {
        String s = "x"; // actual violation
    }
}

➜  src cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
    "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="IllegalTokenText">
      <property name="format" value="x"/>
    </module>
  </module>
</module>

➜  src java -jar checkstyle-10.12.8-SNAPSHOT-all.jar -c config.xml Test.java
Exception in thread "main" java.lang.IllegalArgumentException: unknown TokenTypes value 'STRING_TEMPLATE_CONTENT'
        at com.puppycrawl.tools.checkstyle.utils.TokenUtil.getTokenId(TokenUtil.java:162)
        at com.puppycrawl.tools.checkstyle.TreeWalker.registerCheck(TreeWalker.java:215)
        at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:133)
        at com.puppycrawl.tools.checkstyle.AbstractAutomaticBean.configure(AbstractAutomaticBean.java:207)
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:481)
        at com.puppycrawl.tools.checkstyle.AbstractAutomaticBean.configure(AbstractAutomaticBean.java:207)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:411)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:338)
        at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:195)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:130)

Expected:

➜  src java -jar checkstyle-10.12.8-SNAPSHOT-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/nick/IdeaProjects/tester/src/Test.java:3:25: Token text matches the illegal pattern 'x'. [IllegalTokenText]
[ERROR] /home/nick/IdeaProjects/tester/src/Test.java:7:20: Token text matches the illegal pattern 'x'. [IllegalTokenText]
Audit done.
Checkstyle ends with 2 errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions