summaryrefslogtreecommitdiffstats
path: root/docs/html/tools/help/lint.jd
blob: 0f52689b3342663bb25f771e73cbdf89889a9496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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>In Android Studio, the configured <code>lint</code> and other IDE inspections run automatically
whenever you compile your program. You can also manually run inspections in Android Studio
by selecting <strong>Analyze &gt; Inspect Code</strong> from the application or right-click menu.
The <em>Specify Inspections Scope</em> dialog appears so you can specify the desired inspection 
profile and scope.</p>

<p>For more information on enabling {@code lint} inspections and running {@code lint},
see <a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.</p>

<h2 id="syntax">Command Line Syntax</h2>
<p>
<pre>lint [flags] &lt;project directory&gt;</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 &lt;list&gt;</code></nobr></td>
<td>Disable checking for a specific list of issues.</td>
<td>The <code>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
</tr>

<tr>
<td><nobr><code>--enable &lt;list&gt;</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>&lt;list&gt;</code> must be a comma-separated list of {@code lint} issue IDs or categories.</td>
</tr>

<tr>
<td><nobr><code>--check &lt;list&gt;</code></nobr></td>
<td>Check for a specific list of issues.</td>
<td>The <code>&lt;list&gt;</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>&nbsp;</td>
</tr>

<tr>
<td><nobr><code>-Wall</code></nobr></td>
<td>Check for all warnings, including those that are disabled by default</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><nobr><code>-Werror</code></nobr></td>
<td>Report all warnings as errors</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><nobr><code>--config &lt;filename&gt;</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 &lt;filename&gt;</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 &lt;filepath&gt;=&lt;url&gt;</code></nobr></td>
<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>
<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>
</tr>

<tr>
<td><nobr><code>--simplehtml &lt;filename&gt;</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 &lt;filename&gt;</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>&nbsp;</td>
</tr>

<tr>
<td><nobr><code>--showall</code></nobr></td>
<td>Don't truncate long messages or lists of alternate locations.</td>
<td>&nbsp;</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>&nbsp;</td>
</tr>

<tr>
<td><nobr><code>--exitcode</code></nobr></td>
<td>Set the exit code to 1 if errors are found.</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><nobr><code>--quiet</code></nobr></td>
<td>Don't show the progress indicator.</td>
<td>&nbsp;</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 &lt;topic&gt;} 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>&nbsp;</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 &lt;ids&gt;} 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>&nbsp;</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 {@code lint} checking for a specific Java class or method, use the <code>@SuppressLint</code>
annotation. </LI>
<li>To disable {@code lint} checking for specific sections of your XML file, use the
<code>tools:ignore</code> attribute. </li>
</ul>
<p>You can also specify your {@code lint} checking preferences for a specific Android project in
the <code>lint.xml</code> file.  For more information on configuring {@code lint}, see
<a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.</p>