-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFormatUnusedArgument.qhelp
More file actions
37 lines (34 loc) · 1.28 KB
/
FormatUnusedArgument.qhelp
File metadata and controls
37 lines (34 loc) · 1.28 KB
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
Arguments which are passed to formatting methods (such as <code>String.Format()</code>)
but are not used, are either unnecessary or mean that the format string is incorrect. The result
is that the argument will be ignored, which may not be the intended behavior.
</p>
</overview>
<recommendation>
<p>
Change the format string to use the highlighted argument, or remove the unnecessary argument.
</p>
</recommendation>
<example>
<p>
Here are three examples where the format string does not use all the arguments.
</p>
<sample src="FormatUnusedArgumentBad.cs"/>
<ul>
<li>On line 5, the second argument (<code>ex.HResult</code>) is not logged.</li>
<li>On line 6, the first argument (<code>ex</code>) is not logged but the second
argument (<code>ex.HResult</code>) is logged twice.</li>
<li>On line 4, a C-style format string is used, which is incorrect, and neither
argument will be logged.</li>
</ul>
</example>
<references>
<li>MSDN: <a href="https://msdn.microsoft.com/en-us/library/system.string.format.aspx">String.Format Method</a>.</li>
<li>Microsoft: <a href="https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting">Composite Formatting</a>.</li>
</references>
</qhelp>