Skip to content

Commit 5168b5c

Browse files
committed
Address some messages
Do some dependency in jection on InterceptLogHandler, no need to hold onto a reference to it as Unity will Remove paramter checks in StreamLogger as StreamWriter does the same checks Ibut keep basic tests for them)
1 parent 505dabc commit 5168b5c

33 files changed

Lines changed: 73 additions & 128 deletions

ModuleManager/Cats/CatAnimator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Diagnostics.CodeAnalysis;
23
using UnityEngine;
34

45
namespace ModuleManager.Cats
@@ -12,9 +13,10 @@ class CatAnimator : MonoBehaviour
1213
private SpriteRenderer spriteRenderer;
1314
private int spriteIdx;
1415

16+
[SuppressMessage("CodeQuality", "IDE0051", Justification = "Called by Unity")]
1517
void Start()
1618
{
17-
spriteRenderer = this.GetComponent<SpriteRenderer>();
19+
spriteRenderer = GetComponent<SpriteRenderer>();
1820
spriteRenderer.sortingOrder = 3;
1921
StartCoroutine(Animate());
2022
}

ModuleManager/Cats/CatManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void LaunchCat()
1414
InitCats();
1515

1616
GameObject cat = LaunchCat(scale);
17-
CatMover catMover = cat.AddComponent<CatMover>();
17+
cat.AddComponent<CatMover>();
1818
}
1919

2020
public static void LaunchCats()

ModuleManager/Cats/CatMover.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Diagnostics.CodeAnalysis;
22
using UnityEngine;
33

44
namespace ModuleManager.Cats
@@ -24,12 +24,13 @@ public class CatMover : MonoBehaviour
2424
private bool clearTrail = false;
2525

2626
// Use this for initialization
27+
[SuppressMessage("CodeQuality", "IDE0051", Justification = "Called by Unity")]
2728
void Start()
2829
{
29-
trail = this.GetComponent<TrailRenderer>();
30+
trail = GetComponent<TrailRenderer>();
3031
trail.sortingOrder = 2;
3132

32-
spriteRenderer = this.GetComponent<SpriteRenderer>();
33+
spriteRenderer = GetComponent<SpriteRenderer>();
3334

3435
offsetY = Mathf.FloorToInt(0.2f * Screen.height);
3536

@@ -41,6 +42,7 @@ void Start()
4142
clearTrail = true;
4243
}
4344

45+
[SuppressMessage("CodeQuality", "IDE0051", Justification = "Called by Unity")]
4446
void Update()
4547
{
4648
if (trail.time <= 0f)

ModuleManager/Cats/CatOrbiter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using KSP.UI;
45
using UnityEngine;
56
using Random = UnityEngine.Random;
@@ -8,7 +9,7 @@ namespace ModuleManager.Cats
89
{
910
class CatOrbiter : MonoBehaviour
1011
{
11-
private static List<CatOrbiter> orbiters = new List<CatOrbiter>();
12+
private static readonly List<CatOrbiter> orbiters = new List<CatOrbiter>();
1213

1314
private static CatOrbiter sun;
1415

@@ -20,7 +21,7 @@ class CatOrbiter : MonoBehaviour
2021
private Vector2d force;
2122
private float scale = 1;
2223

23-
private double G = 6.67408E-11;
24+
private const double G = 6.67408E-11;
2425

2526
public double Mass
2627
{
@@ -113,13 +114,14 @@ private void DoForces()
113114
}
114115
}
115116

116-
117+
[SuppressMessage("CodeQuality", "IDE0051", Justification = "Called by Unity")]
117118
void OnDestroy()
118119
{
119120
orbiters.Remove(this);
120121
TimingManager.FixedUpdateRemove(TimingManager.TimingStage.Earlyish, DoForces);
121122
}
122123

124+
[SuppressMessage("CodeQuality", "IDE0051", Justification = "Called by Unity")]
123125
void FixedUpdate()
124126
{
125127
//if (this == sun)

ModuleManager/Collections/ImmutableStack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ImmutableStack<T> : IEnumerable<T>
88
{
99
public struct Enumerator : IEnumerator<T>
1010
{
11-
private ImmutableStack<T> head;
11+
private readonly ImmutableStack<T> head;
1212
private ImmutableStack<T> currentStack;
1313

1414
public Enumerator(ImmutableStack<T> stack)

ModuleManager/ExceptionIntercept/InterceptLogHandler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ class InterceptLogHandler : ILogHandler
1616

1717
public static string Warnings { get; private set; } = "";
1818

19-
public InterceptLogHandler()
19+
public InterceptLogHandler(ILogHandler baseLogHandler)
2020
{
21-
baseLogHandler = Debug.unityLogger.logHandler;
22-
Debug.unityLogger.logHandler = this;
21+
this.baseLogHandler = baseLogHandler ?? throw new ArgumentNullException(nameof(baseLogHandler));
2322
gamePathLength = Path.GetFullPath(KSPUtil.ApplicationRootPath).Length;
2423
}
2524

ModuleManager/Extensions/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static bool IsBracketBalanced(this string s)
1818
return level == 0;
1919
}
2020

21-
private static Regex whitespaceRegex = new Regex(@"\s+");
21+
private static readonly Regex whitespaceRegex = new Regex(@"\s+");
2222

2323
public static string RemoveWS(this string withWhite)
2424
{

ModuleManager/Fix16.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Collections;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace ModuleManager
45
{
56
class Fix16 : LoadingSystem
67
{
8+
[SuppressMessage("CodeQuality", "IDE0051", Justification = "Called by Unity")]
79
private void Awake()
810
{
911
if (Instance != null)

ModuleManager/Logging/StreamLogger.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ namespace ModuleManager.Logging
55
{
66
public sealed class StreamLogger : IBasicLogger, IDisposable
77
{
8-
private readonly Stream stream;
98
private readonly StreamWriter streamWriter;
109
private bool disposed = false;
1110

1211
public StreamLogger(Stream stream)
1312
{
14-
this.stream = stream ?? throw new ArgumentNullException(nameof(stream));
15-
if (!stream.CanWrite) throw new ArgumentException("must be writable", nameof(stream));
1613
streamWriter = new StreamWriter(stream);
1714
}
1815

ModuleManager/Logging/UnityLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ModuleManager.Logging
55
{
66
public class UnityLogger : IBasicLogger
77
{
8-
private ILogger logger;
8+
private readonly ILogger logger;
99

1010
public UnityLogger(ILogger logger)
1111
{

0 commit comments

Comments
 (0)