From e1e76411f7c7e6411906991a2caa297f8faa4d4b Mon Sep 17 00:00:00 2001 From: penev92 Date: Thu, 14 Oct 2021 02:33:14 +0300 Subject: [PATCH] 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. --- Makefile | 6 ++++-- OpenRA.ruleset | 15 +++++++++++++++ make.ps1 | 4 +++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 697f846628..898b28f433 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/OpenRA.ruleset b/OpenRA.ruleset index 93fd24a1ed..10d9441655 100644 --- a/OpenRA.ruleset +++ b/OpenRA.ruleset @@ -1,8 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/make.ps1 b/make.ps1 index 19efd3d84f..4f2da72391 100644 --- a/make.ps1 +++ b/make.ps1 @@ -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