Skip to content

Commit 15baea6

Browse files
committed
Upgraded AnalysisMode to Recommended, code quality improved, code imperfections are more tolerated.
1 parent 87614b6 commit 15baea6

23 files changed

+125
-107
lines changed

.editorconfig

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
[*.cs]
22

3-
csharp_prefer_braces = when_multiline
4-
csharp_style_namespace_declarations=file_scoped:warning
3+
dotnet_analyzer_diagnostic.severity = suggestion
4+
5+
csharp_prefer_braces = when_multiline:suggestion
6+
csharp_prefer_simple_using_statement = true:suggestion
7+
csharp_style_expression_bodied_accessors = true:suggestion
8+
csharp_style_expression_bodied_constructors = true:suggestion
9+
csharp_style_expression_bodied_methods = true:suggestion
10+
csharp_style_expression_bodied_operators = true:suggestion
11+
csharp_style_expression_bodied_properties = true:suggestion
12+
csharp_style_prefer_pattern_matching = true:suggestion
13+
csharp_style_namespace_declarations = file_scoped
514
csharp_style_var_when_type_is_apparent = true
615
csharp_style_var_for_built_in_types = true
716
csharp_style_var_elsewhere = true
8-
9-
# IDE0040: Add accessibility modifiers
10-
dotnet_diagnostic.IDE0040.severity = none
17+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
18+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
19+
dotnet_style_require_accessibility_modifiers = always:suggestion

WebAssembly/CustomSection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ internal void WriteTo(Writer writer)
6969
{
7070
writer.Write(this.Name);
7171
if (this.content is byte[] bytes)
72+
{
7273
writer.Write(bytes);
74+
}
7375
else
76+
{
7477
foreach (var b in this.Content)
7578
writer.Write(b);
79+
}
7680
}
7781
}

WebAssembly/Data.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Data
2424
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
2525
public IList<Instruction> InitializerExpression
2626
{
27-
get => this.initializerExpression ??= new List<Instruction>();
27+
get => this.initializerExpression ??= [];
2828
set => this.initializerExpression = value ?? throw new ArgumentNullException(nameof(value));
2929
}
3030

@@ -37,7 +37,7 @@ public IList<Instruction> InitializerExpression
3737
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
3838
public IList<byte> RawData
3939
{
40-
get => this.rawData ??= new List<byte>();
40+
get => this.rawData ??= [];
4141
set => this.rawData = value ?? throw new ArgumentNullException(nameof(value));
4242
}
4343

@@ -69,9 +69,13 @@ internal void WriteTo(Writer writer)
6969

7070
writer.WriteVar((uint)this.RawData.Count);
7171
if (this.RawData is byte[] bytes)
72+
{
7273
writer.Write(bytes);
74+
}
7375
else
76+
{
7477
foreach (var b in this.RawData)
7578
writer.Write(b);
79+
}
7680
}
7781
}

WebAssembly/Element.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Element
2525
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
2626
public IList<Instruction> InitializerExpression
2727
{
28-
get => this.initializerExpression ??= new List<Instruction>();
28+
get => this.initializerExpression ??= [];
2929
set => this.initializerExpression = value ?? throw new ArgumentNullException(nameof(value));
3030
}
3131

@@ -38,7 +38,7 @@ public IList<Instruction> InitializerExpression
3838
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
3939
public IList<uint> Elements
4040
{
41-
get => this.elements ??= new List<uint>();
41+
get => this.elements ??= [];
4242
set => this.elements = value ?? throw new ArgumentNullException(nameof(value));
4343
}
4444

@@ -80,7 +80,7 @@ internal Element(Reader reader)
8080
this.initializerExpression = Instruction.ParseInitializerExpression(reader).ToList();
8181

8282
var count = checked((int)reader.ReadVarUInt32());
83-
var elements = this.elements = new List<uint>();
83+
var elements = this.elements = [];
8484

8585
for (var i = 0; i < count; i++)
8686
elements.Add(reader.ReadVarUInt32());

WebAssembly/FunctionBody.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class FunctionBody : IEquatable<FunctionBody>
2020
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
2121
public IList<Local> Locals
2222
{
23-
get => this.locals ??= new List<Local>();
23+
get => this.locals ??= [];
2424
set => this.locals = value ?? throw new ArgumentNullException(nameof(value));
2525
}
2626

@@ -33,7 +33,7 @@ public IList<Local> Locals
3333
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
3434
public IList<Instruction> Code
3535
{
36-
get => this.code ??= new List<Instruction>();
36+
get => this.code ??= [];
3737
set => this.code = value ?? throw new ArgumentNullException(nameof(value));
3838
}
3939

WebAssembly/Global.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Global
2929
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
3030
public IList<Instruction> InitializerExpression
3131
{
32-
get => this.initializerExpression ??= new List<Instruction>();
32+
get => this.initializerExpression ??= [];
3333
set => this.initializerExpression = value ?? throw new ArgumentNullException(nameof(value));
3434
}
3535

WebAssembly/HashCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace WebAssembly;
44

5-
static class HashCode
5+
internal static class HashCode
66
{
77
public static int Combine(this System.Collections.Generic.IEnumerable<int?> hashCodes)
88
=> Combine(hashCodes.Select(code => code.GetValueOrDefault()));
@@ -26,7 +26,7 @@ public static int Combine(this System.Collections.Generic.IEnumerable<int> hashC
2626
return hash1 + (hash2 * 1566083941);
2727
}
2828

29-
public static int Combine(int h1, int h2) => (((h1 << 5) + h1) ^ h2);
29+
public static int Combine(int h1, int h2) => ((h1 << 5) + h1) ^ h2;
3030

3131
public static int Combine(int h1, int h2, int h3) => Combine(Combine(h1, h2), h3);
3232
}

WebAssembly/Instructions/BranchTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class BranchTable : Instruction, IEquatable<BranchTable>
2525
/// <exception cref="ArgumentNullException">Value cannot be set to null.</exception>
2626
public IList<uint> Labels
2727
{
28-
get => this.labels ??= new List<uint>();
28+
get => this.labels ??= [];
2929
set => this.labels = value ?? throw new ArgumentNullException(nameof(value));
3030
}
3131

WebAssembly/Instructions/LocalGet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal LocalGet(Reader reader)
3838
internal sealed override void Compile(CompilationContext context)
3939
{
4040
if (this.Index >= context.CheckedLocals.Length)
41-
throw new System.IndexOutOfRangeException($"Attempt to get local at index {this.Index} but only {context.CheckedLocals.Length} {(context.CheckedLocals.Length == 1 ? "local was" : "locals were")} defined.");
41+
throw new System.InvalidOperationException($"Attempt to get local at index {this.Index} but only {context.CheckedLocals.Length} {(context.CheckedLocals.Length == 1 ? "local was" : "locals were")} defined.");
4242
context.Stack.Push(context.CheckedLocals[this.Index]);
4343

4444
var localIndex = this.Index - context.CheckedSignature.ParameterTypes.Length;

WebAssembly/Instructions/LocalSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal LocalSet(Reader reader)
3838
internal sealed override void Compile(CompilationContext context)
3939
{
4040
if (this.Index >= context.CheckedLocals.Length)
41-
throw new System.IndexOutOfRangeException($"Attempt to set local at index {this.Index} but only {context.CheckedLocals.Length} {(context.CheckedLocals.Length == 1 ? "local was" : "locals were")} defined.");
41+
throw new System.InvalidOperationException($"Attempt to set local at index {this.Index} but only {context.CheckedLocals.Length} {(context.CheckedLocals.Length == 1 ? "local was" : "locals were")} defined.");
4242
context.PopStackNoReturn(OpCode.LocalSet, context.CheckedLocals[this.Index]);
4343

4444
var localIndex = this.Index - context.CheckedSignature.ParameterTypes.Length;

0 commit comments

Comments
 (0)