OSDN Git Service

am 8bf221bd: Fix error when using list as actionBarNavMode. [DO NOT MERGE]
[android-x86/frameworks-base.git] / docs / html / tools / help / lint.jd
1 page.title=lint
2 parent.title=Tools
3 parent.link=index.html
4 @jd:body
5
6 <div id="qv-wrapper">
7   <div id="qv">
8      <h2>In this document</h2>
9   <ol>
10      <li><a href="#syntax">Syntax</a></li>
11      <li><a href="#options">Options</a></li>
12      <li><a href="#config_keywords">Configuring Java and XML Source Files</a></li>
13   </ol>
14   </div>
15 </div>
16
17 <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>
18 <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>
19
20 <h2 id="syntax">Syntax</h2>
21 <p>
22 <pre>lint [flags] &lt;project directory&gt;</pre>
23
24 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.
25 <pre>lint myproject</pre>
26
27 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.
28 <pre>lint --check MissingPrefix myproject</pre>
29
30 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.
31 <pre>lint --check Accessibility --HTML accessibility_report.html myproject</pre>
32 </p>
33
34 <h2 id="options">Options</h2>
35 <p>Table 1 describes the command-line options for {@code lint}.</p>
36 <p class="table-caption" id="table1">
37   <strong>Table 1.</strong> Command-line options for lint</p>
38 <table>
39 <tr>
40   <th>Category</th>
41   <th>Option</th>
42   <th>Description</th>
43   <th>Comments</th>
44 </tr>
45
46 <tr>
47 <td rowspan="7">Checking</td>
48 <td><nobr><code>--disable &lt;list&gt;</code></nobr></td>
49 <td>Disable checking for a specific list of issues.</td>
50 <td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
51 </tr>
52
53 <tr>
54 <td><nobr><code>--enable &lt;list&gt;</code></nobr></td>
55 <td>Check for all the default issues supported by {@code lint} as well as the specifically enabled list of issues.</td>
56 <td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
57 </tr>
58
59 <tr>
60 <td><nobr><code>--check &lt;list&gt;</code></nobr></td>
61 <td>Check for a specific list of issues.</td>
62 <td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
63 </tr>
64
65 <tr>
66 <td><nobr><code>-w</code> or <code>--nowarn</code></nobr></td>
67 <td>Only check for errors and ignore warnings</td>
68 <td>&nbsp;</td>
69 </tr>
70
71 <tr>
72 <td><nobr><code>-Wall</code></nobr></td>
73 <td>Check for all warnings, including those that are disabled by default</td>
74 <td>&nbsp;</td>
75 </tr>
76
77 <tr>
78 <td><nobr><code>-Werror</code></nobr></td>
79 <td>Report all warnings as errors</td>
80 <td>&nbsp;</td>
81 </tr>
82
83 <tr>
84 <td><nobr><code>--config &lt;filename&gt;</code></nobr></td>
85 <td>Use the specified configuration file to determine if issues are enabled or disabled for {@code lint} checking</td>
86 <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>
87 </tr>
88
89 <tr>
90 <td rowspan="9">Reporting</td>
91 <td><nobr><code>--html &lt;filename&gt;</code></nobr></td>
92 <td>Generate an HTML report.</td>
93 <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>
94 </tr>
95
96 <tr>
97 <td><nobr><code>--url &lt;filepath&gt;=&lt;url&gt;</code></nobr></td>
98 <td>In the HTML output, replace a local path prefix <code>&lt;filepath&gt;</code> with a url prefix <code>&lt;url&gt;</code>.</td>
99 <td>The {@code --url} option only applies when you are generating an HTML report with the {@code --html} option. You can specify multiple &lt;filepath&gt;=&lt;url&gt; mappings in the argument by separating each mapping with a comma.<p>To turn off linking to files, use {@code --url none}</p></td>
100 </tr>
101
102 <tr>
103 <td><nobr><code>--simplehtml &lt;filename&gt;</code></nobr></td>
104 <td>Generate a simple HTML report</td>
105 <td>The report is saved in the output file specified in the argument.</td>
106 </tr>
107
108 <tr>
109 <td><nobr><code>--xml &lt;filename&gt;</code></nobr></td>
110 <td>Generate an XML report</td>
111 <td>The report is saved in the output file specified in the argument.</td>
112 </tr>
113
114 <tr>
115 <td><nobr><code>--fullpath</code></nobr></td>
116 <td>Show the full file paths in the {@code lint} checking results.</td>
117 <td>&nbsp;</td>
118 </tr>
119
120 <tr>
121 <td><nobr><code>--showall</code></nobr></td>
122 <td>Don't truncate long messages or lists of alternate locations.</td>
123 <td>&nbsp;</td>
124 </tr>
125
126 <tr>
127 <td><nobr><code>--nolines</code></nobr></td>
128 <td>Don't include code snippets from the source files in the output.</td>
129 <td>&nbsp;</td>
130 </tr>
131
132 <tr>
133 <td><nobr><code>--exitcode</code></nobr></td>
134 <td>Set the exit code to 1 if errors are found.</td>
135 <td>&nbsp;</td>
136 </tr>
137
138 <tr>
139 <td><nobr><code>--quiet</code></nobr></td>
140 <td>Don't show the progress indicator.</td>
141 <td>&nbsp;</td>
142 </tr>
143
144 <tr>
145 <td rowspan="4">Help</td>
146 <td><nobr><code>--help</code></nobr></td>
147 <td>List the command-line arguments supported by the {@code lint} tool.</td>
148 <td>Use {@code --help &lt;topic&gt;} to see help information for a specific topic, such as "suppress".</td>
149 </tr>
150
151 <tr>
152 <td><nobr><code>--list</code></nobr></td>
153 <td>List the ID and short description for issues that can be checked by {@code lint}</td>
154 <td>&nbsp;</td>
155 </tr>
156
157 <tr>
158 <td><nobr><code>--show</code></nobr></td>
159 <td>List the ID and verbose description for issues that can be checked by {@code lint}</td>
160 <td>Use {@code --show &lt;ids&gt;} to see descriptions for a specific list of {@code lint} issue IDs.</td>
161 </tr>
162
163 <tr>
164 <td><nobr><code>--version</code></nobr></td>
165 <td>Show the {@code lint} version</td>
166 <td>&nbsp;</td>
167 </tr>
168
169 </table>
170
171
172 <h2 id="config_keywords">Configuring Java and XML Source Files</h2>
173 <p>To configure lint checking, you can apply the following annotation or attribute to the source files in your Android project. </p>
174 <ul>
175 <LI>To disable lint checking for a specific Java class or method, use the <code>@SuppressLint</code> annotation. </LI>
176 <li>To disable lint checking for specific sections of your XML file, use the <code>tools:ignore</code> attribute. </li>
177 </ul>
178 <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>