Skip to content

Commit e395ae9

Browse files
committed
Fix code style issues using Claude Code
1 parent 249baea commit e395ae9

40 files changed

Lines changed: 396 additions & 142 deletions

HintServiceMeow.Benchmarks/Benchmarks/HintParserBenchmark.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public IEnumerable<HintParams> GetParameters()
3737

3838
public const float AspectRatio = 16f / 9f;
3939

40-
public List<Hint> hints;
41-
public List<DynamicHint> dynamicHints;
42-
public HintParserArgument hintArg;
43-
public HintParserArgument hintOnlyArg;
44-
public HintParserArgument dynamicHintOnlyArg;
45-
public List<string> testRichTexts;
40+
public List<Hint> hints = null!;
41+
public List<DynamicHint> dynamicHints = null!;
42+
public HintParserArgument hintArg = null!;
43+
public HintParserArgument hintOnlyArg = null!;
44+
public HintParserArgument dynamicHintOnlyArg = null!;
45+
public List<string> testRichTexts = null!;
4646

4747
// Use GlobalSetup instead of the constructor. BenchmarkDotNet calls this
4848
// AFTER injecting the parameters but BEFORE the benchmark starts.

HintServiceMeow.Benchmarks/Benchmarks/RichTextParserBenchmark.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ namespace HintServiceMeow.Benchmarks.Benchmarks
2222
[CategoriesColumn]
2323
public class PhaseBenchmark
2424
{
25-
private string testInput;
26-
private RichTextParserSetting setting;
27-
private RichTextParser parser;
25+
private string testInput = null!;
26+
private RichTextParserSetting setting = null!;
27+
private RichTextParser parser = null!;
2828

2929
// Sink fields — prevent JIT from optimizing away the entire call
3030
private int sink;
@@ -81,16 +81,16 @@ public void TokenizeOnly()
8181
[MemoryDiagnoser]
8282
public class InputProfileBenchmark
8383
{
84-
private string plainText;
85-
private string tagHeavy;
86-
private string longSingleLine;
87-
private string manyShortLines;
88-
private string nestedStyles;
89-
private string colorHeavy;
90-
private string realWorldMixed;
91-
92-
private RichTextParserSetting setting;
93-
private RichTextParser parser;
84+
private string plainText = null!;
85+
private string tagHeavy = null!;
86+
private string longSingleLine = null!;
87+
private string manyShortLines = null!;
88+
private string nestedStyles = null!;
89+
private string colorHeavy = null!;
90+
private string realWorldMixed = null!;
91+
92+
private RichTextParserSetting setting = null!;
93+
private RichTextParser parser = null!;
9494
private int sink;
9595

9696
[GlobalSetup]
@@ -290,8 +290,8 @@ public void TokenizerPool_RentReturn()
290290
[MemoryDiagnoser]
291291
public class AllocationBenchmark
292292
{
293-
private RichTextParserSetting setting;
294-
private RichTextParser parser;
293+
private RichTextParserSetting setting = null!;
294+
private RichTextParser parser = null!;
295295
private int sink;
296296

297297
[GlobalSetup]
@@ -368,9 +368,9 @@ public class ScalabilityBenchmark
368368
[Params(1, 5, 10, 50, 100)]
369369
public int Scale;
370370

371-
private string scaledInput;
372-
private RichTextParserSetting setting;
373-
private RichTextParser parser;
371+
private string scaledInput = null!;
372+
private RichTextParserSetting setting = null!;
373+
private RichTextParser parser = null!;
374374
private int sink;
375375

376376
[GlobalSetup]
@@ -410,10 +410,10 @@ public void Parse_Scaled()
410410
[MemoryDiagnoser]
411411
public class IgnoreTagsBenchmark
412412
{
413-
private string testInput;
414-
private RichTextParserSetting settingNoIgnore;
415-
private RichTextParserSetting settingWithIgnore;
416-
private RichTextParser parser;
413+
private string testInput = null!;
414+
private RichTextParserSetting settingNoIgnore = null!;
415+
private RichTextParserSetting settingWithIgnore = null!;
416+
private RichTextParser parser = null!;
417417
private int sink;
418418

419419
[GlobalSetup]
@@ -471,8 +471,8 @@ public void WithIgnoreTags()
471471
[MemoryDiagnoser]
472472
public class PoolEffectBenchmark
473473
{
474-
private string testInput;
475-
private RichTextParserSetting setting;
474+
private string testInput = null!;
475+
private RichTextParserSetting setting = null!;
476476
private int sink;
477477

478478
[GlobalSetup]

HintServiceMeow.Tests/Core/Utilities/Pools/RichTextParserPoolTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void Return_DoesNotClearParserState_FontSizeStack()
109109

110110
/// <summary>
111111
/// [BUG DETECTION] Return() does not call ClearStatus() on the parser.
112-
/// Expected: After Return and Rent, parser style should be TextStyle.Normal.
112+
/// Expected: After Return and Rent, parser style should be FontStyle.Normal.
113113
/// Actual: Style from previous use is retained.
114114
/// </summary>
115115
[TestMethod]
@@ -119,16 +119,16 @@ public void Return_DoesNotClearParserState_StyleField()
119119
// Arrange
120120
RichTextParserPool pool = RichTextParserPool.Instance;
121121
RichTextParser parser = pool.Rent();
122-
ReflectionHelper.SetFieldValue(parser, "style", TextStyle.Bold);
122+
ReflectionHelper.SetFieldValue(parser, "style", FontStyle.Bold);
123123

124124
// Act
125125
pool.Return(parser);
126126
RichTextParser reused = pool.Rent();
127127

128128
// Assert
129-
TextStyle style = ReflectionHelper.GetFieldValue<TextStyle>(reused, "style");
129+
FontStyle style = ReflectionHelper.GetFieldValue<FontStyle>(reused, "style");
130130
// If this PASSES (style == Normal), the bug is fixed.
131-
Assert.AreEqual(TextStyle.Normal, style,
131+
Assert.AreEqual(FontStyle.Normal, style,
132132
"[BUG] Parser style field not cleared on Return — state leaks between uses");
133133
}
134134

HintServiceMeow/Core/Enum/FontStyle.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
namespace HintServiceMeow.Core.Enum
1+
namespace HintServiceMeow.Core.Enum
22
{
33
using System;
44

5+
/// <summary>
6+
/// Specifies the font style applied to text, supporting bold and italic as flags.
7+
/// </summary>
58
[Flags]
6-
internal enum TextStyle
9+
internal enum FontStyle
710
{
811
Normal = 0x0000,
912
Bold = 0x0001,

HintServiceMeow/Core/Extension/WrapModeExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static HsmWrapMode ToHsmWrapMode(this WrapMode rm)
2424
WrapMode.PingPong => HsmWrapMode.PingPong,
2525
WrapMode.Default => HsmWrapMode.Default,
2626
WrapMode.ClampForever => HsmWrapMode.Once,
27-
_ => throw new System.ArgumentOutOfRangeException(nameof(rm), $"Unexpected WrapMode value: {rm}")
27+
_ => throw new System.ArgumentOutOfRangeException(nameof(rm), $"Unexpected WrapMode value: {rm}"),
2828
};
2929
}
3030

@@ -41,7 +41,7 @@ public static WrapMode ToUnityWrapMode(this HsmWrapMode rm)
4141
HsmWrapMode.Loop => WrapMode.Loop,
4242
HsmWrapMode.PingPong => WrapMode.PingPong,
4343
HsmWrapMode.Default => WrapMode.Default,
44-
_ => throw new System.ArgumentOutOfRangeException(nameof(rm), $"Unexpected HsmWrapMode value: {rm}")
44+
_ => throw new System.ArgumentOutOfRangeException(nameof(rm), $"Unexpected HsmWrapMode value: {rm}"),
4545
};
4646
}
4747
}

HintServiceMeow/Core/Models/HintCollection.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ public AbstractHint[] GetHints(string assemblyName, Func<AbstractHint, bool> pre
127127
}
128128
}
129129

130+
/// <summary>
131+
/// Adds a hint to the collection under the specified assembly group.
132+
/// </summary>
133+
/// <param name="assemblyName">The name of the assembly group to add the hint to.</param>
134+
/// <param name="hint">The hint to add.</param>
130135
internal void AddHint(string assemblyName, AbstractHint hint)
131136
{
132137
lock (collectionLock)
@@ -143,6 +148,13 @@ internal void AddHint(string assemblyName, AbstractHint hint)
143148
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, hint));
144149
}
145150

151+
/// <summary>
152+
/// Removes the specified hint from the collection.
153+
/// If <paramref name="assemblyName"/> is null, the hint is removed from all groups.
154+
/// </summary>
155+
/// <param name="assemblyName">The assembly group to search in, or null to search all groups.</param>
156+
/// <param name="hint">The hint to remove.</param>
157+
/// <returns>true if the hint was found and removed; otherwise false.</returns>
146158
internal bool RemoveHint(string? assemblyName, AbstractHint hint)
147159
{
148160
bool success = false;
@@ -203,6 +215,13 @@ internal bool RemoveHint(string? assemblyName, AbstractHint hint)
203215
return success;
204216
}
205217

218+
/// <summary>
219+
/// Removes all hints satisfying the predicate from the collection.
220+
/// If <paramref name="assemblyName"/> is null, hints are removed from all groups.
221+
/// </summary>
222+
/// <param name="assemblyName">The assembly group to search in, or null to search all groups.</param>
223+
/// <param name="predicate">A function that returns true for hints to remove.</param>
224+
/// <returns>A list of hints that were removed.</returns>
206225
internal List<AbstractHint> RemoveHint(string? assemblyName, Func<AbstractHint, bool> predicate)
207226
{
208227
List<AbstractHint> updatedHints = [];
@@ -277,6 +296,10 @@ internal List<AbstractHint> RemoveHint(string? assemblyName, Func<AbstractHint,
277296
return updatedHints;
278297
}
279298

299+
/// <summary>
300+
/// Clears all hints from the specified assembly group, or from all groups if null.
301+
/// </summary>
302+
/// <param name="assemblyName">The assembly group to clear, or null to clear all groups.</param>
280303
internal void ClearHints(string? assemblyName)
281304
{
282305
lock (collectionLock)

HintServiceMeow/Core/Models/ParameterCollection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class ParameterCollection : IEnumerable<Tuple<string, IParameter>>
1010
private readonly object collectionLock = new object();
1111
private readonly List<Tuple<string, IParameter>> list = new(4);
1212

13-
public ParameterCollection() { }
13+
public ParameterCollection()
14+
{
15+
}
1416

1517
public ParameterCollection(ParameterCollection other)
1618
{

HintServiceMeow/Core/Models/Parser/Style/LineStyle.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,18 @@ public override bool Equals(object? obj)
8484
&& MarginRight == other.MarginRight
8585
&& MaxWidth == other.MaxWidth;
8686
}
87+
88+
/// <inheritdoc/>
89+
public override int GetHashCode()
90+
{
91+
int hash = 17;
92+
hash = (hash * 31) + Alignment.GetHashCode();
93+
hash = (hash * 31) + LineHeight.GetHashCode();
94+
hash = (hash * 31) + Indent.GetHashCode();
95+
hash = (hash * 31) + MarginLeft.GetHashCode();
96+
hash = (hash * 31) + MarginRight.GetHashCode();
97+
hash = (hash * 31) + MaxWidth.GetHashCode();
98+
return hash;
99+
}
87100
}
88101
}

HintServiceMeow/Core/Models/Parser/Style/TextSegmentStyle.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,20 @@ public override bool Equals(object? obj)
313313
&& Font == other.Font
314314
&& FontWeight == other.FontWeight;
315315
}
316+
317+
/// <inheritdoc/>
318+
public override int GetHashCode()
319+
{
320+
int hash = 17;
321+
hash = (hash * 31) + FontSize.GetHashCode();
322+
hash = (hash * 31) + Color.GetHashCode();
323+
hash = (hash * 31) + Alpha.GetHashCode();
324+
hash = (hash * 31) + Bold.GetHashCode();
325+
hash = (hash * 31) + Italic.GetHashCode();
326+
hash = (hash * 31) + Underline.GetHashCode();
327+
hash = (hash * 31) + Strikethrough.GetHashCode();
328+
hash = (hash * 31) + Superscript.GetHashCode();
329+
return hash;
330+
}
316331
}
317332
}

HintServiceMeow/Core/Models/Parser/Token.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public override string ToString()
104104
RichTextTokenType.CloseTag => $"Close(</{TagName}>)",
105105
RichTextTokenType.SelfCloseTag => $"SelfClose(<{TagName}>)",
106106
RichTextTokenType.LineBreak => "Newline",
107-
_ => "Unknown"
107+
_ => "Unknown",
108108
};
109109
}
110110
}

0 commit comments

Comments
 (0)