Skip to content

Commit 62ab073

Browse files
committed
Improve the code quality
1 parent 6a9d536 commit 62ab073

File tree

105 files changed

+5191
-4494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5191
-4494
lines changed

src/iTextSharp.LGPLv2.Core/.editorconfig

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,216 @@ dotnet_diagnostic.IDE0044.severity = warning
199199
# SYSLIB0014: Method 'System.Net.WebRequest.Create(Uri)' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.'
200200
dotnet_diagnostic.SYSLIB0014.severity = suggestion
201201

202+
203+
# S125 : Remove this commented out code.
204+
dotnet_diagnostic.S125.severity = suggestion
205+
206+
# MA0026 : TODO Evaluate the effect of this.
207+
dotnet_diagnostic.MA0026.severity = suggestion
208+
209+
# S1135 : Complete the task associated to this 'TODO' comment.
210+
dotnet_diagnostic.S1135.severity = suggestion
211+
212+
# S4663 : Remove this empty comment
213+
dotnet_diagnostic.S4663.severity = suggestion
214+
215+
# S108: Either remove or fill this block of code.
216+
dotnet_diagnostic.S108.severity = suggestion
217+
218+
# S1104 : Make this field 'private' and encapsulate it in a 'public' property.
219+
dotnet_diagnostic.S1104.severity = suggestion
220+
221+
# MA0051 : Method is too long
222+
dotnet_diagnostic.MA0051.severity = suggestion
223+
224+
# S1764: Correct one of the identical expressions on both sides of operator '&&'.
225+
dotnet_diagnostic.S1764.severity = suggestion
226+
227+
# MA0056 : Do not call overridable members in constructor
228+
dotnet_diagnostic.MA0056.severity = suggestion
229+
230+
# S1121 : Extract the assignment of 't' from this expression.
231+
dotnet_diagnostic.S1121.severity = suggestion
232+
233+
# S127: Do not update the loop counter 'k' within the loop body.
234+
dotnet_diagnostic.S127.severity = suggestion
235+
236+
# S4143 : Verify this is the index/key that was intended;
237+
dotnet_diagnostic.S4143.severity = suggestion
238+
239+
# S2486 : Handle the exception or explain in a comment why it can be ignored.
240+
dotnet_diagnostic.S2486.severity = suggestion
241+
242+
# S1066: Merge this if statement with the enclosing one.
243+
dotnet_diagnostic.S1066.severity = suggestion
244+
245+
#S1854 : Remove this useless assignment to local variable
246+
dotnet_diagnostic.S1854.severity = suggestion
247+
248+
# S1871: Either merge this case with the identical one on line x or change one of the implementations.
249+
dotnet_diagnostic.S1871.severity = suggestion
250+
251+
# S3400: Remove this method and declare a constant for this value.
252+
dotnet_diagnostic.S3400.severity = suggestion
253+
254+
# S2292: Make this an auto-implemented property and remove its backing field.
255+
dotnet_diagnostic.S2292.severity = suggestion
256+
257+
# S1144 : Remove the unused private field
258+
dotnet_diagnostic.S1144.severity = suggestion
259+
260+
# S907: Remove this use of 'goto'.
261+
dotnet_diagnostic.S907.severity = suggestion
262+
263+
# S4275 : Refactor this getter so that it actually refers to the field
264+
dotnet_diagnostic.S4275.severity = suggestion
265+
266+
# S4487: Remove this unread private field or refactor the code to use its value.
267+
dotnet_diagnostic.S4487.severity = suggestion
268+
269+
# S3887: Use an immutable collection or reduce the accessibility of the non-private readonly field
270+
dotnet_diagnostic.S3887.severity = suggestion
271+
272+
# S2386: Use an immutable collection or reduce the accessibility of the public static field.
273+
dotnet_diagnostic.S2386.severity = suggestion
274+
275+
# S1940: Use the opposite operator ('!=') instead.
276+
dotnet_diagnostic.S1940.severity = suggestion
277+
278+
# S3241: Change return type to 'void'; not a single caller uses the returned value.
279+
dotnet_diagnostic.S3241.severity = suggestion
280+
281+
# S1199: Extract this nested code block into a separate method.
282+
dotnet_diagnostic.S1199.severity = suggestion
283+
284+
# S1481: Remove the unused local variable.
285+
dotnet_diagnostic.S1481.severity = suggestion
286+
287+
# S1075 : Refactor your code not to use hardcoded absolute paths or URIs.
288+
dotnet_diagnostic.S1075.severity = suggestion
289+
290+
# MA0037 : Remove empty statement
291+
dotnet_diagnostic.MA0037.severity = suggestion
292+
293+
# S2376: Provide a getter
294+
dotnet_diagnostic.S2376.severity = suggestion
295+
296+
# S1450: Remove the field and declare it as a local variable in the relevant methods.
297+
dotnet_diagnostic.S1450.severity = suggestion
298+
299+
# S3604: Remove the member initializer, all constructors set an initial value for the member.
300+
dotnet_diagnostic.S3604.severity = suggestion
301+
302+
# S1116: Remove this empty statement.
303+
dotnet_diagnostic.S1116.severity = suggestion
304+
305+
# S1168 : Return an empty collection instead of null.
306+
dotnet_diagnostic.S1168.severity = suggestion
307+
308+
# S1264 : Replace this 'for' loop with a 'while' loop.
309+
dotnet_diagnostic.S1264.severity = suggestion
310+
311+
# S3237: Use the 'value' contextual keyword in this property set accessor declaration.
312+
dotnet_diagnostic.S3237.severity = suggestion
313+
314+
# S4136: All method overloads should be adjacent.
315+
dotnet_diagnostic.S4136.severity = suggestion
316+
317+
# S2368: Make this method private or simplify its parameters to not use multidimensional/ jagged arrays.
318+
dotnet_diagnostic.S2368.severity = suggestion
319+
320+
# S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation.
321+
dotnet_diagnostic.S1186.severity = suggestion
322+
323+
# S1699: Remove this call from a constructor to the overridable method.
324+
dotnet_diagnostic.S1699.severity = suggestion
325+
326+
# S3881: Fix this implementation of 'IDisposable' to conform to the dispose pattern.
327+
dotnet_diagnostic.S3881.severity = suggestion
328+
329+
# MA0016: Prefer using collection abstraction instead of implementation
330+
dotnet_diagnostic.MA0016.severity = suggestion
331+
332+
# S2223: Change the visibility or make it 'const' or 'readonly'.
333+
dotnet_diagnostic.S2223.severity = suggestion
334+
335+
# MA0069: Non-constant static fields should not be visible
336+
dotnet_diagnostic.MA0069.severity = suggestion
337+
338+
# MA0097: A class that implements IComparable<T> or IComparable should override comparison operators
339+
dotnet_diagnostic.MA0097.severity = suggestion
340+
341+
# S1210: When implementing IComparable, you should also override Equals, ==, !=, <, <=, >, and >=.
342+
dotnet_diagnostic.S1210.severity = suggestion
343+
344+
# S4144: Update this method so that its implementation is not identical to X.
345+
dotnet_diagnostic.S4144.severity = suggestion
346+
347+
# S2094: Remove this empty class, write its code or make it an "interface".
348+
dotnet_diagnostic.S2094.severity = suggestion
349+
350+
# S3963: Initialize all 'static fields' inline and remove the 'static constructor'.
351+
dotnet_diagnostic.S3963.severity = suggestion
352+
353+
# S3458: Remove this empty 'case' clause.
354+
dotnet_diagnostic.S3458.severity = suggestion
355+
356+
# S2183: Remove this useless shift by 0.
357+
dotnet_diagnostic.S2183.severity = suggestion
358+
359+
# S1172: Remove this unused method parameter.
360+
dotnet_diagnostic.S1172.severity = suggestion
361+
362+
# MA0015: Use an overload of 'System. ArgumentException' with the parameter name
363+
dotnet_diagnostic.MA0015.severity = suggestion
364+
365+
# S2692: 0 is a valid index, but this check ignores it.
366+
dotnet_diagnostic.S2692.severity = suggestion
367+
368+
# S927: Rename parameter 'refi' to 'piRef' to match the base class declaration.
369+
dotnet_diagnostic.S927.severity = suggestion
370+
371+
# S1643: Use a StringBuilder instead.
372+
dotnet_diagnostic.S1643.severity = suggestion
373+
374+
# S3256 : Use 'string.IsNullOrEmpty()' instead of comparing to empty string.
375+
dotnet_diagnostic.S3256.severity = suggestion
376+
377+
# S2328: Refactor 'GetHashCode' to not reference mutable fields.
378+
dotnet_diagnostic.S2328.severity = suggestion
379+
380+
# S3267: Loops should be simplified using the "Where" LINQ method
381+
dotnet_diagnostic.S3267.severity = suggestion
382+
383+
# S3217: Either change the type of 'n' to 'PdfObject' or iterate on a generic collection of type 'PdfNumber'.
384+
dotnet_diagnostic.S3217.severity = suggestion
385+
386+
# MA0094: A class that provides CompareTo(T) should implement IComparable<T>
387+
dotnet_diagnostic.MA0094.severity = suggestion
388+
389+
# S3358 : Extract this nested ternary operation into an independent statement.
390+
dotnet_diagnostic.S3358.severity = suggestion
391+
392+
# S1244 : Do not check floating point equality with exact values, use a range instead.
393+
dotnet_diagnostic.S1244.severity = suggestion
394+
395+
# S2372 : Remove the exception throwing from this property getter, or refactor the property into a method.
396+
dotnet_diagnostic.S2372.severity = suggestion
397+
398+
# S3626: Remove this redundant jump.
399+
dotnet_diagnostic.S3626.severity = suggestion
400+
401+
# S1751 : Refactor the containing loop to do more than one iteration.
402+
dotnet_diagnostic.S1751.severity = suggestion
403+
404+
# S2234 : Parameters to 'SetColumn' have the same names but not the same order as the method arguments.
405+
dotnet_diagnostic.S2234.severity = suggestion
406+
407+
# S3885 : Replace this call to 'Assembly.LoadFrom' with 'Assembly.Load'.
408+
dotnet_diagnostic.S3885.severity = suggestion
409+
410+
# S3218 : Rename this method to not shadow the outer class' member with the same name.
411+
dotnet_diagnostic.S3218.severity = suggestion
412+
202413
# force file scoped namespaces
203414
csharp_style_namespace_declarations = file_scoped:error

src/iTextSharp.LGPLv2.Core/System/Drawing/Dimension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Dimension : Dimension2D
2323
/// Creates an instance of Dimension with a width
2424
/// of zero and a height of zero.
2525
/// </summary>
26-
public Dimension() : this(0, 0)
26+
public Dimension() : this(width: 0, height: 0)
2727
{
2828
}
2929

@@ -100,10 +100,9 @@ public Dimension(int width, int height)
100100
/// <returns></returns>
101101
public override bool Equals(object obj)
102102
{
103-
if (obj is Dimension)
103+
if (obj is Dimension dimension)
104104
{
105-
var d = (Dimension)obj;
106-
return width == d.width && height == d.height;
105+
return width == dimension.width && height == dimension.height;
107106
}
108107

109108
return false;
@@ -116,6 +115,7 @@ public override bool Equals(object obj)
116115
public override int GetHashCode()
117116
{
118117
var sum = width + height;
118+
119119
return sum * (sum + 1) / 2 + width;
120120
}
121121

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Runtime.InteropServices;
2-
using System.Security.Cryptography;
1+
using System.Security.Cryptography;
32
using Org.BouncyCastle.Crypto.Digests;
43

54
namespace iTextSharp;
@@ -11,33 +10,28 @@ namespace iTextSharp;
1110
public sealed class MD5BouncyCastle : HashAlgorithm
1211
{
1312
#if NET40
14-
public static new HashAlgorithm Create() => MD5.Create();
13+
public new static HashAlgorithm Create() => MD5.Create();
1514
#else
16-
public new static HashAlgorithm Create() =>
17-
string.Equals(RuntimeInformation.OSDescription, "Browser", StringComparison.OrdinalIgnoreCase)
15+
public new static HashAlgorithm Create()
16+
=> string.Equals(System.Runtime.InteropServices.RuntimeInformation.OSDescription, b: "Browser", StringComparison.OrdinalIgnoreCase)
1817
? new MD5BouncyCastle()
1918
: MD5.Create();
2019
#endif
2120

22-
private MD5BouncyCastle()
23-
{
24-
}
25-
2621
private readonly MD5Digest _digestInternal = new();
2722

2823
public override void Initialize()
2924
{
3025
}
3126

3227
protected override void HashCore(byte[] array, int ibStart, int cbSize)
33-
{
34-
_digestInternal.BlockUpdate(array, ibStart, cbSize);
35-
}
28+
=> _digestInternal.BlockUpdate(array, ibStart, cbSize);
3629

3730
protected override byte[] HashFinal()
3831
{
3932
var output = new byte[_digestInternal.GetByteLength()];
40-
_digestInternal.DoFinal(output, 0);
33+
_digestInternal.DoFinal(output, outOff: 0);
34+
4135
return output;
4236
}
4337
}

src/iTextSharp.LGPLv2.Core/System/util/StringTokenizer.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public class StringTokenizer
1414
private string _delim;
1515
private int _pos;
1616

17-
public StringTokenizer(string str) : this(str, " \t\n\r\f", false)
17+
public StringTokenizer(string str) : this(str, delim: " \t\n\r\f", retDelims: false)
1818
{
1919
}
2020

21-
public StringTokenizer(string str, string delim) : this(str, delim, false)
21+
public StringTokenizer(string str, string delim) : this(str, delim, retDelims: false)
2222
{
2323
}
2424

@@ -58,8 +58,8 @@ public int CountTokens()
5858
else
5959
{
6060
tokenFound = true;
61-
while (tmpPos < _len
62-
&& _delim.IndexOf(_str[tmpPos].ToString(), StringComparison.Ordinal) < 0)
61+
62+
while (tmpPos < _len && _delim.IndexOf(_str[tmpPos].ToString(), StringComparison.Ordinal) < 0)
6363
{
6464
++tmpPos;
6565
}
@@ -90,6 +90,7 @@ public bool HasMoreTokens()
9090
public string NextToken(string delim)
9191
{
9292
_delim = delim;
93+
9394
return NextToken();
9495
}
9596

@@ -99,7 +100,7 @@ public string NextToken()
99100
{
100101
if (_retDelims)
101102
{
102-
return _str.Substring(_pos++, 1);
103+
return _str.Substring(_pos++, length: 1);
103104
}
104105

105106
while (++_pos < _len && _delim.IndexOf(_str[_pos].ToString(), StringComparison.Ordinal) >= 0)
@@ -111,6 +112,7 @@ public string NextToken()
111112
if (_pos < _len)
112113
{
113114
var start = _pos;
115+
114116
while (++_pos < _len && _delim.IndexOf(_str[_pos].ToString(), StringComparison.Ordinal) < 0)
115117
{
116118
;
@@ -119,6 +121,6 @@ public string NextToken()
119121
return _str.Substring(start, _pos - start);
120122
}
121123

122-
throw new ArgumentOutOfRangeException();
124+
throw new InvalidOperationException(message: "Failed to get NextToken");
123125
}
124126
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace System.util;
2+
3+
/// <summary>
4+
/// This custom IDictionary doesn't throw a KeyNotFoundException while accessing its value by a given key
5+
/// </summary>
6+
public interface INullValueDictionary<TKey, TValue> : IDictionary<TKey, TValue>
7+
{
8+
new TValue this[TKey key] { get; set; }
9+
10+
INullValueDictionary<TKey, TValue> Clone();
11+
}

0 commit comments

Comments
 (0)