Skip to content

Commit 3cb5e2d

Browse files
authored
Lint Cleanup (#853)
* Update namespaces. * Cleanup redundant null suppression/declaration operators. * Cleanup redundant namespace. * Fix misc lint errors. * Configure async inspections.
1 parent 6dc9810 commit 3cb5e2d

File tree

11 files changed

+50
-39
lines changed

11 files changed

+50
-39
lines changed

NWN.Anvil.Samples/src/main/API/Async/NwTaskExamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Anvil.API;
1010
using Anvil.Services;
1111

12-
namespace NWN.Anvil.Samples.Async
12+
namespace NWN.Anvil.Samples.API.Async
1313
{
1414
[ServiceBinding(typeof(NwTaskExamples))]
1515
public class NwTaskExamples

NWN.Anvil.Samples/src/main/API/EngineStructures/CassowaryExamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Anvil.Services;
77
using NLog;
88

9-
namespace NWN.Anvil.Samples.EngineStructures
9+
namespace NWN.Anvil.Samples.API.EngineStructures
1010
{
1111
[ServiceBinding(typeof(CassowaryExamples))]
1212
public class CassowaryExamples

NWN.Anvil.Samples/src/main/API/EngineStructures/EffectExamples.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
using System;
66
using System.Linq;
7+
using System.Threading.Tasks;
78
using Anvil.API;
89
using Anvil.API.Events;
910
using Anvil.Services;
1011

11-
namespace NWN.Anvil.Samples.EngineStructures
12+
namespace NWN.Anvil.Samples.API.EngineStructures
1213
{
1314
[ServiceBinding(typeof(EffectExamples))]
1415
public class EffectExamples
@@ -23,7 +24,7 @@ public EffectExamples()
2324
blindnessEffect.SubType = EffectSubType.Supernatural;
2425

2526
// Register methods to listen for the player/client enter event.
26-
NwModule.Instance.OnClientEnter += RatSummonExample;
27+
NwModule.Instance.OnClientEnter += eventData => _ = RatSummonExample(eventData);
2728

2829
// When entering a specific area, remove all blindness effects:
2930
NwArea? area = NwObject.FindObjectsWithTag<NwArea>("clear_blind").FirstOrDefault();
@@ -40,7 +41,7 @@ public EffectExamples()
4041
/// <summary>
4142
/// Spawns a rat creature summon at the module spawn location when a player connects.
4243
/// </summary>
43-
private async void RatSummonExample(ModuleEvents.OnClientEnter eventData)
44+
private async Task RatSummonExample(ModuleEvents.OnClientEnter eventData)
4445
{
4546
// Create the summon effect.
4647
// Some effects require a "caster" for the effect, and must be made within the caster's context.

NWN.Anvil.Samples/src/main/API/EngineStructures/ItemPropertyExamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Anvil.API.Events;
77
using Anvil.Services;
88

9-
namespace NWN.Anvil.Samples.EngineStructures
9+
namespace NWN.Anvil.Samples.API.EngineStructures
1010
{
1111
[ServiceBinding(typeof(ItemPropertyExamples))]
1212
public class ItemPropertyExamples

NWN.Anvil.Tests/src/main/API/EngineStructures/ItemPropertyTests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public sealed class AcBonusVsDamageTypeTest : ItemPropertyTest
112112

113113
public sealed class AcBonusVsRaceTest : ItemPropertyTest
114114
{
115-
protected override ItemProperty ItemProperty => ItemProperty.ACBonusVsRace(NwRace.FromRacialType(RacialType.Outsider)!, 3);
115+
protected override ItemProperty ItemProperty => ItemProperty.ACBonusVsRace(NwRace.FromRacialType(RacialType.Outsider), 3);
116116
protected override ItemPropertyType PropertyType => ItemPropertyType.AcBonusVsRacialGroup;
117-
protected override int SubType => NwRace.FromRacialType(RacialType.Outsider)!.Id;
117+
protected override int SubType => NwRace.FromRacialType(RacialType.Outsider).Id;
118118
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(2);
119119
protected override int CostTableValue => 3;
120120
}
@@ -163,9 +163,9 @@ public sealed class AttackBonusVsAlignmentGroupTest : ItemPropertyTest
163163

164164
public sealed class AttackBonusVsRaceTest : ItemPropertyTest
165165
{
166-
protected override ItemProperty ItemProperty => ItemProperty.AttackBonusVsRace(NwRace.FromRacialType(RacialType.Halfling)!, 9);
166+
protected override ItemProperty ItemProperty => ItemProperty.AttackBonusVsRace(NwRace.FromRacialType(RacialType.Halfling), 9);
167167
protected override ItemPropertyType PropertyType => ItemPropertyType.AttackBonusVsRacialGroup;
168-
protected override int SubType => NwRace.FromRacialType(RacialType.Halfling)!.Id;
168+
protected override int SubType => NwRace.FromRacialType(RacialType.Halfling).Id;
169169
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(2);
170170
protected override int CostTableValue => 9;
171171
}
@@ -268,9 +268,9 @@ public sealed class DamageBonusVsAlignmentGroupTest : ItemPropertyTest
268268

269269
public sealed class DamageBonusVsRaceTest : ItemPropertyTest
270270
{
271-
protected override ItemProperty ItemProperty => ItemProperty.DamageBonusVsRace(NwRace.FromRacialType(RacialType.Elemental)!, IPDamageType.Bludgeoning, IPDamageBonus.Plus2d6);
271+
protected override ItemProperty ItemProperty => ItemProperty.DamageBonusVsRace(NwRace.FromRacialType(RacialType.Elemental), IPDamageType.Bludgeoning, IPDamageBonus.Plus2d6);
272272
protected override ItemPropertyType PropertyType => ItemPropertyType.DamageBonusVsRacialGroup;
273-
protected override int SubType => NwRace.FromRacialType(RacialType.Elemental)!.Id;
273+
protected override int SubType => NwRace.FromRacialType(RacialType.Elemental).Id;
274274
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(4);
275275
protected override int CostTableValue => (int)IPDamageBonus.Plus2d6;
276276
protected override int Param1TableValue => (int)IPDamageType.Bludgeoning;
@@ -357,9 +357,9 @@ public sealed class DecreaseACTest : ItemPropertyTest
357357

358358
public sealed class DecreaseSkillTest : ItemPropertyTest
359359
{
360-
protected override ItemProperty ItemProperty => ItemProperty.DecreaseSkill(NwSkill.FromSkillType(Skill.Discipline)!, 5);
360+
protected override ItemProperty ItemProperty => ItemProperty.DecreaseSkill(NwSkill.FromSkillType(Skill.Discipline), 5);
361361
protected override ItemPropertyType PropertyType => ItemPropertyType.DecreasedSkillModifier;
362-
protected override int SubType => NwSkill.FromSkillType(Skill.Discipline)!.Id;
362+
protected override int SubType => NwSkill.FromSkillType(Skill.Discipline).Id;
363363
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(21);
364364
protected override int CostTableValue => 5;
365365
}
@@ -383,9 +383,9 @@ public sealed class EnhancementBonusVsAlignmentGroupTest : ItemPropertyTest
383383

384384
public sealed class EnhancementBonusVsRaceTest : ItemPropertyTest
385385
{
386-
protected override ItemProperty ItemProperty => ItemProperty.EnhancementBonusVsRace(NwRace.FromRacialType(RacialType.Dragon)!, 2);
386+
protected override ItemProperty ItemProperty => ItemProperty.EnhancementBonusVsRace(NwRace.FromRacialType(RacialType.Dragon), 2);
387387
protected override ItemPropertyType PropertyType => ItemPropertyType.EnhancementBonusVsRacialGroup;
388-
protected override int SubType => NwRace.FromRacialType(RacialType.Dragon)!.Id;
388+
protected override int SubType => NwRace.FromRacialType(RacialType.Dragon).Id;
389389
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(2);
390390
protected override int CostTableValue => 2;
391391
}
@@ -501,17 +501,17 @@ public sealed class LimitUseByAlignTest : ItemPropertyTest
501501

502502
public sealed class LimitUseByClassTest : ItemPropertyTest
503503
{
504-
protected override ItemProperty ItemProperty => ItemProperty.LimitUseByClass(NwClass.FromClassType(ClassType.Bard)!);
504+
protected override ItemProperty ItemProperty => ItemProperty.LimitUseByClass(NwClass.FromClassType(ClassType.Bard));
505505
protected override ItemPropertyType PropertyType => ItemPropertyType.UseLimitationClass;
506-
protected override int SubType => NwClass.FromClassType(ClassType.Bard)!.Id;
506+
protected override int SubType => NwClass.FromClassType(ClassType.Bard).Id;
507507
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(0);
508508
}
509509

510510
public sealed class LimitUseByRaceTest : ItemPropertyTest
511511
{
512-
protected override ItemProperty ItemProperty => ItemProperty.LimitUseByRace(NwRace.FromRacialType(RacialType.Undead)!);
512+
protected override ItemProperty ItemProperty => ItemProperty.LimitUseByRace(NwRace.FromRacialType(RacialType.Undead));
513513
protected override ItemPropertyType PropertyType => ItemPropertyType.UseLimitationRacialType;
514-
protected override int SubType => NwRace.FromRacialType(RacialType.Undead)!.Id;
514+
protected override int SubType => NwRace.FromRacialType(RacialType.Undead).Id;
515515
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(0);
516516
}
517517

@@ -625,9 +625,9 @@ public sealed class RegenerationTest : ItemPropertyTest
625625

626626
public sealed class SkillBonusTest : ItemPropertyTest
627627
{
628-
protected override ItemProperty ItemProperty => ItemProperty.SkillBonus(NwSkill.FromSkillType(Skill.Persuade)!, 9);
628+
protected override ItemProperty ItemProperty => ItemProperty.SkillBonus(NwSkill.FromSkillType(Skill.Persuade), 9);
629629
protected override ItemPropertyType PropertyType => ItemPropertyType.SkillBonus;
630-
protected override int SubType => NwSkill.FromSkillType(Skill.Persuade)!.Id;
630+
protected override int SubType => NwSkill.FromSkillType(Skill.Persuade).Id;
631631
protected override ItemPropertyCostTablesEntry? CostTable => NwGameTables.ItemPropertyCostTables.ElementAtOrDefault(25);
632632
protected override int CostTableValue => 9;
633633
}

NWN.Anvil.Tests/src/main/API/EngineStructures/TalentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class TalentTests
99
[Test(Description = "Creating a talent and disposing the talent explicitly frees the associated memory.")]
1010
public void CreateAndDisposeTalentFreesNativeStructure()
1111
{
12-
Talent talent = NwSkill.FromSkillType(Skill.Intimidate)!.ToTalent();
12+
Talent talent = NwSkill.FromSkillType(Skill.Intimidate).ToTalent();
1313
Assert.That(talent.IsValid, Is.True, "Talent was not valid after creation.");
1414
talent.Dispose();
1515
Assert.That(talent.IsValid, Is.False, "Talent was still valid after disposing.");

NWN.Anvil.Tests/src/main/API/Objects/NwCreatureTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public void GetFeatRemainingUsesReturnsValidValue()
217217

218218
createdTestObjects.Add(creature);
219219

220-
NwFeat? feat = NwFeat.FromFeatType(Feat.BarbarianRage);
221-
Assert.That(creature.GetFeatRemainingUses(feat!), Is.EqualTo(1));
220+
NwFeat feat = NwFeat.FromFeatType(Feat.BarbarianRage);
221+
Assert.That(creature.GetFeatRemainingUses(feat), Is.EqualTo(1));
222222
}
223223

224224
[Test(Description = "Querying total feat uses returns a valid value.")]
@@ -232,10 +232,10 @@ public void GetFeatTotalUsesReturnsValidValue()
232232

233233
createdTestObjects.Add(creature);
234234

235-
NwFeat? feat = NwFeat.FromFeatType(Feat.BarbarianRage);
235+
NwFeat feat = NwFeat.FromFeatType(Feat.BarbarianRage);
236236

237237
Assert.That(feat, Is.Not.Null, "Could not get feat.");
238-
Assert.That(creature.GetFeatTotalUses(feat!), Is.EqualTo(1));
238+
Assert.That(creature.GetFeatTotalUses(feat), Is.EqualTo(1));
239239
}
240240

241241
[Test(Description = "Setting remaining feat uses correctly updates the creature.")]
@@ -251,14 +251,14 @@ public void SetFeatRemainingUsesCorrectlyUpdatesState(byte uses)
251251
Assert.That(creature!.IsValid, Is.True, "Creature was invalid after creation.");
252252

253253
createdTestObjects.Add(creature);
254-
NwFeat? feat = NwFeat.FromFeatType(Feat.BarbarianRage);
254+
NwFeat feat = NwFeat.FromFeatType(Feat.BarbarianRage);
255255

256256
Assert.That(feat, Is.Not.Null, "Could not get feat.");
257257

258-
creature.SetFeatRemainingUses(feat!, uses);
258+
creature.SetFeatRemainingUses(feat, uses);
259259

260-
Assert.That(creature.GetFeatRemainingUses(feat!), Is.EqualTo(Math.Min(uses, creature.GetFeatTotalUses(feat!))), "Remaining feat uses was not updated after being set.");
261-
Assert.That(creature.HasFeatPrepared(feat!), Is.EqualTo(uses > 0), "Creature incorrectly assumes the feat is/is not available.");
260+
Assert.That(creature.GetFeatRemainingUses(feat), Is.EqualTo(Math.Min(uses, creature.GetFeatTotalUses(feat))), "Remaining feat uses was not updated after being set.");
261+
Assert.That(creature.HasFeatPrepared(feat), Is.EqualTo(uses > 0), "Creature incorrectly assumes the feat is/is not available.");
262262
}
263263

264264
[TestCase(ClassType.Barbarian, 1)]
@@ -290,7 +290,7 @@ public void LevelUpCreatureUpdatesStats(ClassType classType, int levels)
290290
{
291291
Location startLocation = NwModule.Instance.StartingLocation;
292292
NwCreature? creature = NwCreature.Create(StandardResRef.Creature.nw_bandit002, startLocation);
293-
NwClass? nwClass = NwClass.FromClassType(classType);
293+
NwClass nwClass = NwClass.FromClassType(classType);
294294

295295
Assert.That(creature, Is.Not.Null, "Creature was null after creation.");
296296
Assert.That(nwClass, Is.Not.Null, "Class was null after creation.");
@@ -305,7 +305,7 @@ public void LevelUpCreatureUpdatesStats(ClassType classType, int levels)
305305
classLevels = classInfoBefore.Level;
306306
}
307307

308-
creature.LevelUp(nwClass!, levels);
308+
creature.LevelUp(nwClass, levels);
309309

310310
CreatureClassInfo? classInfo = creature.GetClassInfo(nwClass);
311311
Assert.That(classInfo, Is.Not.Null, "Creature did not have class after level up.");

NWN.Anvil.sln.DotSettings

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeTrailingCommaInSinglelineLists/@EntryIndexedValue">SUGGESTION</s:String>
2424
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeTypeMemberModifiers/@EntryIndexedValue">SUGGESTION</s:String>
2525
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeTypeModifiers/@EntryIndexedValue">SUGGESTION</s:String>
26+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncIteratorInvocationWithoutAwaitForeach/@EntryIndexedValue"></s:String>
27+
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncIteratorInvocationWithoutAwaitForeach/@EntryIndexRemoved">True</s:Boolean>
28+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncVoidEventHandlerMethod/@EntryIndexedValue">WARNING</s:String>
29+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncVoidLambda/@EntryIndexedValue"></s:String>
30+
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncVoidLambda/@EntryIndexRemoved">True</s:Boolean>
31+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncVoidMethod/@EntryIndexedValue">WARNING</s:String>
32+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AsyncVoidThrowException/@EntryIndexedValue">WARNING</s:String>
2633
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AutoPropertyCanBeMadeGetOnly_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
2734
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=BadAttributeBracketsSpaces/@EntryIndexedValue">WARNING</s:String>
2835
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=BadBracesSpaces/@EntryIndexedValue">WARNING</s:String>
@@ -84,6 +91,8 @@
8491
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberHidesStaticFromOuterClass/@EntryIndexedValue">HINT</s:String>
8592
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoPattern/@EntryIndexedValue">DO_NOT_SHOW</s:String>
8693
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeSequentialPatterns/@EntryIndexedValue">DO_NOT_SHOW</s:String>
94+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodHasAsyncOverload/@EntryIndexedValue">HINT</s:String>
95+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodHasAsyncOverloadWithCancellation/@EntryIndexedValue">HINT</s:String>
8796
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MissingBlankLines/@EntryIndexedValue">WARNING</s:String>
8897
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MissingIndent/@EntryIndexedValue">WARNING</s:String>
8998
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MissingLinebreak/@EntryIndexedValue">WARNING</s:String>
@@ -121,6 +130,7 @@
121130
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedParameter_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
122131
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedType_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
123132
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseConfigureAwaitFalseForAsyncDisposable/@EntryIndexedValue">WARNING</s:String>
133+
124134
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VariableHidesOuterVariable/@EntryIndexedValue">HINT</s:String>
125135
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VirtualMemberNeverOverridden_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
126136
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongIndentSize/@EntryIndexedValue">WARNING</s:String>

NWN.Anvil/src/main/API/Events/Native/CombatEvents/OnDisarmWeapon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static int OnApplyDisarm(void* pEffectHandler, void* pObject, void* pEff
4141
{
4242
DisarmedObject = gameObject.ToNwObject<NwGameObject>()!,
4343
DisarmedBy = gameEffect.m_oidCreator.ToNwObject<NwGameObject>()!,
44-
Feat = gameEffect.GetInteger(0) == 1 ? NwFeat.FromFeatType(API.Feat.ImprovedDisarm)! : NwFeat.FromFeatType(API.Feat.Disarm)!,
44+
Feat = gameEffect.GetInteger(0) == 1 ? NwFeat.FromFeatType(API.Feat.ImprovedDisarm) : NwFeat.FromFeatType(API.Feat.Disarm),
4545
};
4646

4747
eventData.Result = new Lazy<bool>(() => !eventData.PreventDisarm && Hook.CallOriginal(pEffectHandler, pObject, pEffect, bLoadingGame).ToBool());

NWN.Anvil/src/main/API/Objects/NwCreature.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,9 +1701,9 @@ public int GetBaseSavingThrow(SavingThrow savingThrow)
17011701
/// </summary>
17021702
/// <param name="nwClass">The class with domains. Defaults to <see cref="ClassType.Cleric"/> if not specified.</param>
17031703
/// <returns>An enumeration of this creature's domains.</returns>
1704-
public IEnumerable<NwDomain> GetClassDomains(NwClass? nwClass = default)
1704+
public IEnumerable<NwDomain> GetClassDomains(NwClass? nwClass = null)
17051705
{
1706-
nwClass ??= NwClass.FromClassType(ClassType.Cleric)!;
1706+
nwClass ??= NwClass.FromClassType(ClassType.Cleric);
17071707

17081708
const int error = (int)Domain.Error;
17091709
int classT = nwClass.Id;
@@ -1950,9 +1950,9 @@ public EquipmentSlots GetSlotFromItem(NwItem item)
19501950
/// </summary>
19511951
/// <param name="nwClass">The class to query for specialized spell schools. Defaults to <see cref="ClassType.Wizard"/> if not specified.</param>
19521952
/// <returns>The creature's selected spell specialization.</returns>
1953-
public SpellSchool GetSpecialization(NwClass? nwClass = default)
1953+
public SpellSchool GetSpecialization(NwClass? nwClass = null)
19541954
{
1955-
nwClass ??= NwClass.FromClassType(ClassType.Wizard)!;
1955+
nwClass ??= NwClass.FromClassType(ClassType.Wizard);
19561956
return (SpellSchool)NWScript.GetSpecialization(this, nwClass.Id);
19571957
}
19581958

0 commit comments

Comments
 (0)