Permalink
Browse files

Added StyleCop and custom StyleCop-Rules to tools

  • Loading branch information...
1 parent 36381a0 commit abb2b6f985d15c93ed8eac91ee73100888b9955d @e-tobi e-tobi committed Aug 29, 2011
View
@@ -66,5 +66,5 @@ ClientBin/
/Raven.Json/Raven.Json.g.3.5.csproj
/Modules/Json/Raven.Json/Raven.Json.g.3.5.csproj
*.docstates
-
+StyleCop.Cache
/Raven.Studio/Settings.dat
View

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,121 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <!-- Specify where tasks are implemented. -->
+ <UsingTask AssemblyFile="$(ProgramFiles)\StyleCop 4.5\StyleCop.dll" TaskName="StyleCopTask"/>
+
+ <PropertyGroup>
+ <BuildDependsOn>$(BuildDependsOn);StyleCop</BuildDependsOn>
+ <RebuildDependsOn>StyleCopForceFullAnalysis;$(RebuildDependsOn)</RebuildDependsOn>
+ </PropertyGroup>
+
+ <!-- Define StyleCopForceFullAnalysis property. -->
+ <PropertyGroup Condition="('$(SourceAnalysisForceFullAnalysis)' != '') and ('$(StyleCopForceFullAnalysis)' == '')">
+ <StyleCopForceFullAnalysis>$(SourceAnalysisForceFullAnalysis)</StyleCopForceFullAnalysis>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(StyleCopForceFullAnalysis)' == ''">
+ <StyleCopForceFullAnalysis>false</StyleCopForceFullAnalysis>
+ </PropertyGroup>
+
+ <!-- Define StyleCopCacheResults property. -->
+ <PropertyGroup Condition="('$(SourceAnalysisCacheResults)' != '') and ('$(StyleCopCacheResults)' == '')">
+ <StyleCopCacheResults>$(SourceAnalysisCacheResults)</StyleCopCacheResults>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(StyleCopCacheResults)' == ''">
+ <StyleCopCacheResults>true</StyleCopCacheResults>
+ </PropertyGroup>
+
+ <!-- Define StyleCopTreatErrorsAsWarnings property. -->
+ <PropertyGroup Condition="('$(SourceAnalysisTreatErrorsAsWarnings)' != '') and ('$(StyleCopTreatErrorsAsWarnings)' == '')">
+ <StyleCopTreatErrorsAsWarnings>$(SourceAnalysisTreatErrorsAsWarnings)</StyleCopTreatErrorsAsWarnings>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(StyleCopTreatErrorsAsWarnings)' == ''">
+ <StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
+ </PropertyGroup>
+
+ <!-- Define StyleCopEnabled property. -->
+ <PropertyGroup Condition="('$(SourceAnalysisEnabled)' != '') and ('$(StyleCopEnabled)' == '')">
+ <StyleCopEnabled>$(SourceAnalysisEnabled)</StyleCopEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(StyleCopEnabled)' == ''">
+ <StyleCopEnabled>true</StyleCopEnabled>
+ </PropertyGroup>
+
+ <!-- Define StyleCopOverrideSettingsFile property. -->
+ <PropertyGroup Condition="('$(SourceAnalysisOverrideSettingsFile)' != '') and ('$(StyleCopOverrideSettingsFile)' == '')">
+ <StyleCopOverrideSettingsFile>$(SourceAnalysisOverrideSettingsFile)</StyleCopOverrideSettingsFile>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(StyleCopOverrideSettingsFile)' == ''">
+ <StyleCopOverrideSettingsFile> </StyleCopOverrideSettingsFile>
+ </PropertyGroup>
+
+ <!-- Define StyleCopOutputFile property. -->
+ <PropertyGroup Condition="('$(SourceAnalysisOutputFile)' != '') and ('$(StyleCopOutputFile)' == '')">
+ <StyleCopOutputFile>$(SourceAnalysisOutputFile)</StyleCopOutputFile>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(StyleCopOutputFile)' == ''">
+ <StyleCopOutputFile>$(IntermediateOutputPath)StyleCopViolations.xml</StyleCopOutputFile>
+ </PropertyGroup>
+
+ <!-- Define all new properties which do not need to have both StyleCop and SourceAnalysis variations. -->
+ <PropertyGroup>
+ <!-- Specifying 0 will cause StyleCop to use the default violation count limit.
+ Specifying any positive number will cause StyleCop to use that number as the violation count limit.
+ Specifying any negative number will cause StyleCop to allow any number of violations without limit. -->
+ <StyleCopMaxViolationCount Condition="'$(StyleCopMaxViolationCount)' == ''">0</StyleCopMaxViolationCount>
+ </PropertyGroup>
+
+ <!-- Define target: StyleCopForceFullAnalysis -->
+ <Target Name="StyleCopForceFullAnalysis">
+ <CreateProperty Value="true">
+ <Output TaskParameter="Value" PropertyName="StyleCopForceFullAnalysis" />
+ </CreateProperty>
+ </Target>
+
+ <!-- Define target: StyleCop -->
+ <Target Name="StyleCop" Condition="'$(StyleCopEnabled)' != 'false'">
+ <Message Text="Forcing full StyleCop reanalysis." Condition="'$(StyleCopForceFullAnalysis)' == 'true'" Importance="Low" />
+
+ <!-- Determine what files should be checked. Take all Compile items, but exclude those that have
+ set ExcludeFromStyleCop=true or ExcludeFromSourceAnalysis=true. -->
+ <CreateItem Include="@(Compile)" Condition="('%(Compile.ExcludeFromStyleCop)' != 'true') and ('%(Compile.ExcludeFromSourceAnalysis)' != 'true')">
+ <Output TaskParameter="Include" ItemName="StyleCopFiles"/>
+ </CreateItem>
+
+ <Message Text="Analyzing @(StyleCopFiles)" Importance="Low" />
+
+ <!-- Show list of what files should be excluded. checked. Take all Compile items, but exclude those that have
+ set ExcludeFromStyleCop=true or ExcludeFromSourceAnalysis=true. -->
+ <CreateItem Include="@(Compile)" Condition="('%(Compile.ExcludeFromStyleCop)' == 'true') or ('%(Compile.ExcludeFromSourceAnalysis)' == 'true')">
+ <Output TaskParameter="Include" ItemName="StyleCopExcludedFiles"/>
+ </CreateItem>
+
+ <ItemGroup>
+ <StyleCopFiles Remove="@(ExcludeFromStyleCop)" />
+ </ItemGroup>
+
+ <Message Text="Excluding @(StyleCopExcludedFiles)" Importance="Normal" />
+
+ <!-- Run the StyleCop MSBuild task. -->
+ <StyleCopTask
+ ProjectFullPath="$(MSBuildProjectDirectory)"
+ SourceFiles="@(StyleCopFiles)"
+ AdditionalAddinPaths="@(StyleCopAdditionalAddinPaths)"
+ ForceFullAnalysis="$(StyleCopForceFullAnalysis)"
+ DefineConstants="$(DefineConstants)"
+ TreatErrorsAsWarnings="$(StyleCopTreatErrorsAsWarnings)"
+ CacheResults="$(StyleCopCacheResults)"
+ OverrideSettingsFile="$(StyleCopOverrideSettingsFile)"
+ OutputFile="$(StyleCopOutputFile)"
+ MaxViolationCount="$(StyleCopMaxViolationCount)"
+ />
+
+ <!-- Make output files cleanable -->
+ <CreateItem Include="$(StyleCopOutputFile)">
+ <Output TaskParameter="Include" ItemName="FileWrites"/>
+ </CreateItem>
+
+ <!-- Add the StyleCop.cache file to the list of files we've written - so they can be cleaned up on a Build Clean. -->
+ <CreateItem Include="StyleCop.Cache" Condition="'$(StyleCopCacheResults)' == 'true'">
+ <Output TaskParameter="Include" ItemName="FileWrites"/>
+ </CreateItem>
+ </Target>
+</Project>
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,68 @@
+Name:
+ StyleCop
+
+Homepage:
+ http://stylecop.codeplex.com
+
+Licence:
+ Microsoft Public License (Ms-PL)
+
+ This license governs use of the accompanying software. If you use the
+ software, you accept this license. If you do not accept the license, do
+ not use the software.
+
+ 1. Definitions
+
+ The terms "reproduce," "reproduction," "derivative works," and
+ "distribution" have the same meaning here as under U.S. copyright law.
+
+ A "contribution" is the original software, or any additions or changes
+ to the software.
+
+ A "contributor" is any person that distributes its contribution under
+ this license.
+
+ "Licensed patents" are a contributor's patent claims that read directly
+ on its contribution.
+
+ 2. Grant of Rights
+
+ (A) Copyright Grant- Subject to the terms of this license, including the
+ license conditions and limitations in section 3, each contributor grants
+ you a non-exclusive, worldwide, royalty-free copyright license to
+ reproduce its contribution, prepare derivative works of its
+ contribution, and distribute its contribution or any derivative works
+ that you create.
+
+ (B) Patent Grant- Subject to the terms of this license, including the
+ license conditions and limitations in section 3, each contributor grants
+ you a non-exclusive, worldwide, royalty-free license under its licensed
+ patents to make, have made, use, sell, offer for sale, import, and/or
+ otherwise dispose of its contribution in the software or derivative
+ works of the contribution in the software.
+
+ 3. Conditions and Limitations
+
+ (A) No Trademark License- This license does not grant you rights to use
+ any contributors' name, logo, or trademarks.
+
+ (B) If you bring a patent claim against any contributor over patents
+ that you claim are infringed by the software, your patent license from
+ such contributor to the software ends automatically.
+
+ (C) If you distribute any portion of the software, you must retain all
+ copyright, patent, trademark, and attribution notices that are present
+ in the software.
+
+ (D) If you distribute any portion of the software in source code form,
+ you may do so only under this license by including a complete copy of
+ this license with your distribution. If you distribute any portion of
+ the software in compiled or object code form, you may only do so under a
+ license that complies with this license.
+
+ (E) The software is licensed "as-is." You bear the risk of using it. The
+ contributors give no express warranties, guarantees or conditions. You
+ may have additional consumer rights under your local laws which this
+ license cannot change. To the extent permitted under your local laws,
+ the contributors exclude the implied warranties of merchantability,
+ fitness for a particular purpose and non-infringement.
@@ -0,0 +1,51 @@
+using System.Text.RegularExpressions;
+using System.Collections.Generic;
+using StyleCop;
+using StyleCop.CSharp;
+
+namespace Raven.CustomStyleCopRules
+{
+ [SourceAnalyzer(typeof(CsParser))]
+ public class IndentationRules : SourceAnalyzer
+ {
+ public override void AnalyzeDocument(CodeDocument document)
+ {
+ Param.RequireNotNull(document, "document");
+
+ var csdocument = (CsDocument)document;
+ if (csdocument.RootElement != null && !csdocument.RootElement.Generated)
+ {
+ CheckSpacing(csdocument.Tokens);
+ }
+ }
+
+ private void CheckSpacing(IEnumerable<CsToken> tokens)
+ {
+ Param.AssertNotNull(tokens, "tokens");
+
+ foreach (var token in tokens)
+ {
+ if (Cancel) break;
+ if (token.Generated) continue;
+
+ switch (token.CsTokenType)
+ {
+ case CsTokenType.WhiteSpace:
+ CheckWhitespace(token as Whitespace);
+ break;
+ }
+ }
+ }
+
+ private void CheckWhitespace(Whitespace whitespace)
+ {
+ Param.AssertNotNull(whitespace, "whitespace");
+
+ // Match any leading spaces, but not " *", which might be used in block comments that are not indented
+ if (whitespace.Location.StartPoint.IndexOnLine == 0 && Regex.IsMatch(whitespace.Text, @"^(?! \*) +"))
+ {
+ AddViolation(whitespace.FindParentElement(), whitespace.LineNumber, "TabsMustBeUsed");
+ }
+ }
+ }
+}
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<SourceAnalyzer Name="Custom RavenDB Rules">
+ <Description>
+ Custom rules for the RavenDB code base
+ </Description>
+ <Rules>
+ <Rule Name="TabsMustBeUsed" CheckId="RA1001">
+ <Context>Indentation by spaces is not allowed. Use tabs instead.</Context>
+ <Description>
+ Make sure the code is indented by tabs. You can use the "Productivity Power Tools"
+ extension available via the VisualStudio Gallery, which allows you to check and
+ fix the indentation when saving a source code document.
+ </Description>
+ </Rule>
+ </Rules>
+</SourceAnalyzer>
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Raven.CustomStyleCopRules")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Raven.CustomStyleCopRules")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("366d69b5-28dc-4dda-849f-f27132c9ee1d")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{B8888574-1ED6-416D-9705-626EE8E470DD}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Raven.CustomStyleCopRules</RootNamespace>
+ <AssemblyName>Raven.CustomStyleCopRules</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="StyleCop">
+ <HintPath>..\..\Tools\StyleCop\StyleCop.dll</HintPath>
+ </Reference>
+ <Reference Include="StyleCop.CSharp">
+ <HintPath>..\..\Tools\StyleCop\StyleCop.CSharp.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="IndentationRules.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="IndentationRules.xml">
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
Oops, something went wrong.

0 comments on commit abb2b6f

Please sign in to comment.