Skip to content

Commit

Permalink
.NET 8 and Cleanup (#392)
Browse files Browse the repository at this point in the history
* Update Projects to .NET 8

* Use collection initializers (IDE0028)

* Simplify collection initializers (IDE0300)

* Update docfx.yml to .NET 8

* Update dotnet.yml to .NET 8

* Simplify collection initializers (IDE0301)

* Simplify collection initializers (IDE0302)

* Simplify collection initializers (IDE0305)

* Invalid version format, change X to x

* Revert "Use collection initializers (IDE0028)"

This reverts commit ff24a25.

* Use collection initializers (IDE0028) - but carefully

* Update Artifact Paths

* Revert "Simplify collection initializers (IDE0305)"

This reverts commit b7c0923.

* Edit editorconfig so IDE0305 will not be suggested
  • Loading branch information
Aaron2550 authored Nov 16, 2023
1 parent b97915f commit 83f29d4
Show file tree
Hide file tree
Showing 59 changed files with 126 additions and 120 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,7 @@ insert_final_newline=true
dotnet_style_prefer_simplified_boolean_expressions=true:warning
dotnet_style_prefer_conditional_expression_over_assignment=true:suggestion
dotnet_style_prefer_conditional_expression_over_return=true:suggestion
dotnet_code_quality_unused_parameters=all:warning
dotnet_code_quality_unused_parameters=all:warning

# IDE0305: Simplify collection initializers (IDE0305) - See https://github.com/dotnet/roslyn/issues/70656
dotnet_diagnostic.IDE0305.severity = none
2 changes: 1 addition & 1 deletion .github/workflows/docfx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.103
dotnet-version: 8.0.0
- name: Install DocFX
run: dotnet tool update -g docfx
continue-on-error: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
include-prerelease: true
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release /p:DebugType=None
- name: Rename executables
working-directory: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net7.0/
working-directory: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net8.0/
run: |
mv Obsidian.ConsoleApp.dll ObsidianApp.dll
mv Obsidian.ConsoleApp.deps.json ObsidianApp.deps.json
Expand All @@ -33,7 +33,7 @@ jobs:
uses: actions/[email protected]
with:
name: Obsidian-Nightly-Build
path: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net7.0/
path: /home/runner/work/Obsidian/Obsidian/Obsidian.ConsoleApp/bin/Release/net8.0/
if: ${{ github.event_name == 'push' }} # Only upload artifacts on push, don't upload them for PRs
- name: Discord Webhook Action
uses: tsickert/[email protected]
Expand Down
14 changes: 7 additions & 7 deletions Obsidian.API/AI/AStarPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal class AStarPath

private readonly IWorld world;

private readonly List<Vector> validMoves = new()
{
private readonly List<Vector> validMoves =
[
Vector.Left,
Vector.Right,
Vector.Forwards,
Expand All @@ -43,7 +43,7 @@ internal class AStarPath
Vector.Backwards + Vector.Down,
Vector.Left + Vector.Down,
Vector.Right + Vector.Down,
};
];

public AStarPath(IWorld world)
{
Expand All @@ -58,11 +58,11 @@ public List<Vector> GetPath(Vector startPos, Vector targetPos)
// Out of range?
float distanceSquared = (targetPos - startPos).MagnitudeSquared();
if (distanceSquared > MaxRange * MaxRange)
return new List<Vector>();
return [];


List<Node> openList = new();
List<Node> closedList = new();
List<Node> openList = [];
List<Node> closedList = [];

openList.Add(startNode);

Expand Down Expand Up @@ -130,7 +130,7 @@ public List<Vector> GetPath(Vector startPos, Vector targetPos)
}
}

return new List<Vector>();
return [];
}

private bool IsValidMove(Vector curPos, Vector nextPos)
Expand Down
6 changes: 3 additions & 3 deletions Obsidian.API/Crafting/Builders/ShapedRecipeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public sealed class ShapedRecipeBuilder : BaseRecipeBuilder<ShapedRecipe>, IPatt
{
private readonly CraftingBookCategory category;

private readonly List<string> pattern = new();
private readonly List<string> pattern = [];

private readonly Dictionary<char, Ingredient> key = new();
private readonly Dictionary<char, Ingredient> key = [];

private bool showNotification;

Expand Down Expand Up @@ -61,7 +61,7 @@ public override ShapedRecipe Build()
Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"),
Type = CraftingType.CraftingShaped,
Group = this.Group,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."),
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."),
Pattern = new ReadOnlyCollection<string>(new List<string>(this.pattern)),
Key = new ReadOnlyDictionary<char, Ingredient>(new Dictionary<char, Ingredient>(this.key)),
Category = this.category,
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Crafting/Builders/ShapelessRecipeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class ShapelessRecipeBuilder : BaseRecipeBuilder<ShapelessRecipe>,
{
private readonly CraftingBookCategory category;

private readonly List<Ingredient> ingredients = new();
private readonly List<Ingredient> ingredients = [];

private ShapelessRecipeBuilder(CraftingBookCategory category) => this.category = category;

Expand All @@ -31,7 +31,7 @@ public override ShapelessRecipe Build()
Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"),
Type = CraftingType.CraftingShapeless,
Group = this.Group,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."),
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."),
Ingredients = new ReadOnlyCollection<Ingredient>(new List<Ingredient>(this.ingredients)),
Category = this.category
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public sealed class SmithingTransformRecipeBuilder : BaseRecipeBuilder<SmithingT
IUpgradeIngredientRecipe<SmithingTransformRecipe>,
ITemplateIngredientRecipe<SmithingTransformRecipe>
{
private Ingredient @base = new();
private Ingredient addition = new();
private Ingredient template = new();
private Ingredient @base = [];
private Ingredient addition = [];
private Ingredient template = [];

private SmithingTransformRecipeBuilder() { }

Expand Down Expand Up @@ -55,7 +55,7 @@ public override SmithingTransformRecipe Build()
Base = this.@base,
Addition = this.addition,
Template = template,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set.")
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set.")
};
}
}
2 changes: 1 addition & 1 deletion Obsidian.API/Crafting/Ingredient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Ingredient : IEnumerable<ItemStack>

public Ingredient()
{
this.items = new List<ItemStack>();
this.items = [];
}

public void Add(ItemStack item) => this.items.Add(item);
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.API/Obsidian.API.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<Nullable>enable</Nullable>
<AssemblyName>Obsidian.API</AssemblyName>
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Plugins/PluginBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected void Unload()

private MethodInfo? GetMethod(string methodName, object[] args)
{
args ??= Array.Empty<object>();
args ??= [];
var types = new Type[args.Length];
for (int i = 0; i < args.Length; i++)
{
Expand All @@ -201,7 +201,7 @@ protected void Unload()
private (MethodInfo? method, int parameterCount) GetFriendlyMethod(string methodName, object[] args)
{
typeCache ??= GetType();
args ??= Array.Empty<object>();
args ??= [];
IEnumerable<(MethodInfo method, ParameterInfo[] parameters)> methods = typeCache
.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
.Where(method => method.Name == methodName)
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.API/_Types/BitSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public sealed class BitSet
{
public ReadOnlyMemory<long> DataStorage => data.AsMemory();
private long[] data = Array.Empty<long>();
private long[] data = [];

public void SetBit(int bitIndex, bool value)
{
Expand Down
6 changes: 3 additions & 3 deletions Obsidian.API/_Types/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public static BoundingBox CreateFromPoints(IEnumerable<VectorF> points)

public VectorF[] GetCorners()
{
return new[]
{
return
[
new VectorF(Min.X, Max.Y, Max.Z),
new VectorF(Max.X, Max.Y, Max.Z),
new VectorF(Max.X, Min.Y, Max.Z),
Expand All @@ -94,7 +94,7 @@ public VectorF[] GetCorners()
new VectorF(Max.X, Max.Y, Min.Z),
new VectorF(Max.X, Min.Y, Min.Z),
new VectorF(Min.X, Min.Y, Min.Z)
};
];
}

public override bool Equals(object? obj) => (obj is BoundingBox box) && this.Equals(box);
Expand Down
6 changes: 3 additions & 3 deletions Obsidian.API/_Types/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ public static string ReformatAmpersandPrefixes(string originalText)

public ChatMessage AddChatComponent(ChatMessage message)
{
this.With ??= new();
this.With ??= [];
this.With.Add(message);

return this;
}

public ChatMessage AddChatComponent(IEnumerable<ChatMessage> message)
{
this.With ??= new();
this.With ??= [];
this.With.AddRange(message);

return this;
Expand All @@ -188,7 +188,7 @@ public ChatMessage AddChatComponent(IEnumerable<ChatMessage> message)

public ChatMessage AddExtra(ChatMessage message)
{
Extra ??= new List<ChatMessage>();
Extra ??= [];
Extra.Add(message);

return this;
Expand Down
8 changes: 4 additions & 4 deletions Obsidian.API/_Types/Inventory/ItemMetaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class ItemMetaBuilder

public IReadOnlyList<ChatMessage> Lore { get; }

private readonly Dictionary<EnchantmentType, Enchantment> enchantments = new Dictionary<EnchantmentType, Enchantment>();
private readonly Dictionary<EnchantmentType, Enchantment> storedEnchantments = new Dictionary<EnchantmentType, Enchantment>();
private readonly Dictionary<EnchantmentType, Enchantment> enchantments = [];
private readonly Dictionary<EnchantmentType, Enchantment> storedEnchantments = [];

private readonly List<string> canDestroy = new List<string>();
private readonly List<string> canDestroy = [];

private readonly List<ChatMessage> lore = new List<ChatMessage>();
private readonly List<ChatMessage> lore = [];

public ItemMetaBuilder()
{
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/_Types/MinecraftArgumentTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class MinecraftArgumentTypes
{
// TODO maybe make a Dictionary mapping an enum to a string?
private static string[] mcTypes =
{
[
"brigadier:bool",
"brigadier:double",
"brigadier:float",
Expand Down Expand Up @@ -52,7 +52,7 @@ public class MinecraftArgumentTypes
"minecraft:time",
// OBSIDIAN TYPES
"obsidian:player"
};
];

public static bool IsValidMcType(string? input) => mcTypes.Contains(input);
}
2 changes: 1 addition & 1 deletion Obsidian.API/_Types/Traversal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static float Frac1(float x)
public List<VectorF> Run()
{

List<VectorF> blocks = new List<VectorF>();
List<VectorF> blocks = [];

float tMaxX, tMaxY, tMaxZ, tDeltaX, tDeltaY, tDeltaZ;
VectorF voxel = new VectorF();
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.API/_Types/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public readonly override bool Equals(object? obj)
/// </summary>
public static readonly IEnumerable<Vector> CardinalDirs = new[] { North, South, West, East };

internal static readonly Vector[] AllDirections = new[] { North, South, West, East, Up, Down };
internal static readonly Vector[] AllDirections = [North, South, West, East, Up, Down];

private string GetDebuggerDisplay()
{
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.ConsoleApp/Obsidian.ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.Nbt/NbtCompound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Obsidian.Nbt;

public class NbtCompound : INbtTag, IEnumerable<KeyValuePair<string, INbtTag>>
{
private readonly Dictionary<string, INbtTag> children = new();
private readonly Dictionary<string, INbtTag> children = [];

public int Count => this.children.Count;

Expand Down
2 changes: 1 addition & 1 deletion Obsidian.Nbt/NbtList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Obsidian.Nbt;

public class NbtList : INbtTag, IList<INbtTag>
{
private readonly List<INbtTag> baseList = new();
private readonly List<INbtTag> baseList = [];

public int Count => this.baseList.Count;

Expand Down
2 changes: 1 addition & 1 deletion Obsidian.Nbt/Obsidian.Nbt.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal abstract class AttributeBehaviorBase
public AttributeBehaviorBase(AttributeSyntax attributeSyntax)
{
syntax = attributeSyntax;
arguments = attributeSyntax?.ArgumentList?.Arguments.Select(arg => arg).ToArray() ?? Array.Empty<AttributeArgumentSyntax>();
arguments = attributeSyntax?.ArgumentList?.Arguments.Select(arg => arg).ToArray() ?? [];
}

public virtual bool Matches(AttributeOwner other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static Dictionary<string, FactoryMethod> GetFactoryMethods()
private static FactoryMethod GetFactoryMethod(this Type type)
{
var parameter = Expression.Parameter(typeof(AttributeSyntax));
var ctor = type.GetConstructor(new[] { typeof(AttributeSyntax) });
var ctor = type.GetConstructor([typeof(AttributeSyntax)]);
var lambda = Expression.Lambda<FactoryMethod>(Expression.New(ctor, parameter), parameter);
return lambda.Compile();
}
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.SourceGenerators/Packets/MethodsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal sealed class MethodsRegistry
public IReadOnlyList<Method> WriteMethods => writeMethods;
public IReadOnlyList<Method> ReadMethods => readMethods;

private readonly List<Method> writeMethods = new();
private readonly List<Method> readMethods = new();
private readonly List<Method> writeMethods = [];
private readonly List<Method> readMethods = [];

public bool TryGetWriteMethod(Property property, out Method method)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public void Initialize(GeneratorInitializationContext context)
varInt = new Property
{
Type = "int",
Attributes = new AttributeBehaviorBase[]
{
Attributes =
[
new VarLengthBehavior(null)

Check warning on line 20 in Obsidian.SourceGenerators/Packets/SerializationMethodsGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
},
],
Flags = AttributeFlags.Field | AttributeFlags.VarLength
};
}
Expand Down
Loading

0 comments on commit 83f29d4

Please sign in to comment.