# Checks for Headers

## Header

#### Description

Checks that a source file begins with a specified header. Property headerFile specifies a file that contains the required header.

Property ignoreLines specifies the line numbers to ignore when matching lines in a header file. This property is very useful for supporting headers that contain copyright dates. For example, consider the following header:

    line 1: ////////////////////////////////////////////////////////////////////
    line 2: // checkstyle:
    line 3: // Checks Java source code for adherence to a set of rules.
    line 4: // Copyright (C) 2002  Oliver Burn
    line 5: ////////////////////////////////////////////////////////////////////

Since the year information will change over time, you can tell Checkstyle to ignore line 4 by setting property ignoreLines to 4.

#### Properties

name | description | type | default value
--- | --- | --- | ---
headerFile | name of the file containing the required header | string | null
ignoreLines | line numbers to ignore | list of integers | {}

#### Example

To configure the check to use header file "java.header" and ignore lines 2, 3, and 4:

    <module name="Header">
        <property name="headerFile" value="java.header"/>
        <property name="ignoreLines" value="2, 3, 4"/>
    </module>

#### Package

com.puppycrawl.tools.checkstyle.checks

#### Parent Module

TreeWalker

## RegexpHeader

#### Description

Checks the header of a source file against a header file that contains a regular expression for each line of the source header.

Rationale: In some projects checking against a fixed header is not sufficient, e.g. the header might require a copyright line where the year information is not static.

For example, consider the following header file:

    line  1: ^/{71}$
    line  2: ^// checkstyle:$
    line  3: ^// Checks Java source code for adherence to a set of rules\.$
    line  4: ^// Copyright \(C\) \d\d\d\d  Oliver Burn$
    line  5: ^// Last modification by \$Author.*\$$
    line  6: ^/{71}$
    line  7:
    line  8: ^package
    line  9:
    line 10: ^import
    line 11:
    line 12: ^/\*\*
    line 13: ^ \*([^/]|$)
    line 14: ^ \*/

Lines 1 and 6 demonstrate a more compact notation for 71 '/' characters. Line 4 enforces that the copyright notice includes a four digit year. Line 5 is an example how to enforce revision control keywords in a file header. Lines 12-14 is a template for javadoc (line 13 is so complecated to remove conflict with and of javadoc comment).

#### Properties

name | description | type | default value
--- | --- | --- | ---
headerFile | name of the file containing the required header | string | null
multiLines | line numbers to repeat (zero or more times) | list of integers | {}

#### Example

To configure the check to use header file "java.header" and 10 and 13 muli-lines:

    <module name="RegexpHeader">
        <property name="headerFile" value="java.header"/>
        <property name="multiLines" value="10, 13"/>
    </module>

Note: ignoreLines property has been removed from this check to simplify it. To make some line optional use "^.*$" regexp for this line.

#### Package

com.puppycrawl.tools.checkstyle.checks

#### Parent Module

TreeWalker

Back to the Checkstyle Home Page

Copyright © 2002-2003 Oliver Burn. All rights Reserved.