| page.title=lint |
| parent.title=Tools |
| parent.link=index.html |
| @jd:body |
| |
| <div id="qv-wrapper"> |
| <div id="qv"> |
| <h2>In this document</h2> |
| <ol> |
| <li><a href="#syntax">Syntax</a></li> |
| <li><a href="#options">Options</a></li> |
| <li><a href="#config_keywords">Configuring Java and XML Source Files</a></li> |
| </ol> |
| </div> |
| </div> |
| |
| <p>The Android {@code lint} tool is a static code analysis tool that checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. </p> |
| <p>For more information on running {@code lint}, see <a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.</p> |
| |
| <h2 id="syntax">Syntax</h2> |
| <p> |
| <pre>lint [flags] <project directory></pre> |
| |
| For example, you can issue the following command to scan the Java and XML files under the {@code myproject} directory and its subdirectories. The result is displayed on the console. |
| <pre>lint myproject</pre> |
| |
| You can also use {@code lint} to check for a specific issue. For example, you can run the following command to scan the files under the {@code myproject} directory and its subdirectories to check for XML attributes missing the Android namespace prefix. The issue ID {@code MissingPrefix} tells lint to only scan for this issue. |
| <pre>lint --check MissingPrefix myproject</pre> |
| |
| You can create an HTML report for the issues that {@code lint} detects. For example, you can run the following command to scan the {@code myproject} directory and its subdirectories for accessibility issues, then generate an HTML report in the {@code accessibility_report.html} file. |
| <pre>lint --check Accessibility --HTML accessibility_report.html myproject</pre> |
| </p> |
| |
| <h2 id="options">Options</h2> |
| <p>Table 1 describes the command-line options for {@code lint}.</p> |
| <p class="table-caption" id="table1"> |
| <strong>Table 1.</strong> Command-line options for lint</p> |
| <table> |
| <tr> |
| <th>Category</th> |
| <th>Option</th> |
| <th>Description</th> |
| <th>Comments</th> |
| </tr> |
| |
| <tr> |
| <td rowspan="7">Checking</td> |
| <td><nobr><code>--disable <list></code></nobr></td> |
| <td>Disable checking for a specific list of issues.</td> |
| <td>The <code><list></code> must be a comma-separated list of {@code lint} issue IDs or categories.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--enable <list></code></nobr></td> |
| <td>Check for all the default issues supported by {@code lint} as well as the specifically enabled list of issues.</td> |
| <td>The <code><list></code> must be a comma-separated list of {@code lint} issue IDs or categories.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--check <list></code></nobr></td> |
| <td>Check for a specific list of issues.</td> |
| <td>The <code><list></code> must be a comma-separated list of {@code lint} issue IDs or categories.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>-w</code> or <code>--nowarn</code></nobr></td> |
| <td>Only check for errors and ignore warnings</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>-Wall</code></nobr></td> |
| <td>Check for all warnings, including those that are disabled by default</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>-Werror</code></nobr></td> |
| <td>Report all warnings as errors</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--config <filename></code></nobr></td> |
| <td>Use the specified configuration file to determine if issues are enabled or disabled for {@code lint} checking</td> |
| <td>If the project contains a {@code lint.xml} file, the {@code lint.xml} file will be used as the configuration file by default.</td> |
| </tr> |
| |
| <tr> |
| <td rowspan="9">Reporting</td> |
| <td><nobr><code>--html <filename></code></nobr></td> |
| <td>Generate an HTML report.</td> |
| <td>The report is saved in the output file specified in the argument. The HTML output includes code snippets of the source code where {@code lint} detected an issue, a verbose description of the issue found, and links to the source file.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--url <filepath>=<url></code></nobr></td> |
| <td>In the HTML output, replace a local path prefix <code><filepath></code> with a url prefix <code><url></code>.</td> |
| <td>The {@code --url} option only applies when you are generating an HTML report with the {@code --html} option. You can specify multiple <filepath>=<url> mappings in the argument by separating each mapping with a comma.<p>To turn off linking to files, use {@code --url none}</p></td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--simplehtml <filename></code></nobr></td> |
| <td>Generate a simple HTML report</td> |
| <td>The report is saved in the output file specified in the argument.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--xml <filename></code></nobr></td> |
| <td>Generate an XML report</td> |
| <td>The report is saved in the output file specified in the argument.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--fullpath</code></nobr></td> |
| <td>Show the full file paths in the {@code lint} checking results.</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--showall</code></nobr></td> |
| <td>Don't truncate long messages or lists of alternate locations.</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--nolines</code></nobr></td> |
| <td>Don't include code snippets from the source files in the output.</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--exitcode</code></nobr></td> |
| <td>Set the exit code to 1 if errors are found.</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--quiet</code></nobr></td> |
| <td>Don't show the progress indicator.</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td rowspan="4">Help</td> |
| <td><nobr><code>--help</code></nobr></td> |
| <td>List the command-line arguments supported by the {@code lint} tool.</td> |
| <td>Use {@code --help <topic>} to see help information for a specific topic, such as "suppress".</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--list</code></nobr></td> |
| <td>List the ID and short description for issues that can be checked by {@code lint}</td> |
| <td> </td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--show</code></nobr></td> |
| <td>List the ID and verbose description for issues that can be checked by {@code lint}</td> |
| <td>Use {@code --show <ids>} to see descriptions for a specific list of {@code lint} issue IDs.</td> |
| </tr> |
| |
| <tr> |
| <td><nobr><code>--version</code></nobr></td> |
| <td>Show the {@code lint} version</td> |
| <td> </td> |
| </tr> |
| |
| </table> |
| |
| |
| <h2 id="config_keywords">Configuring Java and XML Source Files</h2> |
| <p>To configure lint checking, you can apply the following annotation or attribute to the source files in your Android project. </p> |
| <ul> |
| <LI>To disable lint checking for a specific Java class or method, use the <code>@SuppressLint</code> annotation. </LI> |
| <li>To disable lint checking for specific sections of your XML file, use the <code>tools:ignore</code> attribute. </li> |
| </ul> |
| <p>You can also specify your lint checking preferences for a specific Android project in the lint.xml file. For more information on configuring lint, see <a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.</p> |