Skip to content

Commit

Permalink
Merge branch 'master' into SGB-link
Browse files Browse the repository at this point in the history
  • Loading branch information
Fortranm committed Jul 4, 2024
2 parents 06496c6 + a8b4e76 commit 3e401db
Show file tree
Hide file tree
Showing 1,256 changed files with 778 additions and 1,622 deletions.
38 changes: 29 additions & 9 deletions .global.editorconfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ dotnet_diagnostic.MA0038.severity = silent
# Do not write your own certificate validation method
dotnet_diagnostic.MA0039.severity = error
# Flow the cancellation token
dotnet_diagnostic.MA0040.severity = silent
dotnet_diagnostic.MA0040.severity = error
# Make property static
dotnet_diagnostic.MA0041.severity = silent
# Do not use blocking calls in an async method
dotnet_diagnostic.MA0042.severity = error
# Use nameof operator in ArgumentException
dotnet_diagnostic.MA0043.severity = error
# Remove useless ToString call
dotnet_diagnostic.MA0044.severity = silent
dotnet_diagnostic.MA0044.severity = warning
# Do not use blocking call in a sync method (need to make containing method async)
dotnet_diagnostic.MA0045.severity = silent
# Use EventHandler<T> to declare events
Expand All @@ -213,13 +213,13 @@ dotnet_diagnostic.MA0055.severity = silent
# Do not call overridable members in constructor
dotnet_diagnostic.MA0056.severity = silent
# Class name should end with 'Attribute'
dotnet_diagnostic.MA0057.severity = silent
dotnet_diagnostic.MA0057.severity = error
# Class name should end with 'Exception'
dotnet_diagnostic.MA0058.severity = error
# Class name should end with 'EventArgs'
dotnet_diagnostic.MA0059.severity = silent
# The value returned by Stream.Read/Stream.ReadAsync is not used
dotnet_diagnostic.MA0060.severity = silent
dotnet_diagnostic.MA0060.severity = error
# Method overrides should not change parameter defaults
dotnet_diagnostic.MA0061.severity = silent
# Non-flags enums should not be marked with "FlagsAttribute"
Expand All @@ -239,7 +239,7 @@ dotnet_diagnostic.MA0068.severity = error
# Non-constant static fields should not be visible
dotnet_diagnostic.MA0069.severity = silent
# Obsolete attributes should include explanations
dotnet_diagnostic.MA0070.severity = silent
dotnet_diagnostic.MA0070.severity = warning
# Avoid using redundant else
dotnet_diagnostic.MA0071.severity = silent
# Do not throw from a finally block
Expand All @@ -255,7 +255,7 @@ dotnet_diagnostic.MA0076.severity = silent
# A class that provides Equals(T) should implement IEquatable<T>
dotnet_diagnostic.MA0077.severity = error
# Use 'Cast' instead of 'Select' to cast
dotnet_diagnostic.MA0078.severity = silent
dotnet_diagnostic.MA0078.severity = error
# Flow the cancellation token using .WithCancellation()
dotnet_diagnostic.MA0079.severity = error
# Use a cancellation token using .WithCancellation()
Expand All @@ -279,9 +279,9 @@ dotnet_diagnostic.MA0088.severity = error
# Optimize string method usage
dotnet_diagnostic.MA0089.severity = error
# Remove empty else/finally block
dotnet_diagnostic.MA0090.severity = silent
dotnet_diagnostic.MA0090.severity = warning
# Sender should be 'this' for instance events
dotnet_diagnostic.MA0091.severity = silent
dotnet_diagnostic.MA0091.severity = error
# Sender should be 'null' for static events
dotnet_diagnostic.MA0092.severity = error
# EventArgs should not be null
Expand All @@ -307,7 +307,7 @@ dotnet_diagnostic.MA0102.severity = silent
# Use SequenceEqual instead of equality operator
dotnet_diagnostic.MA0103.severity = error
# Do not create a type with a name from the BCL
dotnet_diagnostic.MA0104.severity = silent
dotnet_diagnostic.MA0104.severity = error
# Use the lambda parameters instead of using a closure
dotnet_diagnostic.MA0105.severity = error
# Avoid closure by using an overload with the 'factoryArgument' parameter
Expand All @@ -320,6 +320,26 @@ dotnet_diagnostic.MA0108.severity = error
dotnet_diagnostic.MA0109.severity = silent
# Use the Regex source generator
dotnet_diagnostic.MA0110.severity = error
# Use 'Count > 0' instead of 'Any()'
dotnet_diagnostic.MA0112.severity = silent
# Raw String contains an implicit end of line character (if you compile on Windows you may get CRLFs in string literals)
dotnet_diagnostic.MA0136.severity = warning
# Both if and else branch have identical code
dotnet_diagnostic.MA0140.severity = warning
# Use pattern matching instead of inequality operators for null check
dotnet_diagnostic.MA0141.severity = silent
# Use pattern matching instead of equality operators for null check
dotnet_diagnostic.MA0142.severity = silent
# Use pattern matching instead of equality operators for discrete value
dotnet_diagnostic.MA0148.severity = silent
# Use pattern matching instead of inequality operators for discrete value
dotnet_diagnostic.MA0149.severity = silent
# Do not use async void methods
dotnet_diagnostic.MA0155.severity = error
# Use 'Async' suffix when a method returns IAsyncEnumerable<T>
dotnet_diagnostic.MA0156.severity = error
# Do not use 'Async' suffix when a method does not return IAsyncEnumerable<T>
dotnet_diagnostic.MA0157.severity = error

## Menees.Analyzers rules

Expand Down
12 changes: 7 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
<PackageVersion Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" />
<PackageVersion Include="Google.FlatBuffers" Version="23.5.26" /> <!-- last version with .NET Standard 2.0 support -->
<PackageVersion Include="ImGui.NET" Version="1.90.6.1" />
<PackageVersion Include="JunitXml.TestLogger" Version="3.0.124" />
<PackageVersion Include="JunitXml.TestLogger" Version="3.1.12" />
<PackageVersion Include="Magick.NET-Q8-AnyCPU" Version="13.9.0" />
<PackageVersion Include="Menees.Analyzers" Version="3.0.10" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.33" />
<PackageVersion Include="Menees.Analyzers" Version="3.2.2" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.159" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="8.0.4" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<PackageVersion Include="MSTest" Version="3.2.2" />
<PackageVersion Include="MSTest" Version="3.4.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Nullable" Version="1.3.1" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
Expand All @@ -26,7 +28,7 @@
<PackageVersion Include="Silk.NET.OpenGL" Version="2.21.0" />
<PackageVersion Include="Silk.NET.WGL.Extensions.NV" Version="2.21.0" />
<PackageVersion Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.8" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" /><!-- don't forget to update .stylecop.json at the same time -->
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" /><!-- don't forget to update .stylecop.json at the same time -->
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Drawing.Common" Version="6.0.0" />
Expand Down
26 changes: 13 additions & 13 deletions Dist/deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
(fetchNuGet { pname = "DotNetAnalyzers.DocumentationAnalyzers.Unstable"; version = "1.0.0.59"; sha256 = "1491q3rby0ysm2bszr33r9h48wk4bz3bz748ziz8p2rklcqrhn5f"; })
(fetchNuGet { pname = "Google.FlatBuffers"; version = "23.5.26"; sha256 = "1yly6bjaqwpyh3f367wa8cr6pdwwpvan5q97xg55r1lfvpbbv51a"; })
(fetchNuGet { pname = "ImGui.NET"; version = "1.90.6.1"; sha256 = "1v1zzlpz3g2h7azqqqhfcwssx9vminnb5pl9880jw28mfk5si1q8"; })
(fetchNuGet { pname = "JunitXml.TestLogger"; version = "3.0.124"; sha256 = "1s70k74bkw0fhfkylak289c2s7l6vijz7n5j64qyw7bjzncqs4n7"; })
(fetchNuGet { pname = "JunitXml.TestLogger"; version = "3.1.12"; sha256 = "1571rs2zpd7az5wp0bklx1h3pac388awlwhz70k0p0vv44h0v5jc"; })
(fetchNuGet { pname = "Menees.Analyzers"; version = "3.0.10"; sha256 = "1fgkr4x8cnjmn6xj106g1y5smc49x9qkmb8c42nx7sqg3lzwqpgb"; })
(fetchNuGet { pname = "Meziantou.Analyzer"; version = "2.0.33"; sha256 = "0lyi217pijxh7jw5xg47ks5r32s77g0xlw9nf42vjbmczfmhk23d"; })
(fetchNuGet { pname = "Microsoft.ApplicationInsights"; version = "2.21.0"; sha256 = "1q034jbqkxb8lddkd0ijp0wp0ymnnf3bg2mjpay027zv7jswnc4x"; })
(fetchNuGet { pname = "Microsoft.ApplicationInsights"; version = "2.22.0"; sha256 = "0h5qkhmazlvwvjmxxj9pp2404rmvk55yf6npwcmlskv9mgfkli4r"; })
(fetchNuGet { pname = "Microsoft.Bcl.AsyncInterfaces"; version = "8.0.0"; sha256 = "0z4jq5prnxyb4p3163yxx35znpd2msjd8hw8ysmv4ah90f5sd9gm"; })
(fetchNuGet { pname = "Microsoft.Bcl.HashCode"; version = "1.1.1"; sha256 = "0xwfph92p92d8hgrdiaka4cazqsjpg4ywfxfx6qbk3939f29kzl0"; })
(fetchNuGet { pname = "Microsoft.CodeCoverage"; version = "17.8.0"; sha256 = "173wjadp3gan4x2jfjchngnc4ca4mb95h1sbb28jydfkfw0z1zvj"; })
(fetchNuGet { pname = "Microsoft.CodeCoverage"; version = "17.10.0"; sha256 = "0s0v7jmrq85n356xv7zixvwa4z94fszjcr5vll8x4im1a2lp00f9"; })
(fetchNuGet { pname = "Microsoft.CSharp"; version = "4.7.0"; sha256 = "0gd67zlw554j098kabg887b5a6pq9kzavpa3jjy5w53ccjzjfy8j"; })
(fetchNuGet { pname = "Microsoft.Data.Sqlite.Core"; version = "8.0.4"; sha256 = "03i9b45n2vnsv4wdsk6qvjzj1ga2hcli168liyrqfa87l54skckd"; })
(fetchNuGet { pname = "Microsoft.DotNet.PlatformAbstractions"; version = "3.1.6"; sha256 = "0b9myd7gqbpaw9pkd2bx45jhik9mwj0f1ss57sk2cxmag2lkdws5"; })
(fetchNuGet { pname = "Microsoft.Extensions.DependencyModel"; version = "8.0.0"; sha256 = "02jnx23hm1vid3yd9pw4gghzn6qkgdl5xfc5r0zrcxdax70rsh5a"; })
(fetchNuGet { pname = "Microsoft.NET.Test.Sdk"; version = "17.8.0"; sha256 = "1syvl3g0hbrcgfi9rq6pld8s8hqqww4dflf1lxn59ccddyyx0gmv"; })
(fetchNuGet { pname = "Microsoft.NET.Test.Sdk"; version = "17.10.0"; sha256 = "13g8fwl09li8fc71nk13dgkb7gahd4qhamyg2xby7am63nlchhdf"; })
(fetchNuGet { pname = "Microsoft.NETCore.Platforms"; version = "1.1.0"; sha256 = "08vh1r12g6ykjygq5d3vq09zylgb84l63k49jc4v8faw9g93iqqm"; })
(fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies"; version = "1.0.3"; sha256 = "0hc4d4d4358g5192mf8faijwk0bpf9pjwcfd3h85sr67j0zhj6hl"; })
(fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies.net48"; version = "1.0.3"; sha256 = "18h4265rn5dy5d1igddsz1ilygcyyj4id4cn2qsr3sz7722k8zla"; })
(fetchNuGet { pname = "Microsoft.Testing.Extensions.Telemetry"; version = "1.0.2"; sha256 = "00psv2mvynd2bz8xnzvqvb32qr33glqxg4ni5j91b93k84yjy5ma"; })
(fetchNuGet { pname = "Microsoft.Testing.Extensions.TrxReport.Abstractions"; version = "1.0.2"; sha256 = "09yn3hi9npgi8rs2vyfyzcl8vbfa1lqcl6lgpymw5d7lg0hc511w"; })
(fetchNuGet { pname = "Microsoft.Testing.Extensions.VSTestBridge"; version = "1.0.2"; sha256 = "0c65fsc23xxw648xh83sjcmrn9hvs9q58l5lb36wflvaajbsjf2r"; })
(fetchNuGet { pname = "Microsoft.Testing.Platform"; version = "1.0.2"; sha256 = "0bq46f4v2r4nzwly7g0dsakyc1lcql9nh85sp59d1fwzaknf1n94"; })
(fetchNuGet { pname = "Microsoft.Testing.Platform.MSBuild"; version = "1.0.2"; sha256 = "1vjqrpqjx3z1irqgy0ckmkgyvrzqqqcikxs36q6gadyj643ra1c5"; })
(fetchNuGet { pname = "Microsoft.Testing.Extensions.Telemetry"; version = "1.2.1"; sha256 = "1a6hyd3szjjpjkbr0ncfria0x2qijv3lwr4drhxm15xamfy23azw"; })
(fetchNuGet { pname = "Microsoft.Testing.Extensions.TrxReport.Abstractions"; version = "1.2.1"; sha256 = "19309m0b9cjy1642m99ipjvr6gxq6qb008bam3l10m1mz8m81j31"; })
(fetchNuGet { pname = "Microsoft.Testing.Extensions.VSTestBridge"; version = "1.2.1"; sha256 = "1bly8375zng21yjbfdi08c14lgapngv06p1dlzbryimxicqzxixx"; })
(fetchNuGet { pname = "Microsoft.Testing.Platform"; version = "1.2.1"; sha256 = "0zlbqmvdb1vxnvmxh6lk65mz57c7mz6dqb1s8in0cfww8kxg058k"; })
(fetchNuGet { pname = "Microsoft.Testing.Platform.MSBuild"; version = "1.2.1"; sha256 = "07674xnhc84h36pvzswx6ibjy0bgfi2bxhqm1zyq9fidmim0ch07"; })
(fetchNuGet { pname = "Microsoft.TestPlatform.ObjectModel"; version = "17.5.0"; sha256 = "0qkjyf3ky6xpjg5is2sdsawm99ka7fzgid2bvpglwmmawqgm8gls"; })
(fetchNuGet { pname = "MSTest"; version = "3.2.2"; sha256 = "19pkywdlmgccv2ri52gbpb3pgci1ymb2ba5qhyp9j19vks6gf6cj"; })
(fetchNuGet { pname = "MSTest.Analyzers"; version = "3.2.2"; sha256 = "1ap7imbqxmz2namgli796pxj91gyn01k6xxnllldpwwbxpd0ijgd"; })
(fetchNuGet { pname = "MSTest.TestAdapter"; version = "3.2.2"; sha256 = "14nrxg1cd3lzaxw7zz8z91168sgnsf1xxnrpdy7wkd6ggk22hi19"; })
(fetchNuGet { pname = "MSTest.TestFramework"; version = "3.2.2"; sha256 = "0igdrjr300bqz5lnibf9vl8pkaky1l27f889gza3a9xs83mpd06p"; })
(fetchNuGet { pname = "MSTest"; version = "3.4.3"; sha256 = "070avma2zdxdpn23a9chgz9n1kglxh8nbb1g2ggzk3xxi5sdjj0n"; })
(fetchNuGet { pname = "MSTest.Analyzers"; version = "3.4.3"; sha256 = "14a6rzh4cvaf9bw63qlxw242fbmk4agyx9qgl19swpciqcaq7pxi"; })
(fetchNuGet { pname = "MSTest.TestAdapter"; version = "3.4.3"; sha256 = "0hsslndnfyb6shgkmgy10f1c9p6b47ry20zr2l1msagmkrk49s5q"; })
(fetchNuGet { pname = "MSTest.TestFramework"; version = "3.4.3"; sha256 = "0hviglzfv16dd3aczny455sy1k0rikzd5w34smfpjyxc0wqx6xvp"; })
(fetchNuGet { pname = "NETStandard.Library"; version = "2.0.3"; sha256 = "1fn9fxppfcg4jgypp2pmrpr6awl3qz1xmnri0cygpkwvyx27df1y"; })
(fetchNuGet { pname = "Newtonsoft.Json"; version = "13.0.3"; sha256 = "0xrwysmrn4midrjal8g2hr1bbg38iyisl0svamb11arqws4w2bw7"; })
(fetchNuGet { pname = "NuGet.Frameworks"; version = "5.11.0"; sha256 = "0wv26gq39hfqw9md32amr5771s73f5zn1z9vs4y77cgynxr73s4z"; })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ void CheckAccessor(AccessorDeclarationSyntax ads)
else
{
if (IncludesFNIAttribute(pds.AttributeLists)) Wat(pds.GetLocation());
#if false // accessors will be checked separately
else foreach (var accessor in pds.AccessorList!.Accessors) CheckAccessor(accessor);
#endif
}
break;
}
Expand Down
3 changes: 3 additions & 0 deletions ExternalProjects/BizHawk.AnalyzersTests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/bin
/obj
/TestResults
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e
config="$1"
shift
dotnet test -c "$config" \
-l "junit;LogFilePath=TestResults/{assembly}.coverage.xml;MethodFormat=Class;FailureBodyFormat=Verbose" \
-l "console;verbosity=detailed" \
"$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace BizHawk.Tests.Analyzers;

using System.Threading.Tasks;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Verify = Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerVerifier<
BizHawk.Analyzers.FeatureNotImplementedAnalyzer,
Microsoft.CodeAnalysis.Testing.DefaultVerifier>;

[TestClass]
public sealed class FeatureNotImplementedAnalyzerTests
{
[TestMethod]
public Task CheckMisuseOfFeatureNotImplementedAttr()
=> Verify.VerifyAnalyzerAsync("""
using System;
using BizHawk.Emulation.Common;
public static class Cases {
[FeatureNotImplemented] private static int X => throw new NotImplementedException();
private static int Y {
[FeatureNotImplemented] get => throw new NotImplementedException();
[FeatureNotImplemented] set => throw new NotImplementedException();
}
[FeatureNotImplemented] private static int Z()
=> throw new NotImplementedException();
{|BHI3300:[FeatureNotImplemented] private static int A => default;|}
private static int B {
{|BHI3300:[FeatureNotImplemented] get => default;|}
{|BHI3300:[FeatureNotImplemented] set => _ = value;|}
}
{|BHI3300:[FeatureNotImplemented] private static int C()
=> default;|}
// wrong exception type, same code but different message:
[FeatureNotImplemented] private static int D => {|BHI3300:throw new InvalidOperationException()|};
private static int E {
[FeatureNotImplemented] get => {|BHI3300:throw new InvalidOperationException()|};
[FeatureNotImplemented] set => {|BHI3300:throw new InvalidOperationException()|};
}
[FeatureNotImplemented] private static int F()
=> {|BHI3300:throw new InvalidOperationException()|};
// same code but different message, since only the simplest of expected syntaxes is checked for:
[FeatureNotImplemented] private static int G => {|BHI3300:throw (new NotImplementedException())|};
private static int H {
[FeatureNotImplemented] get => {|BHI3300:throw (new NotImplementedException())|};
[FeatureNotImplemented] set => {|BHI3300:throw (new NotImplementedException())|};
}
[FeatureNotImplemented] private static int I()
=> {|BHI3300:throw (new NotImplementedException())|};
// the "wat" cases (at least the ones that are reachable in practice)
{|BHI3300:[FeatureNotImplemented] private static int K {
get => default;
set => _ = value;
}|}
}
namespace BizHawk.Emulation.Common {
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
public sealed class FeatureNotImplementedAttribute: Attribute {}
}
""");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace BizHawk.Tests.Analyzers;

using System.Threading.Tasks;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Verify = Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerVerifier<
BizHawk.Analyzers.FirstOrDefaultOnStructAnalyzer,
Microsoft.CodeAnalysis.Testing.DefaultVerifier>;

[TestClass]
public sealed class FirstOrDefaultOnStructAnalyzerTests
{
[TestMethod]
public Task CheckMisuseOfFirstOrDefault()
=> Verify.VerifyAnalyzerAsync("""
using System.Collections.Generic;
using System.Linq;
public static class Cases {
private static string? Y()
=> new[] { 0x80.ToString(), 0x20.ToString(), 0x40.ToString() }.FirstOrDefault(static s => s.Length > 2);
private static string? Z()
=> new List<int> { 0x80, 0x20, 0x40 }.Select(static n => n.ToString()).FirstOrDefault();
private static int A()
=> {|BHI3100:new[] { 0x80, 0x20, 0x40 }.FirstOrDefault()|};
private static int B()
=> {|BHI3100:new List<int> { 0x80, 0x20, 0x40 }.FirstOrDefault()|};
private static int C()
=> {|BHI3100:new[] { 0x80, 0x20, 0x40 }.FirstOrDefault(static n => n.ToString().Length > 2)|};
private static int D()
=> {|BHI3100:new List<int> { 0x80, 0x20, 0x40 }.FirstOrDefault(static n => n.ToString().Length > 2)|};
}
namespace BizHawk.Common.CollectionExtensions {
public static class CollectionExtensions {} // Analyzer short-circuits if this doesn't exist, since that's where the extension lives
}
""");
}
Loading

0 comments on commit 3e401db

Please sign in to comment.