Fix some analyzer warnings
also improve globalconfig readability
This commit is contained in:
parent
cdf89f4b09
commit
7d4b21f9c7
|
@ -1,18 +1,29 @@
|
||||||
is_global = true
|
is_global = true
|
||||||
|
|
||||||
# Globalization rules
|
## Globalization rules
|
||||||
dotnet_code_quality.CA1305.excluded_symbol_names = T:System.Byte|T:System.SByte|T:System.Int16|T:System.UInt16|T:System.Int32|T:System.UInt32|T:System.Int64|T:System.UInt64|T:System.String|T:System.Text.StringBuilder|T:System.Convert
|
|
||||||
|
|
||||||
|
# Specify IFormatProvider
|
||||||
dotnet_diagnostic.CA1305.severity = error
|
dotnet_diagnostic.CA1305.severity = error
|
||||||
|
dotnet_code_quality.CA1305.excluded_symbol_names = T:System.Byte|T:System.SByte|T:System.Int16|T:System.UInt16|T:System.Int32|T:System.UInt32|T:System.Int64|T:System.UInt64|T:System.String|T:System.Text.StringBuilder|T:System.Convert
|
||||||
|
# Specify marshalling for P/Invoke string arguments
|
||||||
dotnet_diagnostic.CA2101.severity = suggestion
|
dotnet_diagnostic.CA2101.severity = suggestion
|
||||||
|
|
||||||
# Performance rules
|
## Performance rules
|
||||||
dotnet_code_quality.CA1826.exclude_ordefault_methods = true
|
|
||||||
|
|
||||||
|
# Do not initialize unnecessarily
|
||||||
dotnet_diagnostic.CA1805.severity = silent
|
dotnet_diagnostic.CA1805.severity = silent
|
||||||
|
# Mark members as static
|
||||||
dotnet_diagnostic.CA1822.severity = silent
|
dotnet_diagnostic.CA1822.severity = silent
|
||||||
|
# Use property instead of Linq Enumerable method
|
||||||
|
dotnet_code_quality.CA1826.exclude_ordefault_methods = true
|
||||||
|
# Avoid StringBuilder parameters for P/Invokes
|
||||||
dotnet_diagnostic.CA1838.severity = suggestion
|
dotnet_diagnostic.CA1838.severity = suggestion
|
||||||
|
|
||||||
# Usage rules
|
## Usage rules
|
||||||
|
|
||||||
|
# Call GC.SuppressFinalize correctly
|
||||||
dotnet_diagnostic.CA1816.severity = none
|
dotnet_diagnostic.CA1816.severity = none
|
||||||
|
# Do not raise reserved exception types
|
||||||
dotnet_diagnostic.CA2201.severity = suggestion
|
dotnet_diagnostic.CA2201.severity = suggestion
|
||||||
|
# Implement serialization constructors
|
||||||
|
dotnet_diagnostic.CA2229.severity = silent
|
||||||
|
|
|
@ -461,10 +461,6 @@
|
||||||
<!-- Use the Regex source generator -->
|
<!-- Use the Regex source generator -->
|
||||||
<Rule Id="MA0110" Action="Error" />
|
<Rule Id="MA0110" Action="Error" />
|
||||||
</Rules>
|
</Rules>
|
||||||
<Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.CodeAnalysis.FxCopAnalyzers">
|
|
||||||
<!-- Implement serialization constructors -->
|
|
||||||
<Rule Id="CA2229" Action="Hidden" />
|
|
||||||
</Rules>
|
|
||||||
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers.SpacingRules">
|
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers.SpacingRules">
|
||||||
<!-- Keywords should be spaced correctly -->
|
<!-- Keywords should be spaced correctly -->
|
||||||
<Rule Id="SA1000" Action="Hidden" />
|
<Rule Id="SA1000" Action="Hidden" />
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[*.cs]
|
||||||
|
csharp_using_directive_placement = inside_namespace
|
|
@ -10,9 +10,10 @@
|
||||||
<Import Project="LibCommon.props" />
|
<Import Project="LibCommon.props" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||||
<NoWarn>$(NoWarn)IDE0065;RS2008</NoWarn>
|
<NoWarn>$(NoWarn);RS2008</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<EditorConfigFiles Include="$(MSBuildProjectDirectory)/../Analyzers.editorconfig" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
|
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
|
||||||
<Compile Include="$(MSBuildProjectDirectory)/../AnalyzersCommon/**/*.cs" />
|
<Compile Include="$(MSBuildProjectDirectory)/../AnalyzersCommon/**/*.cs" />
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
namespace BizHawk.SrcGen.ReflectionCache;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -7,61 +9,59 @@ using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
|
|
||||||
namespace BizHawk.SrcGen.ReflectionCache
|
[Generator]
|
||||||
|
public sealed class ReflectionCacheGenerator : ISourceGenerator
|
||||||
{
|
{
|
||||||
[Generator]
|
private sealed class ReflectionCacheGenSyntaxReceiver : ISyntaxReceiver
|
||||||
public sealed class ReflectionCacheGenerator : ISourceGenerator
|
|
||||||
{
|
{
|
||||||
private sealed class ReflectionCacheGenSyntaxReceiver : ISyntaxReceiver
|
/// <remarks>
|
||||||
|
/// I may have just added RNG to the build process...
|
||||||
|
/// Increase this sample size to decrease chance of random failure.
|
||||||
|
/// Alternatively, if you can come up with a better way of getting the project name in <see cref="ISourceGenerator.Execute"/> (I tried like 5 different things), do that instead.
|
||||||
|
/// --yoshi
|
||||||
|
/// </remarks>
|
||||||
|
private const int SAMPLE_SIZE = 20;
|
||||||
|
|
||||||
|
private string? _namespace;
|
||||||
|
|
||||||
|
private readonly List<string> _namespaces = new();
|
||||||
|
|
||||||
|
public string Namespace => _namespace ??= CalcNamespace();
|
||||||
|
|
||||||
|
private string CalcNamespace()
|
||||||
{
|
{
|
||||||
/// <remarks>
|
// black magic wizardry to find common prefix https://stackoverflow.com/a/35081977
|
||||||
/// I may have just added RNG to the build process...
|
var ns = new string(_namespaces[0]
|
||||||
/// Increase this sample size to decrease chance of random failure.
|
.Substring(0, _namespaces.Min(s => s.Length))
|
||||||
/// Alternatively, if you can come up with a better way of getting the project name in <see cref="ISourceGenerator.Execute"/> (I tried like 5 different things), do that instead.
|
.TakeWhile((c, i) => _namespaces.TrueForAll(s => s[i] == c))
|
||||||
/// --yoshi
|
.ToArray());
|
||||||
/// </remarks>
|
return ns[ns.Length - 1] == '.' ? ns.Substring(0, ns.Length - 1) : ns; // trim trailing '.' (can't use BizHawk.Common from Source Generators)
|
||||||
private const int SAMPLE_SIZE = 20;
|
|
||||||
|
|
||||||
private string? _namespace;
|
|
||||||
|
|
||||||
private readonly List<string> _namespaces = new();
|
|
||||||
|
|
||||||
public string Namespace => _namespace ??= CalcNamespace();
|
|
||||||
|
|
||||||
private string CalcNamespace()
|
|
||||||
{
|
|
||||||
// black magic wizardry to find common prefix https://stackoverflow.com/a/35081977
|
|
||||||
var ns = new string(_namespaces[0]
|
|
||||||
.Substring(0, _namespaces.Min(s => s.Length))
|
|
||||||
.TakeWhile((c, i) => _namespaces.TrueForAll(s => s[i] == c))
|
|
||||||
.ToArray());
|
|
||||||
return ns[ns.Length - 1] == '.' ? ns.Substring(0, ns.Length - 1) : ns; // trim trailing '.' (can't use BizHawk.Common from Source Generators)
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
|
||||||
{
|
|
||||||
static string Ser(NameSyntax nameSyn) => nameSyn switch
|
|
||||||
{
|
|
||||||
SimpleNameSyntax simple => simple.Identifier.ValueText,
|
|
||||||
QualifiedNameSyntax qual => $"{Ser(qual.Left)}.{Ser(qual.Right)}",
|
|
||||||
_ => throw new InvalidOperationException()
|
|
||||||
};
|
|
||||||
if (_namespace != null || syntaxNode is not NamespaceDeclarationSyntax syn) return;
|
|
||||||
var newNS = Ser(syn.Name);
|
|
||||||
if (!newNS.StartsWith("BizHawk.", StringComparison.Ordinal)) return;
|
|
||||||
_namespaces.Add(newNS);
|
|
||||||
if (_namespaces.Count == SAMPLE_SIZE) _namespace = CalcNamespace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize(GeneratorInitializationContext context)
|
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
||||||
=> context.RegisterForSyntaxNotifications(() => new ReflectionCacheGenSyntaxReceiver());
|
|
||||||
|
|
||||||
public void Execute(GeneratorExecutionContext context)
|
|
||||||
{
|
{
|
||||||
if (context.SyntaxReceiver is not ReflectionCacheGenSyntaxReceiver receiver) return;
|
static string Ser(NameSyntax nameSyn) => nameSyn switch
|
||||||
var nSpace = receiver.Namespace;
|
{
|
||||||
var src = $@"#nullable enable
|
SimpleNameSyntax simple => simple.Identifier.ValueText,
|
||||||
|
QualifiedNameSyntax qual => $"{Ser(qual.Left)}.{Ser(qual.Right)}",
|
||||||
|
_ => throw new InvalidOperationException()
|
||||||
|
};
|
||||||
|
if (_namespace != null || syntaxNode is not NamespaceDeclarationSyntax syn) return;
|
||||||
|
var newNS = Ser(syn.Name);
|
||||||
|
if (!newNS.StartsWith("BizHawk.", StringComparison.Ordinal)) return;
|
||||||
|
_namespaces.Add(newNS);
|
||||||
|
if (_namespaces.Count == SAMPLE_SIZE) _namespace = CalcNamespace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(GeneratorInitializationContext context)
|
||||||
|
=> context.RegisterForSyntaxNotifications(() => new ReflectionCacheGenSyntaxReceiver());
|
||||||
|
|
||||||
|
public void Execute(GeneratorExecutionContext context)
|
||||||
|
{
|
||||||
|
if (context.SyntaxReceiver is not ReflectionCacheGenSyntaxReceiver receiver) return;
|
||||||
|
var nSpace = receiver.Namespace;
|
||||||
|
var src = $@"#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -103,7 +103,6 @@ namespace {nSpace}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
";
|
";
|
||||||
context.AddSource("ReflectionCache.cs", SourceText.From(src, Encoding.UTF8));
|
context.AddSource("ReflectionCache.cs", SourceText.From(src, Encoding.UTF8));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
using System;
|
namespace BizHawk.SrcGen.VersionInfo;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
namespace BizHawk.SrcGen.VersionInfo;
|
|
||||||
|
|
||||||
[Generator]
|
[Generator]
|
||||||
public class VersionInfoGenerator : ISourceGenerator
|
public class VersionInfoGenerator : ISourceGenerator
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using BizHawk.Client.Common;
|
namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
|
||||||
{
|
{
|
||||||
public partial class TAStudio : IControlMainform
|
public partial class TAStudio : IControlMainform
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
||||||
|
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Emulation.Common;
|
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using BizHawk.BizInvoke;
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using NymaTypes;
|
using NymaTypes;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue