Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more code style rules #19871

Merged
merged 7 commits into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 20 additions & 9 deletions .editorconfig
Expand Up @@ -25,12 +25,12 @@ csharp_using_directive_placement = outside_namespace:suggestion
csharp_new_line_before_open_brace = all
csharp_space_around_binary_operators = before_and_after

# Naming styles:
## Naming styles:

dotnet_naming_style.camel_case.capitalization = camel_case
dotnet_naming_style.pascal_case.capitalization = pascal_case

# Symbol specifications:
## Symbol specifications:

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal
Expand All @@ -56,16 +56,19 @@ dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, int

dotnet_naming_symbols.parameters.applicable_kinds = parameter

# Naming rules:
## Naming rules:

# IDE1006, IDE-only counterpart of StyleCopAnalyzers - SA1300: ElementMustBeginWithUpperCaseLetter.
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# IDE1006, IDE-only counterpart of StyleCopAnalyzers - SA1311: StaticReadonlyFieldsMustBeginWithUpperCaseLetter.
dotnet_naming_rule.static_private_or_internal_field_should_be_pascal_case.severity = none
dotnet_naming_rule.static_private_or_internal_field_should_be_pascal_case.symbols = static_private_or_internal_field
dotnet_naming_rule.static_private_or_internal_field_should_be_pascal_case.style = pascal_case

# IDE1006, IDE-only counterpart of StyleCopAnalyzers - SA1303: ConstFieldNamesMustBeginWithUpperCaseLetter.
dotnet_naming_rule.const_private_field_should_be_pascal_case.severity = warning
dotnet_naming_rule.const_private_field_should_be_pascal_case.symbols = const_private_field
dotnet_naming_rule.const_private_field_should_be_pascal_case.style = pascal_case
Expand All @@ -74,15 +77,17 @@ dotnet_naming_rule.const_private_or_internal_field_should_be_pascal_case.severit
dotnet_naming_rule.const_private_or_internal_field_should_be_pascal_case.symbols = internal_field
dotnet_naming_rule.const_private_or_internal_field_should_be_pascal_case.style = pascal_case

# IDE1006, IDE-only counterpart of StyleCopAnalyzers - SA1306: FieldNamesMustBeginWithLowerCaseLetter.
dotnet_naming_rule.private_or_internal_field_should_be_camel_case.severity = warning
dotnet_naming_rule.private_or_internal_field_should_be_camel_case.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_field_should_be_camel_case.style = camel_case

# IDE1006, IDE-only counterpart of StyleCopAnalyzers - SA1313: ParameterNamesMustBeginWithLowerCaseLetter.
dotnet_naming_rule.parameters.severity = warning
dotnet_naming_rule.parameters.symbols = parameters
dotnet_naming_rule.parameters.style = camel_case

# Formatting:
## Formatting:

# Also handled by StyleCopAnalyzers - SA1024: ColonsMustBeSpacedCorrectly.
csharp_space_after_colon_in_inheritance_clause = true
Expand All @@ -99,22 +104,28 @@ csharp_preserve_single_line_blocks = true
# Leave statements and member declarations on the same line.
csharp_preserve_single_line_statements = true

# Also handled by StyleCopAnalyzers - SA1121: UseBuiltInTypeAlias. Also by IDE0049, it seems.
# IDE0049, IDE-only counterpart of StyleCopAnalyzers - SA1121: UseBuiltInTypeAlias.
dotnet_style_predefined_type_for_member_access = true

# Also handled by StyleCopAnalyzers - SA1121: UseBuiltInTypeAlias. Also by IDE0049, it seems.
# IDE0049, IDE-only counterpart of StyleCopAnalyzers - SA1121: UseBuiltInTypeAlias.
dotnet_style_predefined_type_for_locals_parameters_members = true

# Others:
## Others:

# Show an IDE warning when default access modifiers are explicitly specified.
dotnet_style_require_accessibility_modifiers = omit_if_default:warning

# Don't prefer braces (for one liners).
dotnet_diagnostic.IDE0011.severity = silent

# Modifiers are not ordered.
dotnet_diagnostic.IDE0036.severity = warning

# Raise a warning on build when default access modifiers are explicitly specified.
dotnet_diagnostic.IDE0040.severity = warning

# Don't prefer braces (for one liners).
dotnet_diagnostic.IDE0011.severity = none
# Avoid unnecessary zero-length array allocations.
dotnet_diagnostic.CA1825.severity = warning

; 4-column tab indentation
[*.yaml]
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Graphics/HardwarePalette.cs
Expand Up @@ -24,8 +24,8 @@ public sealed class HardwarePalette : IDisposable
readonly Dictionary<string, ImmutablePalette> palettes = new Dictionary<string, ImmutablePalette>();
readonly Dictionary<string, MutablePalette> mutablePalettes = new Dictionary<string, MutablePalette>();
readonly Dictionary<string, int> indices = new Dictionary<string, int>();
byte[] buffer = new byte[0];
float[] colorShiftBuffer = new float[0];
byte[] buffer = Array.Empty<byte>();
float[] colorShiftBuffer = Array.Empty<float>();

public HardwarePalette()
{
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Game/Graphics/SpriteRenderable.cs
Expand Up @@ -9,14 +9,15 @@
*/
#endregion

using System;
using System.Collections.Generic;
using OpenRA.Primitives;

namespace OpenRA.Graphics
{
public class SpriteRenderable : IPalettedRenderable, IModifyableRenderable, IFinalizedRenderable
{
public static readonly IEnumerable<IRenderable> None = new IRenderable[0];
public static readonly IEnumerable<IRenderable> None = Array.Empty<IRenderable>();

readonly Sprite sprite;
readonly WPos pos;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Map/MapPreview.cs
Expand Up @@ -370,11 +370,11 @@ public void UpdateFromMap(IReadOnlyPackage p, IReadOnlyPackage parent, MapClassi
newData.SpawnPoints = spawns.ToArray();
}
else
newData.SpawnPoints = new CPos[0];
newData.SpawnPoints = Array.Empty<CPos>();
}
catch (Exception)
{
newData.SpawnPoints = new CPos[0];
newData.SpawnPoints = Array.Empty<CPos>();
newData.Status = MapStatus.Unavailable;
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Primitives/TypeDictionary.cs
Expand Up @@ -77,7 +77,7 @@ public IEnumerable<T> WithInterface<T>()
{
if (data.TryGetValue(typeof(T), out var objs))
return objs.Cast<T>();
return new T[0];
return Array.Empty<T>();
}

public void Remove<T>(T val)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Scripting/ScriptContext.cs
Expand Up @@ -279,7 +279,7 @@ static IEnumerable<Type> ExtractRequiredTypes(Type t)
return outer.SelectMany(i => i.GetGenericArguments());
}

static readonly object[] NoArguments = new object[0];
static readonly object[] NoArguments = Array.Empty<object>();
Type[] FilterActorCommands(ActorInfo ai)
{
return FilterCommands(ai, knownActorCommands);
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/StreamExts.cs
Expand Up @@ -229,7 +229,7 @@ public static int WriteString(this Stream s, Encoding encoding, string text)
if (!string.IsNullOrEmpty(text))
bytes = encoding.GetBytes(text);
else
bytes = new byte[0];
bytes = Array.Empty<byte>();

s.Write(bytes.Length);
s.WriteArray(bytes);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Traits/Player/FrozenActorLayer.cs
Expand Up @@ -72,8 +72,8 @@ public class FrozenActor

public Polygon MouseBounds = Polygon.Empty;

static readonly IRenderable[] NoRenderables = new IRenderable[0];
static readonly Rectangle[] NoBounds = new Rectangle[0];
static readonly IRenderable[] NoRenderables = Array.Empty<IRenderable>();
static readonly Rectangle[] NoBounds = Array.Empty<Rectangle>();

int flashTicks;
TintModifiers flashModifiers;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Traits/World/ScreenMap.cs
Expand Up @@ -41,7 +41,7 @@ public class ScreenMapInfo : TraitInfo

public class ScreenMap : IWorldLoaded
{
static readonly IEnumerable<FrozenActor> NoFrozenActors = new FrozenActor[0];
static readonly IEnumerable<FrozenActor> NoFrozenActors = Array.Empty<FrozenActor>();
readonly Func<FrozenActor, bool> frozenActorIsValid = fa => fa.IsValid;
readonly Func<Actor, bool> actorIsInWorld = a => a.IsInWorld;
readonly Func<Actor, ActorBoundsPair> selectActorAndBounds;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/World.cs
Expand Up @@ -51,7 +51,7 @@ public sealed class World : IDisposable
public LongBitSet<PlayerBitMask> AllPlayersMask = default(LongBitSet<PlayerBitMask>);
public readonly LongBitSet<PlayerBitMask> NoPlayersMask = default(LongBitSet<PlayerBitMask>);

public Player[] Players = new Player[0];
public Player[] Players = Array.Empty<Player>();

public event Action<Player> RenderPlayerChanged;

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs
Expand Up @@ -58,7 +58,7 @@ public TeslaZapRenderable(WPos pos, int zOffset, in WVec length, string image, s

cachedPos = WPos.Zero;
cachedLength = WVec.Zero;
cache = new IFinalizedRenderable[] { };
cache = Array.Empty<IFinalizedRenderable>();
}

public WPos Pos => pos;
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.IO;
using OpenRA.Graphics;
using OpenRA.Primitives;
Expand All @@ -32,7 +33,7 @@ public TmpRAFrame(byte[] data, Size size)
Data = data;

if (data == null)
Data = new byte[0];
Data = Array.Empty<byte>();
else
Size = size;
}
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.IO;
using OpenRA.Graphics;
using OpenRA.Primitives;
Expand All @@ -32,7 +33,7 @@ public TmpTDFrame(byte[] data, Size size)
Data = data;

if (data == null)
Data = new byte[0];
Data = Array.Empty<byte>();
else
Size = size;
}
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.IO;
using OpenRA.Graphics;
using OpenRA.Primitives;
Expand Down Expand Up @@ -109,7 +110,7 @@ public TmpTSFrame(Stream s, Size size, int u, int v)
}
}
else
Data = new byte[0];
Data = Array.Empty<byte>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs
Expand Up @@ -50,7 +50,7 @@ void IUtilityCommand.Run(Utility utility, string[] args)
Game.ModData = destModData;
var destPaletteInfo = destModData.DefaultRules.Actors[SystemActors.Player].TraitInfo<PlayerColorPaletteInfo>();
var destRemapIndex = destPaletteInfo.RemapIndex;
var shadowIndex = new int[] { };
var shadowIndex = Array.Empty<int>();

// the remap range is always 16 entries, but their location and order changes
for (var i = 0; i < 16; i++)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Air/Land.cs
Expand Up @@ -54,7 +54,7 @@ public Land(Actor self, in Target target, WDist landRange, in WVec offset, WAngl
aircraft = self.Trait<Aircraft>();
this.target = target;
this.offset = offset;
this.clearCells = clearCells ?? new CPos[0];
this.clearCells = clearCells ?? Array.Empty<CPos>();
this.landRange = landRange.Length >= 0 ? landRange : aircraft.Info.LandRange;
this.targetLineColor = targetLineColor;

Expand Down
5 changes: 3 additions & 2 deletions OpenRA.Mods.Common/Effects/SpawnActorEffect.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Effects;
Expand All @@ -26,10 +27,10 @@ public class SpawnActorEffect : IEffect
int remainingDelay;

public SpawnActorEffect(Actor actor)
: this(actor, 0, new CPos[0], null) { }
: this(actor, 0, Array.Empty<CPos>(), null) { }

public SpawnActorEffect(Actor actor, int delay)
: this(actor, delay, new CPos[0], null) { }
: this(actor, delay, Array.Empty<CPos>(), null) { }

public SpawnActorEffect(Actor actor, int delay, CPos[] pathAfterSpawn, Activity activityAtDestination)
{
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -78,7 +79,7 @@ public class TgaFrame : ISpriteFrame

public TgaFrame()
{
Data = new byte[0];
Data = Array.Empty<byte>();
}

public TgaFrame(Stream stream)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Expand Up @@ -64,7 +64,7 @@ public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
throw new YamlException("Facing tolerance must be in range of [0, 512], 512 covers 360 degrees.");
}

public override abstract object Create(ActorInitializer init);
public abstract override object Create(ActorInitializer init);
}

public abstract class AttackBase : PausableConditionalTrait<AttackBaseInfo>, ITick, IIssueOrder, IResolveOrder, IOrderVoice, ISync
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackFrontal.cs
Expand Up @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
public class AttackFrontalInfo : AttackBaseInfo, Requires<IFacingInfo>
{
[Desc("Tolerance for attack angle. Range [0, 512], 512 covers 360 degrees.")]
public readonly new WAngle FacingTolerance = WAngle.Zero;
public new readonly WAngle FacingTolerance = WAngle.Zero;

public override object Create(ActorInitializer init) { return new AttackFrontal(init.Self, this); }
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs
Expand Up @@ -77,7 +77,7 @@ public override void RulesetLoaded(Ruleset rules, ActorInfo ai)

public class AttackGarrisoned : AttackFollow, INotifyPassengerEntered, INotifyPassengerExited, IRender
{
public readonly new AttackGarrisonedInfo Info;
public new readonly AttackGarrisonedInfo Info;
Lazy<BodyOrientation> coords;
List<Armament> armaments;
List<AnimationWithOffset> muzzles;
Expand Down
5 changes: 3 additions & 2 deletions OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
Expand All @@ -27,7 +28,7 @@ public class LineBuildParentInit : ValueActorInit<string[]>, ISingleInstanceInit
readonly Actor[] parents = null;

public LineBuildParentInit(Actor[] value)
: base(new string[0])
: base(Array.Empty<string>())
{
parents = value;
}
Expand Down Expand Up @@ -70,7 +71,7 @@ public class LineBuildInfo : TraitInfo
public class LineBuild : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyLineBuildSegmentsChanged
{
readonly LineBuildInfo info;
readonly Actor[] parentNodes = new Actor[0];
readonly Actor[] parentNodes = Array.Empty<Actor>();
HashSet<Actor> segments;

public LineBuild(ActorInitializer init, LineBuildInfo info)
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/Immobile.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.Collections.Generic;
using OpenRA.Traits;

Expand Down Expand Up @@ -46,7 +47,7 @@ public Immobile(ActorInitializer init, ImmobileInfo info)
if (info.OccupiesSpace)
occupied = new[] { (TopLeft, SubCell.FullCell) };
else
occupied = new (CPos, SubCell)[0];
occupied = Array.Empty<(CPos, SubCell)>();
}

public CPos TopLeft => location;
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/Targetable.cs
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
Expand All @@ -29,7 +30,7 @@ public class TargetableInfo : ConditionalTraitInfo, ITargetableInfo

public class Targetable : ConditionalTrait<TargetableInfo>, ITargetable
{
protected static readonly string[] None = new string[] { };
protected static readonly string[] None = Array.Empty<string>();
protected Cloak[] cloaks;

public Targetable(Actor self, TargetableInfo info)
Expand Down
Expand Up @@ -35,7 +35,7 @@ void IUtilityCommand.Run(Utility utility, string[] args)
var modData = Game.ModData = utility.ModData;

var src = args[1];
var shadowIndex = new int[] { };
var shadowIndex = Array.Empty<int>();
if (args.Contains("--noshadow"))
{
Array.Resize(ref shadowIndex, shadowIndex.Length + 3);
Expand Down