Add --check-code-style utility command.
This commit is contained in:
committed by
Matthias Mailänder
parent
ecd4479807
commit
f4055dae53
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,6 +22,7 @@ mods/*/*.mdb
|
||||
/*.pdb
|
||||
/*.mdb
|
||||
/*.exe
|
||||
thirdparty/StyleCop*
|
||||
|
||||
# backup files by various editors
|
||||
*~
|
||||
@@ -57,6 +58,7 @@ Lua-API.md
|
||||
|
||||
# StyleCop
|
||||
*.Cache
|
||||
StyleCopViolations.xml
|
||||
|
||||
# SublimeText
|
||||
*.sublime-project
|
||||
|
||||
@@ -38,6 +38,7 @@ Debian/Ubuntu
|
||||
|
||||
* mono-dmcs
|
||||
* libmono-system-windows-forms4.0-cil
|
||||
* nuget
|
||||
* cli-common-dev (>= 2.10)
|
||||
* libfreetype6
|
||||
* libopenal1
|
||||
@@ -50,6 +51,7 @@ openSUSE
|
||||
--------
|
||||
|
||||
* mono-devel
|
||||
* nuget
|
||||
* openal
|
||||
* freetype2
|
||||
* SDL2
|
||||
@@ -62,6 +64,7 @@ Gentoo
|
||||
|
||||
* dev-lang/mono
|
||||
* dev-dotnet/libgdiplus
|
||||
* dev-dotnet/nuget
|
||||
* media-libs/freetype:2
|
||||
* media-libs/libsdl2
|
||||
* media-libs/openal
|
||||
|
||||
3
Makefile
3
Makefile
@@ -105,7 +105,7 @@ mod_common_SRCS := $(shell find OpenRA.Mods.Common/ -iname '*.cs')
|
||||
mod_common_TARGET = mods/common/OpenRA.Mods.Common.dll
|
||||
mod_common_KIND = library
|
||||
mod_common_DEPS = $(game_TARGET)
|
||||
mod_common_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS)
|
||||
mod_common_LIBS = $(COMMON_LIBS) $(STD_MOD_LIBS) thirdparty/StyleCop.dll thirdparty/StyleCop.CSharp.dll thirdparty/StyleCop.CSharp.Rules.dll
|
||||
PROGRAMS += mod_common
|
||||
mod_common: $(mod_common_TARGET)
|
||||
|
||||
@@ -264,6 +264,7 @@ distclean: clean
|
||||
dependencies: cli-dependencies native-dependencies
|
||||
|
||||
cli-dependencies:
|
||||
cd thirdparty && ./fetch-thirdparty-deps.sh && cd ..
|
||||
@ $(CP_R) thirdparty/*.dll .
|
||||
@ $(CP_R) thirdparty/*.dll.config .
|
||||
|
||||
|
||||
@@ -31,14 +31,22 @@
|
||||
</CustomCommands>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Eluant, Version=1.0.5229.27703, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\thirdparty\Eluant.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Eluant">
|
||||
<HintPath>..\thirdparty\Eluant.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="StyleCop.CSharp.Rules">
|
||||
<HintPath>..\thirdparty\StyleCop.CSharp.Rules.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StyleCop.CSharp">
|
||||
<HintPath>..\thirdparty\StyleCop.CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StyleCop">
|
||||
<HintPath>..\thirdparty\StyleCop.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
@@ -244,6 +252,7 @@
|
||||
<Compile Include="LoadScreens\LogoStripeLoadScreen.cs" />
|
||||
<Compile Include="LoadScreens\BlankLoadScreen.cs" />
|
||||
<Compile Include="UtilityCommands\CheckYaml.cs" />
|
||||
<Compile Include="UtilityCommands\CheckCodeStyle.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
56
OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs
Normal file
56
OpenRA.Mods.Common/UtilityCommands/CheckCodeStyle.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Traits;
|
||||
using StyleCop;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
class CheckCodeStyle : IUtilityCommand
|
||||
{
|
||||
public string Name { get { return "--check-code-style"; } }
|
||||
int violationCount;
|
||||
|
||||
[Desc("DIRECTORY", "Check the *.cs source code files in a directory for code style violations.")]
|
||||
public void Run(ModData modData, string[] args)
|
||||
{
|
||||
var projectPath = Path.GetFullPath(args[1]);
|
||||
|
||||
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);
|
||||
|
||||
console.OutputGenerated += OnOutputGenerated;
|
||||
console.ViolationEncountered += OnViolationEncountered;
|
||||
console.Start(new[] { project }, true);
|
||||
|
||||
if (violationCount > 0)
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
void OnOutputGenerated(object sender, OutputEventArgs e)
|
||||
{
|
||||
Console.WriteLine(e.Output);
|
||||
}
|
||||
|
||||
void OnViolationEncountered(object sender, ViolationEventArgs e)
|
||||
{
|
||||
violationCount++;
|
||||
Console.WriteLine("{0}:L{1}: [{2}] {3}", e.SourceCode.Path, e.LineNumber, e.Violation.Rule.CheckId, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
make.ps1
7
make.ps1
@@ -107,8 +107,11 @@ elseif ($command -eq "version")
|
||||
}
|
||||
elseif ($command -eq "dependencies")
|
||||
{
|
||||
cp thirdparty/*.dll .
|
||||
cp thirdparty/windows/*.dll .
|
||||
cd thirdparty
|
||||
./fetch-thirdparty-deps.ps1
|
||||
cp *.dll ..
|
||||
cp windows/*.dll ..
|
||||
cd ..
|
||||
echo "Dependencies copied."
|
||||
}
|
||||
elseif ($command -eq "test")
|
||||
|
||||
12
thirdparty/fetch-thirdparty-deps.ps1
vendored
Normal file
12
thirdparty/fetch-thirdparty-deps.ps1
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
if (!(Test-Path "nuget.exe"))
|
||||
{
|
||||
echo "Fetching NuGet."
|
||||
Invoke-WebRequest "http://nuget.org/nuget.exe" -OutFile "nuget.exe"
|
||||
}
|
||||
if (!(Test-Path "StyleCop.dll"))
|
||||
{
|
||||
echo "Fetching StyleCop files from NuGet."
|
||||
./nuget.exe install StyleCop.MSBuild -Version 4.7.49.0
|
||||
cp StyleCop.MSBuild.4.7.49.0/tools/StyleCop*.dll .
|
||||
rmdir StyleCop.MSBuild.4.7.49.0 -Recurse
|
||||
}
|
||||
7
thirdparty/fetch-thirdparty-deps.sh
vendored
Executable file
7
thirdparty/fetch-thirdparty-deps.sh
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
if [ ! -f StyleCop.dll ]; then
|
||||
echo "Fetching StyleCop files from nuget"
|
||||
nuget install StyleCop.MSBuild -Version 4.7.49.0
|
||||
cp ./StyleCop.MSBuild.4.7.49.0/tools/StyleCop*.dll .
|
||||
rm -rf StyleCop.MSBuild.4.7.49.0
|
||||
fi
|
||||
Reference in New Issue
Block a user