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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user