A check for detecting single lines that match a supplied regular expression. Works with any file type.
Rationale: This check can be used to prototype checks and to find common bad practice such as calling ex.printStacktrace(), System.out.println(), System.exit(), etc.
name | description | type | default value |
---|---|---|---|
format | illegal pattern | regular expression | ^$ (empty) |
message | message which is used to notify about violations, if empty then default(hard-coded) message is used. | String | ""(empty) |
ignoreCase | Controls whether to ignore case when searching. | Boolean | false |
minimum | The minimum number of matches required in each file. | Integer | 0 |
maximum | The maximum number of matches required in each file. | Integer | 0 |
fileExtensions | file type extension of files to process | String Set | {} |
To configure the check to find trailing whitespace at the end of a line:
<module name="RegexpSingleline"> <!-- \s matches whitespace character, $ matches end of line. --> <property name="format" value="\s+$"/> </module>
To configure the check to find trailing whitespace at the end of a line, with some slack of allowing two occurances per file:
<module name="RegexpSingleline"> <property name="format" value="\s+$"/> <!-- next line not required as 0 is the default --> <property name="minimum" value="0"/> <property name="maximum" value="2"/> </module>
An example of how to configure the check to make sure a copyright statement is included in the file:
<module name="RegexpSingleline"> <property name="format" value="This file is copyrighted"/> <property name="minimum" value="1"/> <!-- Need to specify a maximum, so 10 times is more than enough. --> <property name="maximum" value="10"/> </module>
A check for detecting that matches across multiple lines. Works with any file type.
Rationale: This check can be used to when the regular expression can be span multiple lines.
name | description | type | default value |
---|---|---|---|
format | illegal pattern | regular expression | ^$ (empty) |
message | message which is used to notify about violations, if empty then default(hard-coded) message is used. | String | ""(empty) |
ignoreCase | Controls whether to ignore case when searching. | Boolean | false |
minimum | The minimum number of matches required in each file. | Integer | 0 |
maximum | The maximum number of matches required in each file. | Integer | 0 |
fileExtensions | file type extension of files to process | String Set | {} |
To configure the check to find calls to print to the console:
<module name="RegexpMultiline"> <property name="format" value="System\.(out)|(err)\.print(ln)?\("/> </module>
This class is variation on RegexpSingleline for detecting single lines that match a supplied regular expression in Java files. It supports suppressing matches in Java comments.
name | description | type | default value |
---|---|---|---|
format | illegal pattern | regular expression | ^$ (empty) |
message | message which is used to notify about violations, if empty then default(hard-coded) message is used. | String | ""(empty) |
ignoreCase | Controls whether to ignore case when searching. | Boolean | false |
minimum | The minimum number of matches required in each file. | Integer | 0 |
maximum | The maximum number of matches required in each file. | Integer | 0 |
ignoreComments | Controls whether to ignore text in comments when searching. | Boolean | false |
To configure the check for calls to System.out.println, except in comments:
<module name="RegexpSinglelineJava"> <!-- . matches any character, so we need to escape it and use \. to match dots. --> <property name="format" value="System\.out\.println"/> <property name="ignoreComments" value="true"/> </module>
To configure the check to find case-insensitive occurrences of "debug":
<module name="RegexpSinglelineJava"> <property name="format" value="debug"/> <property name="ignoreCase" value="true"/> </module>