From ba282865f174af363dba609374abc48d08cfe17b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 3 May 2019 21:25:28 +0000 Subject: [PATCH] Replace legacy StyleCop(Plus) with StyleCopAnalyzers Analyzers are enabled in the Debug configuration only to avoid unnecessary overheads when compiling normally. --- Makefile | 30 +- OpenRA.Game/OpenRA.Game.csproj | 9 + OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 11 +- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 9 + OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj | 9 + .../OpenRA.Platforms.Default.csproj | 9 + OpenRA.PostProcess/OpenRA.PostProcess.csproj | 11 + OpenRA.Server/OpenRA.Server.csproj | 9 + OpenRA.StyleCheck/App.config | 8 - OpenRA.StyleCheck/OpenRA.StyleCheck.csproj | 34 -- OpenRA.StyleCheck/Program.cs | 47 -- OpenRA.Test/OpenRA.Test.csproj | 9 + OpenRA.Utility/OpenRA.Utility.csproj | 9 + OpenRA.ruleset | 54 +++ OpenRA.sln | 6 - Settings.StyleCop | 408 ------------------ make.ps1 | 29 +- stylecop.json | 10 + thirdparty/fetch-thirdparty-deps.ps1 | 16 - thirdparty/fetch-thirdparty-deps.sh | 14 - 20 files changed, 159 insertions(+), 582 deletions(-) delete mode 100644 OpenRA.StyleCheck/App.config delete mode 100644 OpenRA.StyleCheck/OpenRA.StyleCheck.csproj delete mode 100644 OpenRA.StyleCheck/Program.cs create mode 100644 OpenRA.ruleset delete mode 100644 Settings.StyleCop create mode 100644 stylecop.json diff --git a/Makefile b/Makefile index 55887761d8..847fa8767a 100644 --- a/Makefile +++ b/Makefile @@ -96,37 +96,17 @@ check-scripts: @luac -p $(shell find mods/*/maps/* -iname '*.lua') @luac -p $(shell find lua/* -iname '*.lua') -check: core +check: dependencies + @echo + @echo "Compiling in debug mode..." + @$(MSBUILD) -t:build -p:Configuration=Debug @echo @echo "Checking runtime assemblies..." @mono --debug OpenRA.Utility.exe all --check-runtime-assemblies $(WHITELISTED_OPENRA_ASSEMBLIES) $(WHITELISTED_THIRDPARTY_ASSEMBLIES) $(WHITELISTED_CORE_ASSEMBLIES) @echo @echo "Checking for explicit interface violations..." @mono --debug OpenRA.Utility.exe all --check-explicit-interfaces - @echo - @echo "Checking for code style violations in OpenRA.Game..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Game - @echo - @echo "Checking for code style violations in OpenRA.Platforms.Default..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Platforms.Default - @echo - @echo "Checking for code style violations in OpenRA.Mods.Common..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Mods.Common - @echo - @echo "Checking for code style violations in OpenRA.Mods.Cnc..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Mods.Cnc - @echo - @echo "Checking for code style violations in OpenRA.Mods.D2k..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Mods.D2k - @echo - @echo "Checking for code style violations in OpenRA.Utility..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Utility - @echo - @echo "Checking for code style violations in OpenRA.Test..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Test - @echo - @echo "Checking for code style violations in OpenRA.Server..." - @mono --debug OpenRA.StyleCheck.exe OpenRA.Server + NUNIT_CONSOLE := $(shell test -f thirdparty/download/nunit3-console.exe && echo mono thirdparty/download/nunit3-console.exe || \ which nunit3-console 2>/dev/null || which nunit2-console 2>/dev/null || which nunit-console 2>/dev/null) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 0457bee021..7de94515d0 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -16,6 +16,7 @@ x86 false false + ..\OpenRA.ruleset @@ -61,7 +62,15 @@ false + + + + + + + + diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 12f5a8b8d7..286f08fb40 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -11,6 +11,7 @@ x86 x86 false + ..\OpenRA.ruleset @@ -25,13 +26,19 @@ ..\thirdparty\download\Eluant.dll False - - False False + + + + + + + + \ No newline at end of file diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index f4d4f4bac1..dde3fcee98 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -11,6 +11,7 @@ x86 x86 false + ..\OpenRA.ruleset @@ -42,5 +43,13 @@ False + + + + + + + + diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index eb9dfd44c2..6aeaaa5e9c 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -11,6 +11,7 @@ x86 x86 false + ..\OpenRA.ruleset @@ -33,5 +34,13 @@ False + + + + + + + + \ No newline at end of file diff --git a/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj b/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj index e81a811fdd..fffabda7c7 100644 --- a/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj +++ b/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj @@ -11,6 +11,7 @@ x86 x86 false + ..\OpenRA.ruleset @@ -33,7 +34,15 @@ + + + + + + + + PreserveNewest diff --git a/OpenRA.PostProcess/OpenRA.PostProcess.csproj b/OpenRA.PostProcess/OpenRA.PostProcess.csproj index da899f17ca..eb6ba7381f 100644 --- a/OpenRA.PostProcess/OpenRA.PostProcess.csproj +++ b/OpenRA.PostProcess/OpenRA.PostProcess.csproj @@ -14,6 +14,7 @@ x86 false false + ..\OpenRA.ruleset @@ -23,4 +24,14 @@ DEBUG;TRACE false + + + + + + + + + + diff --git a/OpenRA.Server/OpenRA.Server.csproj b/OpenRA.Server/OpenRA.Server.csproj index dd3769e697..5b391471d9 100644 --- a/OpenRA.Server/OpenRA.Server.csproj +++ b/OpenRA.Server/OpenRA.Server.csproj @@ -14,6 +14,7 @@ x86 false false + ..\OpenRA.ruleset @@ -28,7 +29,15 @@ false + + + + + + + + diff --git a/OpenRA.StyleCheck/App.config b/OpenRA.StyleCheck/App.config deleted file mode 100644 index eba8d1e0ba..0000000000 --- a/OpenRA.StyleCheck/App.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/OpenRA.StyleCheck/OpenRA.StyleCheck.csproj b/OpenRA.StyleCheck/OpenRA.StyleCheck.csproj deleted file mode 100644 index 118d326a26..0000000000 --- a/OpenRA.StyleCheck/OpenRA.StyleCheck.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - Exe - net461 - true - true - false - .. - false - 5 - true - true - x86 - x86 - false - false - - - - - - - DEBUG;TRACE - false - - - - ..\StyleCop.dll - - - - - - \ No newline at end of file diff --git a/OpenRA.StyleCheck/Program.cs b/OpenRA.StyleCheck/Program.cs deleted file mode 100644 index 3949e46581..0000000000 --- a/OpenRA.StyleCheck/Program.cs +++ /dev/null @@ -1,47 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, and is made available under the terms of the MS-PL license. - * For more information, see https://opensource.org/licenses/MS-PL - */ -#endregion - -using System; -using System.IO; -using StyleCop; - -namespace OpenRA.StyleCheck -{ - class StyleCheck - { - public static void Main(string[] args) - { - if (args.Length != 1) - { - Console.WriteLine("Usage: OpenRA.StyleCheck.exe DIRECTORY"); - Console.WriteLine("Check the *.cs source code files in a directory for code style violations."); - return; - } - - var projectPath = Path.GetFullPath(args[0]); - var console = new StyleCopConsole(null, false, null, null, true); - var project = new CodeProject(0, projectPath, new Configuration(null)); - foreach (var filePath in Directory.GetFiles(projectPath, "*.cs", SearchOption.AllDirectories)) - console.Core.Environment.AddSourceCode(project, filePath, null); - - var violationCount = 0; - console.ViolationEncountered += (object sender, ViolationEventArgs e) => { - violationCount++; - var path = e.SourceCode.Path.Replace(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar, ""); - Console.WriteLine("{0}:L{1}: [{2}] {3}", path, e.LineNumber, e.Violation.Rule.CheckId, e.Message); - }; - - console.Start(new[] { project }, true); - - if (violationCount > 0) - Environment.Exit(1); - else - Console.WriteLine("No violations encountered in {0}.", args[0]); - } - } -} diff --git a/OpenRA.Test/OpenRA.Test.csproj b/OpenRA.Test/OpenRA.Test.csproj index 0bf6e99ff6..670ec59912 100644 --- a/OpenRA.Test/OpenRA.Test.csproj +++ b/OpenRA.Test/OpenRA.Test.csproj @@ -10,6 +10,7 @@ x86 x86 false + ..\OpenRA.ruleset @@ -36,5 +37,13 @@ False + + + + + + + + \ No newline at end of file diff --git a/OpenRA.Utility/OpenRA.Utility.csproj b/OpenRA.Utility/OpenRA.Utility.csproj index dd3769e697..5b391471d9 100644 --- a/OpenRA.Utility/OpenRA.Utility.csproj +++ b/OpenRA.Utility/OpenRA.Utility.csproj @@ -14,6 +14,7 @@ x86 false false + ..\OpenRA.ruleset @@ -28,7 +29,15 @@ false + + + + + + + + diff --git a/OpenRA.ruleset b/OpenRA.ruleset new file mode 100644 index 0000000000..8845db0580 --- /dev/null +++ b/OpenRA.ruleset @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenRA.sln b/OpenRA.sln index 2d57d67928..a0eec86dbb 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -176,8 +176,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tiberian Sun Lua scripts", mods\ts\maps\fields-of-green\fields-of-green.lua = mods\ts\maps\fields-of-green\fields-of-green.lua EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.StyleCheck", "OpenRA.StyleCheck\OpenRA.StyleCheck.csproj", "{5FEAB6DC-4E81-4B63-958B-22FC3534C606}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.PostProcess", "OpenRA.PostProcess\OpenRA.PostProcess.csproj", "{EE63AF7E-92EA-48FB-81E2-53D7D92F8050}" EndProject Global @@ -218,10 +216,6 @@ Global {6CB8E1B7-6B36-4D93-8633-7C573E194AC4}.Debug|x86.Build.0 = Debug|x86 {6CB8E1B7-6B36-4D93-8633-7C573E194AC4}.Release|x86.ActiveCfg = Release|x86 {6CB8E1B7-6B36-4D93-8633-7C573E194AC4}.Release|x86.Build.0 = Release|x86 - {5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Debug|x86.ActiveCfg = Debug|x86 - {5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Debug|x86.Build.0 = Debug|x86 - {5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Release|x86.ActiveCfg = Release|x86 - {5FEAB6DC-4E81-4B63-958B-22FC3534C606}.Release|x86.Build.0 = Release|x86 {EE63AF7E-92EA-48FB-81E2-53D7D92F8050}.Debug|x86.ActiveCfg = Debug|x86 {EE63AF7E-92EA-48FB-81E2-53D7D92F8050}.Debug|x86.Build.0 = Debug|x86 {EE63AF7E-92EA-48FB-81E2-53D7D92F8050}.Release|x86.ActiveCfg = Release|x86 diff --git a/Settings.StyleCop b/Settings.StyleCop deleted file mode 100644 index dce8c7e2f0..0000000000 --- a/Settings.StyleCop +++ /dev/null @@ -1,408 +0,0 @@ - - - - - False - - - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - - - - - - False - - - - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - - - - - - False - - - - - - - - - - False - - - - - False - - - - - False - - - - - False - - - - - False - - - - - True - - - - - 180:4 - - - - \ No newline at end of file diff --git a/make.ps1 b/make.ps1 index 37a59349b0..e100075477 100644 --- a/make.ps1 +++ b/make.ps1 @@ -136,33 +136,18 @@ function Test-Command function Check-Command { + echo "Compiling in debug configuration..." + dotnet build /p:Configuration=Debug /nologo + if ($lastexitcode -ne 0) + { + echo "Build failed." + } + if (CheckForUtility -eq 0) { echo "Checking for explicit interface violations..." ./OpenRA.Utility.exe all --check-explicit-interfaces } - - if (Test-Path OpenRA.StyleCheck.exe) - { - echo "Checking for code style violations in OpenRA.Platforms.Default..." - ./OpenRA.StyleCheck.exe OpenRA.Platforms.Default - echo "Checking for code style violations in OpenRA.Game..." - ./OpenRA.StyleCheck.exe OpenRA.Game - echo "Checking for code style violations in OpenRA.Mods.Common..." - ./OpenRA.StyleCheck.exe OpenRA.Mods.Common - echo "Checking for code style violations in OpenRA.Mods.Cnc..." - ./OpenRA.StyleCheck.exe OpenRA.Mods.Cnc - echo "Checking for code style violations in OpenRA.Mods.D2k..." - ./OpenRA.StyleCheck.exe OpenRA.Mods.D2k - echo "Checking for code style violations in OpenRA.Utility..." - ./OpenRA.StyleCheck.exe OpenRA.Utility - echo "Checking for code style violations in OpenRA.Test..." - ./OpenRA.StyleCheck.exe OpenRA.Test - } - else - { - echo "OpenRA.StyleCheck.exe could not be found. Build the project first using the `"all`" command." - } } function Check-Scripts-Command diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 0000000000..b0b1bb2a49 --- /dev/null +++ b/stylecop.json @@ -0,0 +1,10 @@ +{ + "settings": { + "indentation": { + "useTabs": true + }, + "layoutRules": { + "newlineAtEndOfFile": "require" + } + } +} \ No newline at end of file diff --git a/thirdparty/fetch-thirdparty-deps.ps1 b/thirdparty/fetch-thirdparty-deps.ps1 index fac79da9ea..fe189e3b61 100644 --- a/thirdparty/fetch-thirdparty-deps.ps1 +++ b/thirdparty/fetch-thirdparty-deps.ps1 @@ -11,22 +11,6 @@ if (!(Test-Path "nuget.exe")) (New-Object System.Net.WebClient).DownloadFile("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", $target) } -if (!(Test-Path "StyleCopPlus.dll")) -{ - echo "Fetching StyleCopPlus from NuGet." - ./nuget.exe install StyleCopPlus.MSBuild -Version 4.7.49.5 -ExcludeVersion -Verbosity quiet -Source nuget.org - cp StyleCopPlus.MSBuild/tools/StyleCopPlus.dll . - rmdir StyleCopPlus.MSBuild -Recurse -} - -if (!(Test-Path "StyleCop.dll")) -{ - echo "Fetching StyleCop files from NuGet." - ./nuget.exe install StyleCop.MSBuild -Version 4.7.49.0 -ExcludeVersion -Verbosity quiet -Source nuget.org - cp StyleCop.MSBuild/tools/StyleCop*.dll . - rmdir StyleCop.MSBuild -Recurse -} - if (!(Test-Path "ICSharpCode.SharpZipLib.dll")) { echo "Fetching ICSharpCode.SharpZipLib from NuGet." diff --git a/thirdparty/fetch-thirdparty-deps.sh b/thirdparty/fetch-thirdparty-deps.sh index 4e93e03ac1..5b7f9ccd19 100755 --- a/thirdparty/fetch-thirdparty-deps.sh +++ b/thirdparty/fetch-thirdparty-deps.sh @@ -13,20 +13,6 @@ download_dir="${0%/*}/download" mkdir -p "${download_dir}" cd "${download_dir}" || exit 1 -if [ ! -f StyleCopPlus.dll ]; then - echo "Fetching StyleCopPlus from NuGet" - ../noget.sh StyleCopPlus.MSBuild 4.7.49.5 - cp ./StyleCopPlus.MSBuild/tools/StyleCopPlus.dll . - rm -rf StyleCopPlus.MSBuild -fi - -if [ ! -f StyleCop.dll ]; then - echo "Fetching StyleCop files from NuGet" - ../noget.sh StyleCop.MSBuild 4.7.49.0 - cp ./StyleCop.MSBuild/tools/StyleCop*.dll . - rm -rf StyleCop.MSBuild -fi - if [ ! -f ICSharpCode.SharpZipLib.dll ]; then echo "Fetching ICSharpCode.SharpZipLib from NuGet" ../noget.sh SharpZipLib 1.1.0