Skip to content

Commit

Permalink
Fix some warnings from Meziantou analyzer (#1668) #minor
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Dec 26, 2023
1 parent 5089b92 commit ed2ee89
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void FieldsCanBeSet() {
var character = ImperatorToCK3.Imperator.Characters.Character.Parse(reader, "42", genesDB);
var spouse1Reader = new BufferedReader(string.Empty);
var spouse2Reader = new BufferedReader(string.Empty);
character.Spouses = new() {
character.Spouses = new Dictionary<ulong, ImperatorToCK3.Imperator.Characters.Character> {
{ 3, ImperatorToCK3.Imperator.Characters.Character.Parse(spouse1Reader, "3", genesDB) },
{ 4, ImperatorToCK3.Imperator.Characters.Character.Parse(spouse2Reader, "4", genesDB) }
};
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CommonUtils/DiffHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ImperatorToCK3.CommonUtils;

internal class DiffHistoryField : IHistoryField {
public string Id { get; }
public List<KeyValuePair<string, object>> InitialEntries { get; } = new();
public IList<KeyValuePair<string, object>> InitialEntries { get; } = new List<KeyValuePair<string, object>>();

public SortedDictionary<Date, List<KeyValuePair<string, object>>> DateToEntriesDict { get; } = new();

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CommonUtils/Genes/AccessoryGeneTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ImperatorToCK3.CommonUtils.Genes;
public class AccessoryGeneTemplate : IIdentifiable<string> {
public string Id { get; }
public uint Index { get; private set; } = 0;
public Dictionary<string, WeightBlock> AgeSexWeightBlocks { get; } = new();
public IDictionary<string, WeightBlock> AgeSexWeightBlocks { get; } = new Dictionary<string, WeightBlock>();

public AccessoryGeneTemplate(string id, BufferedReader reader) {
Id = id;
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CommonUtils/IHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ImperatorToCK3.CommonUtils;

public interface IHistoryField : IIdentifiable<string> {
public List<KeyValuePair<string, object>> InitialEntries { get; }
public IList<KeyValuePair<string, object>> InitialEntries { get; }
public SortedDictionary<Date, List<KeyValuePair<string, object>>> DateToEntriesDict { get; }

public object? GetValue(Date date);
Expand Down
19 changes: 19 additions & 0 deletions ImperatorToCK3/CommonUtils/IListExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace ImperatorToCK3.CommonUtils;

public static class IListExtensions {
public static int RemoveAll<T>(this IList<T> list, Predicate<T> match) {
int count = 0;

for (int i = list.Count - 1; i >= 0; i--) {
if (match(list[i])) {
++count;
list.RemoveAt(i);
}
}

return count;
}
}
2 changes: 1 addition & 1 deletion ImperatorToCK3/CommonUtils/LiteralHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ImperatorToCK3.CommonUtils;

public class LiteralHistoryField : IHistoryField {
public string Id { get; }
public List<KeyValuePair<string, object>> InitialEntries { get; } = new(); // every entry is a <setter, value> pair
public IList<KeyValuePair<string, object>> InitialEntries { get; } = new List<KeyValuePair<string, object>>(); // every entry is a <setter, value> pair

public SortedDictionary<Date, List<KeyValuePair<string, object>>> DateToEntriesDict { get; } = new();

Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CommonUtils/SimpleHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ImperatorToCK3.CommonUtils;

public class SimpleHistoryField : IHistoryField {
public string Id { get; }
public List<KeyValuePair<string, object>> InitialEntries { get; } = new(); // every entry is a <setter, value> pair
public IList<KeyValuePair<string, object>> InitialEntries { get; } = new List<KeyValuePair<string, object>>(); // every entry is a <setter, value> pair

public SortedDictionary<Date, List<KeyValuePair<string, object>>> DateToEntriesDict { get; } = new();

Expand Down
5 changes: 2 additions & 3 deletions ImperatorToCK3/Helpers/RakalyCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace ImperatorToCK3.Helpers;

Expand All @@ -13,10 +12,10 @@ public static class RakalyCaller {
static RakalyCaller() {
string currentDir = Directory.GetCurrentDirectory();
RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-pc-windows-msvc/rakaly.exe";
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
if (OperatingSystem.IsMacOS()) {
RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-apple-darwin/rakaly";
Exec($"chmod +x {currentDir}/{RakalyExecutablePath}");
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
} else if (OperatingSystem.IsLinux()) {
RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-unknown-linux-musl/rakaly";
Exec($"chmod +x {currentDir}/{RakalyExecutablePath}");
}
Expand Down
6 changes: 3 additions & 3 deletions ImperatorToCK3/Imperator/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public bool LinkFamily(FamilyCollection families, SortedSet<ulong>? missingDefin
public bool IsDead => DeathDate is not null;
public string? DeathReason { get; set; }
private HashSet<ulong> parsedSpouseIds = new();
public Dictionary<ulong, Character> Spouses { get; set; } = new();
public IDictionary<ulong, Character> Spouses { get; set; } = new Dictionary<ulong, Character>();
public OrderedSet<ulong> FriendIds { get; } = new();
public OrderedSet<ulong> RivalIds { get; } = new();
private HashSet<ulong> parsedChildrenIds = new();
public Dictionary<ulong, Character> Children { get; set; } = new();
public IDictionary<ulong, Character> Children { get; set; } = new Dictionary<ulong, Character>();
private ulong? parsedMotherId;
public Character? Mother { get; set; }
private ulong? parsedFatherId;
Expand All @@ -85,7 +85,7 @@ public Family? Family {
family = value;
}
}
public List<string> Traits { get; set; } = new();
public IList<string> Traits { get; set; } = new List<string>();
public CharacterAttributes Attributes { get; private set; } = new();
public IReadOnlySet<string> Variables { get; private set; } = ImmutableHashSet<string>.Empty;
public bool IsBald => Variables.Contains("bald");
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/ImperatorToCK3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\Release\ImperatorToCK3\</OutputPath>
<NoWarn>1701;1702;MA0002;MA0006;MA0074</NoWarn>
<NoWarn>1701;1702;MA0002;MA0006;MA0011;MA0074</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\Debug\ImperatorToCK3\</OutputPath>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<NoWarn>1701;1702;MA0002;MA0006;MA0074</NoWarn>
<NoWarn>1701;1702;MA0002;MA0006;MA0011;MA0074</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit ed2ee89

Please sign in to comment.