Added a rule for unused usings to OpenRA.ruleset

Unfortunately due to bugs in the analyzers or something else, the IDE0005 doesn't work as expected. The "officially suggested" workaround is to enable XML documentation generation to trigger IDE0005 during compiling. Then we need to add three more rules to silence the warnings that come from the XML documentation generation. We also need to enable code style enforcing on build for all of this to work.
Known issue is that all of this produces a bunch (tens to hundreds) of obscure analyzer warnings on older versions of Visual Studio, but those seem to not be causing issues.
This commit is contained in:
penev92
2021-10-14 02:33:14 +03:00
committed by abcdefg30
parent 8ba6d13b2f
commit e1e76411f7
3 changed files with 22 additions and 3 deletions

View File

@@ -99,9 +99,11 @@ check:
@echo
@echo "Compiling in Debug mode..."
ifeq ($(RUNTIME), mono)
@$(MSBUILD) -t:build -restore -p:Configuration=Debug -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:Mono=true
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
@$(MSBUILD) -t:build -restore -p:Configuration=Debug -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:Mono=true -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
else
@$(DOTNET) build -c Debug -nologo -warnaserror -p:TargetPlatform=$(TARGETPLATFORM)
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
@$(DOTNET) build -c Debug -nologo -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
endif
ifeq ($(TARGETPLATFORM), unix-generic)
@./configure-system-libraries.sh

View File

@@ -1,8 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="OpenRA Code Style" ToolsVersion="14.0">
<IncludeAll Action="Warning" />
<!-- Rules related to generating XML documentation that we need to silence. -->
<!-- These are here because of GenerateDocumentationFile, which is a workaround for forcing rule IDE0005 to work outside of an IDE. -->
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp" RuleNamespace="Microsoft.CodeAnalysis.CSharp">
<Rule Id="CS1570" Action="None" /><!-- Invalid XML in XML comment. -->
<Rule Id="CS1573" Action="None" /><!-- Parameter has no matching param tag in the XML comment. -->
<Rule Id="CS1591" Action="None" /><!-- Missing XML comment for publicly visible type or member. -->
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.CodeStyle" RuleNamespace="Microsoft.CodeAnalysis.CSharp.CodeStyle">
<Rule Id="IDE0005" Action="Warning" /><!-- Using directive is unnecessary. -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SX1101" Action="Warning" /><!-- DoNotPrefixLocalMembersWithThis -->
<!-- Rules that conflict with OpenRA project style conventions -->
<Rule Id="SA0001" Action="None" /><!-- XmlCommentAnalysisDisabled -->
<Rule Id="SA1101" Action="None" /><!-- PrefixLocalCallsWithThis -->

View File

@@ -111,7 +111,9 @@ function Test-Command
function Check-Command
{
Write-Host "Compiling in Debug configuration..." -ForegroundColor Cyan
dotnet build -c Debug --nologo -warnaserror -p:TargetPlatform=win-x64
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
dotnet build -c Debug --nologo -warnaserror -p:TargetPlatform=win-x64 -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
if ($lastexitcode -ne 0)
{
Write-Host "Build failed." -ForegroundColor Red