MultiFileRegexpHeader
Since Checkstyle 10.24.0
Description
Properties
name | description | type | default value | since |
---|---|---|---|---|
fileExtensions | Specify the file extensions of the files to process. | String[] | all files |
10.24.0 |
headerFiles | Specify a comma-separated list of files containing the required headers. If a file's header matches none, the violation references the first file in this list. Users can order files to set a preferred header for such reporting. | String | null |
10.24.0 |
Examples
To configure the check such that no violations arise. Default values of properties are used.
<module name="Checker">
<module name="MultiFileRegexpHeader"/>
</module>
Example1:
package com.puppycrawl.tools.checkstyle.checks.header.header;
// OK, as by default there is not specific header defined to validate it presence
public class Example1 { }
To configure the check to use multiple header files:
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property name="fileExtensions" value="java"/>
<property name="headerFiles" value="${config.folder}/java.header, ${config.folder}/apache.header"/>
</module>
</module>
content of "java.header" file:
// Checkstyle - Java code style checker. Copyright (C) 20XX-20XX the authors.
// Licensed under the LGPL v2.1 or later. See LICENSE for details.
// Distributed without warranty; see the GNU LGPL for more info.
content of "apache.header" file:
/* Licensed to the ASF under the Apache License, Version 2.0 (see NOTICE).
* You may not use this file except in compliance:
* http://www.apache.org/licenses/LICENSE-2.0 (AS IS, no warranties/conditions). */
Example2:
package com.puppycrawl.tools.checkstyle.checks.header.header;
/* violation on first line 'Line does not match expected header line of' */
// because headerFile is bigger then target java file
public class Example2 { }
To configure the check to verify that each file starts with one of multiple headers:
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
name="headerFiles"
value="${config.folder}/java.header,${config.folder}/apache.header"/>
</module>
</module>
Example3:
package com.puppycrawl.tools.checkstyle.checks.header.regexpheader;
/* violation on first line 'Line does not match expected header line' */
public class Example3 { }
For a configuration where any header is accepted:
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
name="headerFiles"
value="${config.folder}/universal.header"/>
</module>
</module>
content of "universal.header" file:
^.*
".*"
will match all lines and
expect no violation. For example -
package com.puppycrawl.tools.checkstyle.checks.header.regexpheader;
//OK, as regex value matches all lines
public class Example4 { }
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.header