Ensure editorconfig naming styles align with StyleCop SA13XX style rules.
Aligns the naming conventions defined in editorconfig (dotnet_naming_style, dotnet_naming_symbols, dotnet_naming_rule) which are reported under the IDE1006 rule with the existing StyleCop rules from the SA13XX range. This ensures the two rulesets agree when rejecting and accepting naming conventions within the IDE, with a few edges cases where only one ruleset can enforce the convention. IDE1006 allows use to specify a naming convention for type parameters, const locals and protected readonly fields which SA13XX cannot enforce. Some StyleCop SA13XX rules such as SA1309 'Field names should not begin with underscore' are not possible to enforce with the naming rules of IDE1006. Therefore we enable the IDE1006 as a build time warning to enforce conventions and extend them. We disable SA13XX rules that can now be covered by IDE1006 to avoid double-reporting but leave the remaining SA13XX rules that cover additional cases enabled. We also re-enable the SA1311 rule convention but enforce it via IDE1006, requiring some violations to be fixed or duplication of existing suppressions. Most violations fixes are trivial renames with the following exception. In ActorInitializer.cs, we prefer to make the fields private instead. ValueActorInit provides a publicly accessible property for access and OwnerInit provides a publicly accessible method. Health.cs is adjusted to access the property base instead when overriding. The reflection calls must be adjusted to target the base class specifically, as searching for a private field from the derived class will fail to locate it on the base class. Unused suppressions were removed.
This commit is contained in:
@@ -119,8 +119,8 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
// More accurate replacement for Environment.TickCount
|
||||
static readonly Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
public static long RunTime => stopwatch.ElapsedMilliseconds;
|
||||
static readonly Stopwatch Stopwatch = Stopwatch.StartNew();
|
||||
public static long RunTime => Stopwatch.ElapsedMilliseconds;
|
||||
|
||||
public static int RenderFrame = 0;
|
||||
public static int NetFrameNumber => OrderManager.NetFrameNumber;
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace OpenRA
|
||||
|
||||
public abstract class ValueActorInit<T> : ActorInit
|
||||
{
|
||||
protected readonly T value;
|
||||
readonly T value;
|
||||
|
||||
protected ValueActorInit(TraitInfo info, T value)
|
||||
: base(info.InstanceName) { this.value = value; }
|
||||
@@ -159,7 +159,7 @@ namespace OpenRA
|
||||
|
||||
public virtual void Initialize(T value)
|
||||
{
|
||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field = typeof(ValueActorInit<T>).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, value);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ namespace OpenRA
|
||||
public class OwnerInit : ActorInit, ISingleInstanceInit
|
||||
{
|
||||
public readonly string InternalName;
|
||||
protected readonly Player value;
|
||||
readonly Player value;
|
||||
|
||||
public OwnerInit(Player value)
|
||||
{
|
||||
@@ -246,14 +246,14 @@ namespace OpenRA
|
||||
|
||||
public void Initialize(MiniYaml yaml)
|
||||
{
|
||||
var field = GetType().GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance);
|
||||
var field = typeof(OwnerInit).GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, yaml.Value);
|
||||
}
|
||||
|
||||
public void Initialize(Player player)
|
||||
{
|
||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field = typeof(OwnerInit).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, player);
|
||||
}
|
||||
|
||||
@@ -75,11 +75,11 @@ namespace OpenRA
|
||||
/// <summary>Gets or sets the <see cref="CellLayer"/> using cell coordinates</summary>
|
||||
public T this[CPos cell]
|
||||
{
|
||||
get => entries[Index(cell)];
|
||||
get => Entries[Index(cell)];
|
||||
|
||||
set
|
||||
{
|
||||
entries[Index(cell)] = value;
|
||||
Entries[Index(cell)] = value;
|
||||
|
||||
CellEntryChanged?.Invoke(cell);
|
||||
}
|
||||
@@ -88,11 +88,11 @@ namespace OpenRA
|
||||
/// <summary>Gets or sets the layer contents using raw map coordinates (not CPos!)</summary>
|
||||
public T this[MPos uv]
|
||||
{
|
||||
get => entries[Index(uv)];
|
||||
get => Entries[Index(uv)];
|
||||
|
||||
set
|
||||
{
|
||||
entries[Index(uv)] = value;
|
||||
Entries[Index(uv)] = value;
|
||||
|
||||
CellEntryChanged?.Invoke(uv.ToCPos(GridType));
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace OpenRA
|
||||
|
||||
public bool Contains(MPos uv)
|
||||
{
|
||||
return bounds.Contains(uv.U, uv.V);
|
||||
return Bounds.Contains(uv.U, uv.V);
|
||||
}
|
||||
|
||||
public CPos Clamp(CPos uv)
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace OpenRA
|
||||
public readonly Size Size;
|
||||
public readonly MapGridType GridType;
|
||||
|
||||
protected readonly T[] entries;
|
||||
protected readonly Rectangle bounds;
|
||||
protected readonly T[] Entries;
|
||||
protected readonly Rectangle Bounds;
|
||||
|
||||
public CellLayerBase(Map map)
|
||||
: this(map.Grid.Type, new Size(map.MapSize.X, map.MapSize.Y)) { }
|
||||
@@ -30,9 +30,9 @@ namespace OpenRA
|
||||
public CellLayerBase(MapGridType gridType, Size size)
|
||||
{
|
||||
Size = size;
|
||||
bounds = new Rectangle(0, 0, Size.Width, Size.Height);
|
||||
Bounds = new Rectangle(0, 0, Size.Width, Size.Height);
|
||||
GridType = gridType;
|
||||
entries = new T[size.Width * size.Height];
|
||||
Entries = new T[size.Width * size.Height];
|
||||
}
|
||||
|
||||
public virtual void CopyValuesFrom(CellLayerBase<T> anotherLayer)
|
||||
@@ -40,24 +40,24 @@ namespace OpenRA
|
||||
if (Size != anotherLayer.Size || GridType != anotherLayer.GridType)
|
||||
throw new ArgumentException("Layers must have a matching size and shape (grid type).", nameof(anotherLayer));
|
||||
|
||||
Array.Copy(anotherLayer.entries, entries, entries.Length);
|
||||
Array.Copy(anotherLayer.Entries, Entries, Entries.Length);
|
||||
}
|
||||
|
||||
/// <summary>Clears the layer contents with their default value</summary>
|
||||
public virtual void Clear()
|
||||
{
|
||||
Array.Clear(entries, 0, entries.Length);
|
||||
Array.Clear(Entries, 0, Entries.Length);
|
||||
}
|
||||
|
||||
/// <summary>Clears the layer contents with a known value</summary>
|
||||
public virtual void Clear(T clearValue)
|
||||
{
|
||||
Array.Fill(entries, clearValue);
|
||||
Array.Fill(Entries, clearValue);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<T>)entries).GetEnumerator();
|
||||
return ((IEnumerable<T>)Entries).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
|
||||
@@ -38,15 +38,12 @@ namespace OpenRA
|
||||
Remote = 4
|
||||
}
|
||||
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules",
|
||||
"SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter",
|
||||
Justification = "Fields names must match the with the remote API.")]
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules",
|
||||
"SA1304:NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter",
|
||||
Justification = "Fields names must match the with the remote API.")]
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules",
|
||||
"SA1310:FieldNamesMustNotContainUnderscore",
|
||||
Justification = "Fields names must match the with the remote API.")]
|
||||
[SuppressMessage("Style",
|
||||
"IDE1006:Naming Styles",
|
||||
Justification = "Fields names must match the with the remote API.")]
|
||||
public class RemoteMapData
|
||||
{
|
||||
public readonly string title;
|
||||
|
||||
@@ -36,22 +36,22 @@ namespace OpenRA
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get => entries[index];
|
||||
get => Entries[index];
|
||||
|
||||
set => entries[index] = value;
|
||||
set => Entries[index] = value;
|
||||
}
|
||||
|
||||
/// <summary>Gets or sets the layer contents using projected map coordinates.</summary>
|
||||
public T this[PPos uv]
|
||||
{
|
||||
get => entries[Index(uv)];
|
||||
get => Entries[Index(uv)];
|
||||
|
||||
set => entries[Index(uv)] = value;
|
||||
set => Entries[Index(uv)] = value;
|
||||
}
|
||||
|
||||
public bool Contains(PPos uv)
|
||||
{
|
||||
return bounds.Contains(uv.U, uv.V);
|
||||
return Bounds.Contains(uv.U, uv.V);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Network
|
||||
class SyncReport
|
||||
{
|
||||
const int NumSyncReports = 5;
|
||||
static readonly Cache<Type, TypeInfo> typeInfoCache = new Cache<Type, TypeInfo>(t => new TypeInfo(t));
|
||||
static readonly Cache<Type, TypeInfo> TypeInfoCache = new Cache<Type, TypeInfo>(t => new TypeInfo(t));
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace OpenRA.Network
|
||||
{
|
||||
var type = sync.GetType();
|
||||
TypeInfo typeInfo;
|
||||
lock (typeInfoCache)
|
||||
typeInfo = typeInfoCache[type];
|
||||
lock (TypeInfoCache)
|
||||
typeInfo = TypeInfoCache[type];
|
||||
var values = new Values(typeInfo.Names.Length);
|
||||
var index = 0;
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace OpenRA
|
||||
|
||||
public static class Platform
|
||||
{
|
||||
public static PlatformType CurrentPlatform => currentPlatform.Value;
|
||||
public static PlatformType CurrentPlatform => LazyCurrentPlatform.Value;
|
||||
public static readonly Guid SessionGUID = Guid.NewGuid();
|
||||
|
||||
static readonly Lazy<PlatformType> currentPlatform = Exts.Lazy(GetCurrentPlatform);
|
||||
static readonly Lazy<PlatformType> LazyCurrentPlatform = Exts.Lazy(GetCurrentPlatform);
|
||||
|
||||
static bool engineDirAccessed;
|
||||
static string engineDir;
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Mimic a built-in type alias.")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly struct float2 : IEquatable<float2>
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Mimic a built-in type alias.")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly struct float3 : IEquatable<float3>
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Mimic a built-in type alias.")]
|
||||
public readonly struct int2 : IEquatable<int2>
|
||||
{
|
||||
public readonly int X, Y;
|
||||
|
||||
@@ -31,16 +31,16 @@ namespace OpenRA.Support
|
||||
List<PerfTimer> children;
|
||||
long ticks;
|
||||
|
||||
static readonly ThreadLocal<PerfTimer> parentThreadLocal = new ThreadLocal<PerfTimer>();
|
||||
static readonly ThreadLocal<PerfTimer> ParentThreadLocal = new ThreadLocal<PerfTimer>();
|
||||
|
||||
public PerfTimer(string name, float thresholdMs = 0)
|
||||
{
|
||||
this.name = name;
|
||||
this.thresholdMs = thresholdMs;
|
||||
|
||||
parent = parentThreadLocal.Value;
|
||||
parent = ParentThreadLocal.Value;
|
||||
depth = parent == null ? (byte)0 : (byte)(parent.depth + 1);
|
||||
parentThreadLocal.Value = this;
|
||||
ParentThreadLocal.Value = this;
|
||||
|
||||
ticks = Stopwatch.GetTimestamp();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Support
|
||||
{
|
||||
ticks = Stopwatch.GetTimestamp() - ticks;
|
||||
|
||||
parentThreadLocal.Value = parent;
|
||||
ParentThreadLocal.Value = parent;
|
||||
|
||||
if (parent == null)
|
||||
Write();
|
||||
|
||||
@@ -345,7 +345,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ILobbyCustomRulesIgnore { }
|
||||
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")]
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Not a real interface, but more like a tag.")]
|
||||
public interface Requires<T> where T : class, ITraitInfoInterface { }
|
||||
|
||||
public interface IActivityInterface { }
|
||||
|
||||
Reference in New Issue
Block a user