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

Apply FxCop at game side #7238

Merged
merged 12 commits into from
Dec 17, 2019
58 changes: 58 additions & 0 deletions CodeAnalysis/osu.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="osu! Rule Set" Description=" " ToolsVersion="16.0">
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
<Rule Id="CA1016" Action="None" />
<Rule Id="CA1028" Action="None" />
<Rule Id="CA1031" Action="None" />
<Rule Id="CA1034" Action="None" />
<Rule Id="CA1036" Action="None" />
<Rule Id="CA1040" Action="None" />
<Rule Id="CA1044" Action="None" />
<Rule Id="CA1051" Action="None" />
<Rule Id="CA1054" Action="None" />
<Rule Id="CA1056" Action="None" />
<Rule Id="CA1062" Action="None" />
<Rule Id="CA1063" Action="None" />
<Rule Id="CA1067" Action="None" />
<Rule Id="CA1707" Action="None" />
<Rule Id="CA1710" Action="None" />
<Rule Id="CA1714" Action="None" />
<Rule Id="CA1716" Action="None" />
<Rule Id="CA1717" Action="None" />
<Rule Id="CA1720" Action="None" />
<Rule Id="CA1721" Action="None" />
<Rule Id="CA1724" Action="None" />
<Rule Id="CA1801" Action="None" />
<Rule Id="CA1806" Action="None" />
<Rule Id="CA1812" Action="None" />
<Rule Id="CA1814" Action="None" />
<Rule Id="CA1815" Action="None" />
<Rule Id="CA1819" Action="None" />
<Rule Id="CA1822" Action="None" />
<Rule Id="CA1823" Action="None" />
<Rule Id="CA2007" Action="None" />
<Rule Id="CA2214" Action="None" />
<Rule Id="CA2227" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeQuality.CSharp.Analyzers" RuleNamespace="Microsoft.CodeQuality.CSharp.Analyzers">
<Rule Id="CA1001" Action="None" />
<Rule Id="CA1032" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.Analyzers">
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1304" Action="None" />
<Rule Id="CA1305" Action="None" />
<Rule Id="CA1307" Action="None" />
<Rule Id="CA1308" Action="None" />
<Rule Id="CA1816" Action="None" />
<Rule Id="CA1826" Action="None" />
<Rule Id="CA2000" Action="None" />
<Rule Id="CA2008" Action="None" />
<Rule Id="CA2213" Action="None" />
<Rule Id="CA2235" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.CSharp.Analyzers" RuleNamespace="Microsoft.NetCore.CSharp.Analyzers">
<Rule Id="CA1309" Action="Warning" />
<Rule Id="CA2201" Action="Warning" />
</Rules>
</RuleSet>
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<ItemGroup Label="Code Analysis">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="2.9.8" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\BannedSymbols.txt" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Label="Code Analysis">
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis\osu.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Label="Documentation">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Catch/CatchRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using osu.Game.Rulesets.Catch.Difficulty;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Scoring;
using System;

namespace osu.Game.Rulesets.Catch
{
Expand Down Expand Up @@ -114,7 +115,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
};

default:
return new Mod[] { };
return Array.Empty<Mod>();
}
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Mania/ManiaRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
};

default:
return new Mod[] { };
return Array.Empty<Mod>();
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0)
return stage1Bindings.Concat(stage2Bindings);
}

return new KeyBinding[0];
return Array.Empty<KeyBinding>();
}

public override string GetVariantName(int variant)
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Osu/OsuRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using osu.Game.Rulesets.Osu.Skinning;
using osu.Game.Scoring;
using osu.Game.Skinning;
using System;

namespace osu.Game.Rulesets.Osu
{
Expand Down Expand Up @@ -151,7 +152,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
};

default:
return new Mod[] { };
return Array.Empty<Mod>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ private class ProxiedContentContainer : Container
}
}

public abstract class DrawableTaikoHitObject<TaikoHitType> : DrawableTaikoHitObject
where TaikoHitType : TaikoHitObject
public abstract class DrawableTaikoHitObject<TTaikoHit> : DrawableTaikoHitObject
where TTaikoHit : TaikoHitObject
{
public override Vector2 OriginPosition => new Vector2(DrawHeight / 2);

public new TaikoHitType HitObject;
public new TTaikoHit HitObject;

protected readonly Vector2 BaseSize;
protected readonly TaikoPiece MainPiece;

private readonly Container<DrawableStrongNestedHit> strongHitContainer;

protected DrawableTaikoHitObject(TaikoHitType hitObject)
protected DrawableTaikoHitObject(TTaikoHit hitObject)
: base(hitObject)
{
HitObject = hitObject;
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Taiko/TaikoRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using osu.Game.Rulesets.Taiko.Beatmaps;
using osu.Game.Rulesets.Taiko.Difficulty;
using osu.Game.Scoring;
using System;

namespace osu.Game.Rulesets.Taiko
{
Expand Down Expand Up @@ -113,7 +114,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
};

default:
return new Mod[] { };
return Array.Empty<Mod>();
}
}

Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Tests/NonVisual/LimitedCapacityStackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void TestEmptyStack()
{
Assert.AreEqual(0, stack.Count);

Assert.Throws<IndexOutOfRangeException>(() =>
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
int unused = stack[0];
});
Expand Down Expand Up @@ -55,7 +55,7 @@ public void TestInRangeElements(int count)
// e.g. indices 3, 4, 5, 6 (out of range)
for (int i = stack.Count; i < stack.Count + capacity; i++)
{
Assert.Throws<IndexOutOfRangeException>(() =>
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
int unused = stack[i];
});
Expand All @@ -80,7 +80,7 @@ public void TestOverflowElements(int count)
// e.g. indices 3, 4, 5, 6 (out of range)
for (int i = stack.Count; i < stack.Count + capacity; i++)
{
Assert.Throws<IndexOutOfRangeException>(() =>
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
int unused = stack[i];
});
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Visual/Gameplay/TestSceneSkipOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -31,7 +32,7 @@ public void SetUp() => Schedule(() =>
requestCount = 0;
increment = skip_time;

Child = gameplayClockContainer = new GameplayClockContainer(CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)), new Mod[] { }, 0)
Child = gameplayClockContainer = new GameplayClockContainer(CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)), Array.Empty<Mod>(), 0)
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public TestSceneMatchParticipants()
});

AddStep(@"set max", () => Room.MaxParticipants.Value = 10);
AddStep(@"clear users", () => Room.Participants.Value = new User[] { });
AddStep(@"clear users", () => Room.Participants.Value = System.Array.Empty<User>());
AddStep(@"set max to null", () => Room.MaxParticipants.Value = null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class TestSceneUserProfileOverlay : OsuTestScene
},
Title = "osu!volunteer",
Colour = "ff0000",
Achievements = new User.UserAchievement[0],
Achievements = Array.Empty<User.UserAchievement>(),
};

public TestSceneUserProfileOverlay()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TestSceneUserProfilePreviousUsernames()
new User { PreviousUsernames = new[] { "longusername", "longerusername" } },
new User { PreviousUsernames = new[] { "test", "angelsim", "verylongusername" } },
new User { PreviousUsernames = new[] { "ihavenoidea", "howcani", "makethistext", "anylonger" } },
new User { PreviousUsernames = new string[0] },
new User { PreviousUsernames = Array.Empty<string>() },
null
};

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tests/Visual/TestSceneOsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void load(GameHost host, OsuGameBase gameBase)
foreach (var type in requiredGameDependencies)
{
if (game.Dependencies.Get(type) == null)
throw new Exception($"{type} has not been cached");
throw new InvalidOperationException($"{type} has not been cached");
}

return true;
Expand All @@ -121,7 +121,7 @@ private void load(GameHost host, OsuGameBase gameBase)
foreach (var type in requiredGameBaseDependencies)
{
if (gameBase.Dependencies.Get(type) == null)
throw new Exception($"{type} has not been cached");
throw new InvalidOperationException($"{type} has not been cached");
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tournament/Screens/Editors/LadderEditorScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public MenuItem[] ContextMenuItems
get
{
if (editorInfo == null)
return new MenuItem[0];
return Array.Empty<MenuItem>();

return new MenuItem[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public MenuItem[] ContextMenuItems
get
{
if (editorInfo == null)
return new MenuItem[0];
return Array.Empty<MenuItem>();

return new MenuItem[]
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Beatmaps/BeatmapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public string StoredBookmarks
{
if (string.IsNullOrEmpty(value))
{
Bookmarks = new int[0];
Bookmarks = Array.Empty<int>();
return;
}

Expand All @@ -111,7 +111,7 @@ public string StoredBookmarks
}

[NotMapped]
public int[] Bookmarks { get; set; } = new int[0];
public int[] Bookmarks { get; set; } = Array.Empty<int>();

public double DistanceSpacing { get; set; }
public int BeatDivisor { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override IBeatmap GetBeatmap()
}
}

private string getPathForFile(string filename) => BeatmapSetInfo.Files.FirstOrDefault(f => string.Equals(f.Filename, filename, StringComparison.InvariantCultureIgnoreCase))?.FileInfo.StoragePath;
private string getPathForFile(string filename) => BeatmapSetInfo.Files.FirstOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;

private TextureStore textureStore;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public virtual HitSampleInfo ApplyTo(HitSampleInfo hitSampleInfo)

public override bool EquivalentTo(ControlPoint other) =>
other is SampleControlPoint otherTyped &&
string.Equals(SampleBank, otherTyped.SampleBank) && SampleVolume == otherTyped.SampleVolume;
SampleBank == otherTyped.SampleBank && SampleVolume == otherTyped.SampleVolume;
}
}
2 changes: 1 addition & 1 deletion osu.Game/Beatmaps/DummyWorkingBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private class DummyRulesetInfo : RulesetInfo

private class DummyRuleset : Ruleset
{
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[] { };
public override IEnumerable<Mod> GetModsFor(ModType type) => Array.Empty<Mod>();

public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace osu.Game.Database
{
public abstract class MutableDatabaseBackedStoreWithFileIncludes<T, U> : MutableDatabaseBackedStore<T>
where T : class, IHasPrimaryKey, ISoftDelete, IHasFiles<U>
where U : INamedFileInfo
public abstract class MutableDatabaseBackedStoreWithFileIncludes<T, TFileInfo> : MutableDatabaseBackedStore<T>
where T : class, IHasPrimaryKey, ISoftDelete, IHasFiles<TFileInfo>
where TFileInfo : INamedFileInfo
{
protected MutableDatabaseBackedStoreWithFileIncludes(IDatabaseContextFactory contextFactory, Storage storage = null)
: base(contextFactory, storage)
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Graphics/ScreenshotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Task TakeScreenshotAsync() => Task.Run(async () =>
break;

default:
throw new ArgumentOutOfRangeException(nameof(screenshotFormat));
throw new InvalidOperationException($"Unknown enum member {nameof(ScreenshotFormat)} {screenshotFormat.Value}.");
}

notificationOverlay.Post(new SimpleNotification
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace osu.Game.Graphics.UserInterfaceV2
{
public abstract class LabelledComponent<T, U> : LabelledDrawable<T>, IHasCurrentValue<U>
where T : Drawable, IHasCurrentValue<U>
public abstract class LabelledComponent<TDrawable, TValue> : LabelledDrawable<TDrawable>, IHasCurrentValue<TValue>
where TDrawable : Drawable, IHasCurrentValue<TValue>
{
protected LabelledComponent(bool padded)
: base(padded)
{
}

public Bindable<U> Current
public Bindable<TValue> Current
{
get => Component.Current;
set => Component.Current = value;
Expand Down
8 changes: 4 additions & 4 deletions osu.Game/IO/Legacy/SerializationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public IList<T> ReadList<T>()
}

/// <summary> Reads a generic Dictionary from the buffer. </summary>
public IDictionary<T, U> ReadDictionary<T, U>()
public IDictionary<TKey, TValue> ReadDictionary<TKey, TValue>()
{
int count = ReadInt32();
if (count < 0) return null;

IDictionary<T, U> d = new Dictionary<T, U>();
for (int i = 0; i < count; i++) d[(T)ReadObject()] = (U)ReadObject();
IDictionary<TKey, TValue> d = new Dictionary<TKey, TValue>();
for (int i = 0; i < count; i++) d[(TKey)ReadObject()] = (TValue)ReadObject();
return d;
}

Expand Down Expand Up @@ -192,7 +192,7 @@ public object ReadObject()
}
}

public class DynamicDeserializer
public static class DynamicDeserializer
{
private static VersionConfigToNamespaceAssemblyObjectBinder versionBinder;
private static BinaryFormatter formatter;
Expand Down
Loading