Skip to content

Commit 5849a69

Browse files
authored
Merge pull request #30921 from huoyaoyuan/netcore-analyzer
Set up-to-date .NET code quality analyzers
2 parents 7592813 + 68e400d commit 5849a69

28 files changed

+182
-176
lines changed

.globalconfig

-57
This file was deleted.

CodeAnalysis/BannedSymbols.txt

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ M:Realms.CollectionExtensions.SubscribeForNotifications`1(System.Collections.Gen
1414
M:System.Threading.Tasks.Task.Wait();Don't use Task.Wait. Use Task.WaitSafely() to ensure we avoid deadlocks.
1515
P:System.Threading.Tasks.Task`1.Result;Don't use Task.Result. Use Task.GetResultSafely() to ensure we avoid deadlocks.
1616
M:System.Threading.ManualResetEventSlim.Wait();Specify a timeout to avoid waiting forever.
17-
M:System.Char.ToLower(System.Char);char.ToLower() changes behaviour depending on CultureInfo.CurrentCulture. Use char.ToLowerInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture.
18-
M:System.Char.ToUpper(System.Char);char.ToUpper() changes behaviour depending on CultureInfo.CurrentCulture. Use char.ToUpperInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture.
19-
M:System.String.ToLower();string.ToLower() changes behaviour depending on CultureInfo.CurrentCulture. Use string.ToLowerInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture or use LocalisableString.
20-
M:System.String.ToUpper();string.ToUpper() changes behaviour depending on CultureInfo.CurrentCulture. Use string.ToUpperInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture or use LocalisableString.
2117
M:Humanizer.InflectorExtensions.Pascalize(System.String);Humanizer's .Pascalize() extension method changes behaviour depending on CultureInfo.CurrentCulture. Use StringDehumanizeExtensions.ToPascalCase() instead.
2218
M:Humanizer.InflectorExtensions.Camelize(System.String);Humanizer's .Camelize() extension method changes behaviour depending on CultureInfo.CurrentCulture. Use StringDehumanizeExtensions.ToCamelCase() instead.
2319
M:Humanizer.InflectorExtensions.Underscore(System.String);Humanizer's .Underscore() extension method changes behaviour depending on CultureInfo.CurrentCulture. Use StringDehumanizeExtensions.ToSnakeCase() instead.

CodeAnalysis/osu.globalconfig

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# .NET Code Style
2+
# IDE styles reference: https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/
3+
is_global = true
4+
5+
# IDE0001: Simplify names
6+
dotnet_diagnostic.IDE0001.severity = warning
7+
8+
# IDE0002: Simplify member access
9+
dotnet_diagnostic.IDE0002.severity = warning
10+
11+
# IDE0003: Remove qualification
12+
dotnet_diagnostic.IDE0003.severity = warning
13+
14+
# IDE0004: Remove unnecessary cast
15+
dotnet_diagnostic.IDE0004.severity = warning
16+
17+
# IDE0005: Remove unnecessary imports
18+
dotnet_diagnostic.IDE0005.severity = warning
19+
20+
# IDE0034: Simplify default literal
21+
dotnet_diagnostic.IDE0034.severity = warning
22+
23+
# IDE0036: Sort modifiers
24+
dotnet_diagnostic.IDE0036.severity = warning
25+
26+
# IDE0040: Add accessibility modifier
27+
dotnet_diagnostic.IDE0040.severity = warning
28+
29+
# IDE0049: Use keyword for type name
30+
dotnet_diagnostic.IDE0040.severity = warning
31+
32+
# IDE0055: Fix formatting
33+
dotnet_diagnostic.IDE0055.severity = warning
34+
35+
# IDE0051: Private method is unused
36+
dotnet_diagnostic.IDE0051.severity = silent
37+
38+
# IDE0052: Private member is unused
39+
dotnet_diagnostic.IDE0052.severity = silent
40+
41+
# IDE0073: File header
42+
dotnet_diagnostic.IDE0073.severity = warning
43+
44+
# IDE0130: Namespace mismatch with folder
45+
dotnet_diagnostic.IDE0130.severity = warning
46+
47+
# IDE1006: Naming style
48+
dotnet_diagnostic.IDE1006.severity = warning
49+
50+
# CA1305: Specify IFormatProvider
51+
# Too many noisy warnings for parsing/formatting numbers
52+
dotnet_diagnostic.CA1305.severity = none
53+
54+
# CA1507: Use nameof to express symbol names
55+
# Flaggs serialization name attributes
56+
dotnet_diagnostic.CA1507.severity = suggestion
57+
58+
# CA1806: Do not ignore method results
59+
# The usages for numeric parsing are explicitly optional
60+
dotnet_diagnostic.CA1806.severity = suggestion
61+
62+
# CA1822: Mark members as static
63+
# Potential false positive around reflection/too much noise
64+
dotnet_diagnostic.CA1822.severity = none
65+
66+
# CA1826: Do not use Enumerable method on indexable collections
67+
dotnet_diagnostic.CA1826.severity = suggestion
68+
69+
# CA1859: Use concrete types when possible for improved performance
70+
# Involves design considerations
71+
dotnet_diagnostic.CA1859.severity = suggestion
72+
73+
# CA1860: Avoid using 'Enumerable.Any()' extension method
74+
dotnet_diagnostic.CA1860.severity = suggestion
75+
76+
# CA1861: Avoid constant arrays as arguments
77+
# Outdated with collection expressions
78+
dotnet_diagnostic.CA1861.severity = suggestion
79+
80+
# CA2007: Consider calling ConfigureAwait on the awaited task
81+
dotnet_diagnostic.CA2007.severity = warning
82+
83+
# CA2016: Forward the 'CancellationToken' parameter to methods
84+
# Some overloads are having special handling for debugger
85+
dotnet_diagnostic.CA2016.severity = suggestion
86+
87+
# CA2021: Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
88+
# Causing a lot of false positives with generics
89+
dotnet_diagnostic.CA2021.severity = none
90+
91+
# CA2101: Specify marshaling for P/Invoke string arguments
92+
# Reports warning for all non-UTF16 usages on DllImport; consider migrating to LibraryImport
93+
dotnet_diagnostic.CA2101.severity = none
94+
95+
# CA2201: Do not raise reserved exception types
96+
dotnet_diagnostic.CA2201.severity = warning
97+
98+
# CA2208: Instantiate argument exceptions correctly
99+
dotnet_diagnostic.CA2208.severity = suggestion
100+
101+
# CA2242: Test for NaN correctly
102+
dotnet_diagnostic.CA2242.severity = warning
103+
104+
# Banned APIs
105+
dotnet_diagnostic.RS0030.severity = error
106+
107+
# Temporarily disable analysing CanBeNull = true in NRT contexts due to mobile issues.
108+
# See: https://github.com/ppy/osu/pull/19677
109+
dotnet_diagnostic.OSUF001.severity = none

CodeAnalysis/osu.ruleset

-58
This file was deleted.

Directory.Build.props

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@
1818
<ItemGroup Label="Code Analysis">
1919
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" PrivateAssets="All" />
2020
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\BannedSymbols.txt" />
21+
<!-- Rider compatibility: .globalconfig needs to be explicitly referenced instead of using the global file name. -->
22+
<GlobalAnalyzerConfigFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\osu.globalconfig" />
2123
</ItemGroup>
2224
<PropertyGroup Label="Code Analysis">
23-
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis\osu.ruleset</CodeAnalysisRuleSet>
25+
<AnalysisMode>Default</AnalysisMode>
26+
<AnalysisModeDesign>Default</AnalysisModeDesign>
27+
<AnalysisModeDocumentation>Recommended</AnalysisModeDocumentation>
28+
<AnalysisModeGlobalization>Recommended</AnalysisModeGlobalization>
29+
<AnalysisModeInteroperability>Recommended</AnalysisModeInteroperability>
30+
<AnalysisModeMaintainability>Recommended</AnalysisModeMaintainability>
31+
<AnalysisModeNaming>Default</AnalysisModeNaming>
32+
<AnalysisModePerformance>Minimum</AnalysisModePerformance>
33+
<AnalysisModeReliability>Recommended</AnalysisModeReliability>
34+
<AnalysisModeSecurity>Default</AnalysisModeSecurity>
35+
<AnalysisModeUsage>Default</AnalysisModeUsage>
2436
</PropertyGroup>
2537
<PropertyGroup Label="Documentation">
2638
<GenerateDocumentationFile>true</GenerateDocumentationFile>

osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
164164

165165
case 1: return colour_cyan;
166166

167-
default: throw new ArgumentOutOfRangeException();
167+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
168168
}
169169

170170
case 3:
@@ -176,7 +176,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
176176

177177
case 2: return colour_cyan;
178178

179-
default: throw new ArgumentOutOfRangeException();
179+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
180180
}
181181

182182
case 4:
@@ -190,7 +190,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
190190

191191
case 3: return colour_purple;
192192

193-
default: throw new ArgumentOutOfRangeException();
193+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
194194
}
195195

196196
case 5:
@@ -206,7 +206,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
206206

207207
case 4: return colour_cyan;
208208

209-
default: throw new ArgumentOutOfRangeException();
209+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
210210
}
211211

212212
case 6:
@@ -224,7 +224,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
224224

225225
case 5: return colour_pink;
226226

227-
default: throw new ArgumentOutOfRangeException();
227+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
228228
}
229229

230230
case 7:
@@ -244,7 +244,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
244244

245245
case 6: return colour_pink;
246246

247-
default: throw new ArgumentOutOfRangeException();
247+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
248248
}
249249

250250
case 8:
@@ -266,7 +266,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
266266

267267
case 7: return colour_purple;
268268

269-
default: throw new ArgumentOutOfRangeException();
269+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
270270
}
271271

272272
case 9:
@@ -290,7 +290,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
290290

291291
case 8: return colour_purple;
292292

293-
default: throw new ArgumentOutOfRangeException();
293+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
294294
}
295295

296296
case 10:
@@ -316,7 +316,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
316316

317317
case 9: return colour_purple;
318318

319-
default: throw new ArgumentOutOfRangeException();
319+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
320320
}
321321
}
322322

@@ -339,7 +339,7 @@ private Color4 getColourForLayout(int columnIndex, StageDefinition stage)
339339

340340
case 5: return colour_green;
341341

342-
default: throw new ArgumentOutOfRangeException();
342+
default: throw new ArgumentOutOfRangeException(nameof(columnIndex));
343343
}
344344
}
345345
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Higher global_level has higher priority, the default global_level
2+
# is 100 for root .globalconfig and 0 for others
3+
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files#precedence
4+
is_global = true
5+
global_level = 101
6+
7+
dotnet_diagnostic.CA2007.severity = none

osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void TestReplayExport()
221221
string? filePath = null;
222222

223223
// Files starting with _ are temporary, created by CreateFileSafely call.
224-
AddUntilStep("wait for export file", () => filePath = LocalStorage.GetFiles("exports").SingleOrDefault(f => !Path.GetFileName(f).StartsWith("_", StringComparison.Ordinal)), () => Is.Not.Null);
224+
AddUntilStep("wait for export file", () => filePath = LocalStorage.GetFiles("exports").SingleOrDefault(f => !Path.GetFileName(f).StartsWith('_')), () => Is.Not.Null);
225225
AddUntilStep("filesize is non-zero", () =>
226226
{
227227
try

osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerParticipantsList.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void TestKickButtonOnlyPresentWhenHost()
198198

199199
AddStep("make second user host", () => MultiplayerClient.TransferHost(3));
200200

201-
AddUntilStep("kick buttons not visible", () => this.ChildrenOfType<ParticipantPanel.KickButton>().Count(d => d.IsPresent) == 0);
201+
AddUntilStep("kick buttons not visible", () => !this.ChildrenOfType<ParticipantPanel.KickButton>().Any(d => d.IsPresent));
202202

203203
AddStep("make local user host again", () => MultiplayerClient.TransferHost(API.LocalUser.Value.Id));
204204

osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void TestDeleteViaRightClick()
151151

152152
AddStep("click delete option", () =>
153153
{
154-
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => i.Item.Text.Value.ToString().ToLowerInvariant() == "delete"));
154+
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => string.Equals(i.Item.Text.Value.ToString(), "delete", System.StringComparison.OrdinalIgnoreCase)));
155155
InputManager.Click(MouseButton.Left);
156156
});
157157

osu.Game.Tests/osu.Game.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<OutputType>WinExe</OutputType>
1313
<TargetFramework>net8.0</TargetFramework>
1414
</PropertyGroup>
15-
<PropertyGroup Label="Code Analysis">
16-
<CodeAnalysisRuleSet>tests.ruleset</CodeAnalysisRuleSet>
17-
</PropertyGroup>
15+
<ItemGroup Label="Code Analysis">
16+
<GlobalAnalyzerConfigFiles Include="CodeAnalysis.tests.globalconfig" />
17+
</ItemGroup>
1818
<ItemGroup Label="Project References">
1919
<ProjectReference Include="..\osu.Game.Rulesets.Osu\osu.Game.Rulesets.Osu.csproj" />
2020
<ProjectReference Include="..\osu.Game.Rulesets.Catch\osu.Game.Rulesets.Catch.csproj" />

0 commit comments

Comments
 (0)