Move Stylecop checks to their own helper executable.
This commit is contained in:
41
OpenRA.StyleCheck/OpenRA.StyleCheck.csproj
Normal file
41
OpenRA.StyleCheck/OpenRA.StyleCheck.csproj
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{5FEAB6DC-4E81-4B63-958B-22FC3534C606}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>OpenRA.StyleCheck</RootNamespace>
|
||||
<AssemblyName>OpenRA.StyleCheck</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ExternalConsole>true</ExternalConsole>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ExternalConsole>true</ExternalConsole>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="StyleCop">
|
||||
<HintPath>..\StyleCop.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
47
OpenRA.StyleCheck/Program.cs
Normal file
47
OpenRA.StyleCheck/Program.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user