FileTabCharacter

Since Checkstyle 5.0

Description

Checks that there are no tab characters ('\t') in the source code.

Rationale:

  • Developers should not need to configure the tab width of their text editors in order to be able to read source code.
  • From the Apache jakarta coding standards: In a distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.

Properties

name description type default value since
eachLine Control whether to report on each line containing a tab, or just the first instance. boolean false 5.0
fileExtensions Specify the file extensions of the files to process. String[] all files 5.0

Examples

To configure the check to report only the first instance in each file:

<module name="Checker">
  <module name="FileTabCharacter"/>
</module>
        

Example - Test.java:

class Example1 {
  int a; // violation 'File contains tab characters'

  public void foo (int arg) { // OK, only first occurrence in file reported
    a = arg; // OK, indented using spaces
  }
}
        

To configure the check to report each instance in each file:

<module name="Checker">
  <module name="FileTabCharacter">
    <property name="eachLine" value="true"/>
  </module>
</module>
        

Example - Test.java:

class Example2 {
  int a; // violation 'contains a tab character'

  public void foo (int arg) { // violation 'contains a tab character'
    a = arg; // OK, indented using spaces
  }
}
        

To configure the check to report instances on only certain file types:

<module name="Checker">
  <module name="FileTabCharacter">
    <property name="fileExtensions" value="java, xml"/>
  </module>
</module>
        

Example - Test.java:

class Example3 {
  int a; // violation 'File contains tab characters'

  public void foo (int arg) { // OK, only first occurrence in file reported
    a = arg; // OK, indented using spaces
  }
}
        

Example - Test.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<UserAccount>
  <FirstName>John</FirstName> // violation 'File contains tab characters'
  <LastName>Doe</LastName>    <!-- OK, only first occurrence in file reported -->
</UserAccount>
        

Example - Test.html:

<head>
  <title>Page Title</title> <!-- OK, no check performed on html file extension -->
</head>                       <!-- not specified in check config -->
<body>
  <p>This is a simple html document.</p>
</body>
        

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.whitespace

Parent Module

Checker