Skip to content

Commit

Permalink
Enable Stylecop analysis (#1037)
Browse files Browse the repository at this point in the history
Additionally, the following changes were made:
- analyzers are now disabled for the `Debug` and `Release` configurations;
- some StyleCop rules are suppressed for test projects;
- added a hint to switch IDE to `Verify` configuration for easier analysis fixing.
  • Loading branch information
blairconrad authored and zvirja committed Jun 4, 2018
1 parent a401270 commit b9a3f4d
Show file tree
Hide file tree
Showing 432 changed files with 2,949 additions and 2,654 deletions.
14 changes: 12 additions & 2 deletions Build.fsx
Expand Up @@ -202,7 +202,17 @@ Target "EnableSourceLinkGeneration" (fun _ ->
enableSourceLink <- true
)

Target "VerifyOnly" (fun _ -> rebuild "Verify")
Target "VerifyOnly" (fun _ ->
try
rebuild "Verify"
with
| BuildException (msg, errors) ->
let msg = sprintf
"%s\r\nHINT: To simplify the fix process it's recommended to switch to the 'Verify' configuration \
in the IDE. This way you might get Roslyn quick fixes for the violated rules."
msg
raise (BuildException(msg, errors))
)

Target "BuildOnly" (fun _ -> rebuild configuration)
Target "TestOnly" (fun _ ->
Expand Down Expand Up @@ -449,4 +459,4 @@ if buildServer = BuildServer.AppVeyor
ActivateFinalTarget "AppVeyor_UpdateVersion"

// ========= ENTRY POINT =========
RunTargetOrDefault "CompleteBuild"
RunTargetOrDefault "CompleteBuild"
5 changes: 4 additions & 1 deletion Src/All.sln
Expand Up @@ -60,10 +60,13 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F0A01F00-72C7-4CE4-8BA4-9EB178B72329}"
ProjectSection(SolutionItems) = preProject
..\.editorconfig = ..\.editorconfig
..\Build.fsx = ..\Build.fsx
CodeAnalysis.AutoFixture.ruleset = CodeAnalysis.AutoFixture.ruleset
CodeAnalysis.Empty.ruleset = CodeAnalysis.Empty.ruleset
CodeAnalysis.Test.ruleset = CodeAnalysis.Test.ruleset
Common.props = Common.props
Common.Test.props = Common.Test.props
Common.Test.xUnit.props = Common.Test.xUnit.props
..\Build.fsx = ..\Build.fsx
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoFakeItEasy.FakeItEasy2UnitTest", "AutoFakeItEasy.FakeItEasy2UnitTest\AutoFakeItEasy.FakeItEasy2UnitTest.csproj", "{7F957CC0-79C3-48A1-9A3E-47BED7539248}"
Expand Down
8 changes: 8 additions & 0 deletions Src/All.sln.DotSettings
@@ -1,8 +1,16 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=BuiltInTypeReferenceStyle/@EntryIndexedValue">SUGGESTION</s:String>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/ReadSettingsFromFileLevel/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_BEFORE_SINGLE_LINE_COMMENT/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_DECLARATION_PARENS_ARRANGEMENT/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_TYPE_CONSTRAINTS_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_EXTENDS_COLON/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_FIRST_TYPE_PARAMETER_CONSTRAINT/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion Src/AutoFakeItEasy/AutoFakeItEasyCustomization.cs
Expand Up @@ -10,7 +10,7 @@ namespace AutoFixture.AutoFakeItEasy
/// Enables auto-mocking with FakeItEasy.
/// </summary>
/// <remarks>
/// NOTICE! You can assign the customization properties to tweak the features you would like to enable. Example:
/// NOTICE! You can assign the customization properties to tweak the features you would like to enable. See example.
/// <br />
/// <code>new AutoFakeItEasyCustomization { GenerateDelegates = true }</code>
/// </remarks>
Expand Down
32 changes: 16 additions & 16 deletions Src/AutoFakeItEasy/ConfigureFakeMembersCommand.cs
Expand Up @@ -7,26 +7,26 @@

namespace AutoFixture.AutoFakeItEasy
{
/// <summary>
/// Sets up a Fake's members so that the return, out, and ref values of virtual members will
/// be retrieved from the fixture, instead of being created directly by FakeItEasy.
///
/// This will setup virtual methods and properties.
/// </summary>
/// <remarks>
/// <summary>
/// Sets up a Fake's members so that the return, out, and ref values of virtual members will
/// be retrieved from the fixture, instead of being created directly by FakeItEasy.
///
/// This will setup virtual methods and properties.
/// </summary>
/// <remarks>
/// This will setup any virtual methods and properties.
/// This includes:
/// - interface's methods/properties;
/// - class's abstract/virtual/overridden/non-sealed methods/properties.
/// </remarks>
/// This includes:
/// - interface's methods/properties;
/// - class's abstract/virtual/overridden/non-sealed methods/properties.
/// </remarks>
public class ConfigureFakeMembersCommand : ISpecimenCommand
{
/// <summary>
/// <summary>
/// Sets up a Fake's members so that the return, out, and ref values will be retrieved
/// from the fixture, instead of being created directly by FakeItEasy.
/// </summary>
/// <param name="specimen">The Fake to setup.</param>
/// <param name="context">The context of the Fake.</param>
/// from the fixture, instead of being created directly by FakeItEasy.
/// </summary>
/// <param name="specimen">The Fake to setup.</param>
/// <param name="context">The context of the Fake.</param>
public void Execute(object specimen, ISpecimenContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
Expand Down
16 changes: 8 additions & 8 deletions Src/AutoFakeItEasy/FakeItEasyMethodQuery.cs
Expand Up @@ -13,7 +13,7 @@ namespace AutoFixture.AutoFakeItEasy
/// </summary>
public class FakeItEasyMethodQuery : IMethodQuery
{
private static readonly DelegateSpecification delegateSpecification = new DelegateSpecification();
private static readonly DelegateSpecification DelegateSpecification = new DelegateSpecification();

/// <summary>
/// Selects constructors for the supplied type.
Expand All @@ -36,7 +36,7 @@ public IEnumerable<IMethod> SelectMethods(Type type)
}

var fakeType = type.GetFakedType();
if (fakeType.GetTypeInfo().IsInterface || delegateSpecification.IsSatisfiedBy(fakeType))
if (fakeType.GetTypeInfo().IsInterface || DelegateSpecification.IsSatisfiedBy(fakeType))
{
return new[] { new ConstructorMethod(type.GetDefaultConstructor()) };
}
Expand All @@ -53,7 +53,7 @@ private static class FakeMethod
Type type,
IEnumerable<ParameterInfo> parameterInfos)
{
var constructedType =
var constructedType =
typeof(FakeMethod<>).MakeGenericType(type);
return (IMethod)Activator.CreateInstance(
constructedType,
Expand All @@ -74,7 +74,7 @@ public FakeMethod(IEnumerable<ParameterInfo> parameterInfos)

public object Invoke(IEnumerable<object> parameters)
{
var genericFakeType = typeof (Fake<>).MakeGenericType(typeof (T));
var genericFakeType = typeof(Fake<>).MakeGenericType(typeof(T));

foreach (var constructor in genericFakeType.GetConstructors())
{
Expand All @@ -86,7 +86,7 @@ public object Invoke(IEnumerable<object> parameters)

var parameterType = constructorParameterInfos[0].ParameterType;
if (!parameterType.GetTypeInfo().IsGenericType ||
parameterType.GetGenericTypeDefinition() != typeof (Action<>))
parameterType.GetGenericTypeDefinition() != typeof(Action<>))
{
continue;
}
Expand All @@ -100,17 +100,17 @@ public object Invoke(IEnumerable<object> parameters)

var withArgumentsForConstructorMethod = fakeOptionsType.GetMethod(
"WithArgumentsForConstructor",
new[] {typeof (object[])});
new[] { typeof(object[]) });

if (withArgumentsForConstructorMethod == null)
{
continue;
}

Action<object> addConstructorArgumentsToOptionsAction =
options => withArgumentsForConstructorMethod.Invoke(options, new object[] {parameters});
options => withArgumentsForConstructorMethod.Invoke(options, new object[] { parameters });

return constructor.Invoke(new object[] {addConstructorArgumentsToOptionsAction});
return constructor.Invoke(new object[] { addConstructorArgumentsToOptionsAction });
}

return null;
Expand Down
13 changes: 6 additions & 7 deletions Src/AutoFakeItEasy/FakeObjectCall.cs
Expand Up @@ -8,7 +8,7 @@ namespace AutoFixture.AutoFakeItEasy
using System.Globalization;

/// <summary>
/// A bridge class, required because the types representing fake object calls in
/// A bridge class, required because the types representing fake object calls in
/// 1.7.4109.1 (which the .NET Framework version of AutoFixture.AutoFakeItEasy is compiled against)
/// differ from those in 2.0.0+ in ways that prevent us from using them directly.
/// If ever support for FakeItEasy versions below 2.0.0 is dropped, this class may be removed.
Expand All @@ -28,16 +28,15 @@ public FakeObjectCall(IFakeObjectCall wrappedCall)

public MethodInfo Method => this.wrappedCall.Method;

public IEnumerable<object> Arguments => (IEnumerable<object>)InvokeWrappedPropertyGetter(ArgumentsPropertyName);
public IEnumerable<object> Arguments => (IEnumerable<object>)this.InvokeWrappedPropertyGetter(ArgumentsPropertyName);

public void SetReturnValue(object value)
{
InvokeWrappedMethod(SetReturnValueMethodName, value);
this.InvokeWrappedMethod(SetReturnValueMethodName, value);
}

public void SetArgumentValue(int index, object value) =>
InvokeWrappedMethod(SetArgumentValueMethodName, index, value);

this.InvokeWrappedMethod(SetArgumentValueMethodName, index, value);

private object InvokeWrappedPropertyGetter(string propertyName)
{
Expand All @@ -49,7 +48,7 @@ private object InvokeWrappedPropertyGetter(string propertyName)
"Property {0} cannot be found on {1}", propertyName, callType.FullName));
}

return propertyInfo.GetValue(wrappedCall);
return propertyInfo.GetValue(this.wrappedCall);
}

private void InvokeWrappedMethod(string methodName, params object[] parameters)
Expand All @@ -62,7 +61,7 @@ private void InvokeWrappedMethod(string methodName, params object[] parameters)
"Method {0} cannot be found on {1}", methodName, callType.FullName));
}

methodInfo.Invoke(wrappedCall, parameters);
methodInfo.Invoke(this.wrappedCall, parameters);
}
}
}
12 changes: 6 additions & 6 deletions Src/AutoFakeItEasy/GlobalSuppressions.cs
@@ -1,13 +1,13 @@
// This file is used by Code Analysis to maintain SuppressMessage
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes",
Scope = "namespace", Target = "AutoFixture.AutoFakeItEasy",
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes",
Scope = "namespace", Target = "AutoFixture.AutoFakeItEasy",
Justification = "This should be a separate assembly because it provides extensions to AutoFixture that are specific to the use of FakeItEasy.")]
8 changes: 4 additions & 4 deletions Src/AutoFakeItEasy/MethodCall.cs
Expand Up @@ -36,15 +36,15 @@ public override int GetHashCode()
unchecked
{
var hashCode = -712421553;
hashCode = hashCode * -1521134295 + this.declaringType.GetHashCode();
hashCode = hashCode * -1521134295 + this.methodName.GetHashCode();
hashCode = (hashCode * -1521134295) + this.declaringType.GetHashCode();
hashCode = (hashCode * -1521134295) + this.methodName.GetHashCode();
foreach (var argument in this.arguments)
{
hashCode = hashCode * -1521134295 + EqualityComparer<object>.Default.GetHashCode(argument);
hashCode = (hashCode * -1521134295) + EqualityComparer<object>.Default.GetHashCode(argument);
}
foreach (var argumentType in this.parameterTypes)
{
hashCode = hashCode * -1521134295 + argumentType.GetHashCode();
hashCode = (hashCode * -1521134295) + argumentType.GetHashCode();
}
return hashCode;
}
Expand Down
3 changes: 2 additions & 1 deletion Src/AutoFakeItEasy/MethodCallResult.cs
Expand Up @@ -15,7 +15,7 @@ public MethodCallResult(object returnValue)
public void ApplyToCall(FakeObjectCall fakeObjectCall)
{
fakeObjectCall.SetReturnValue(this.returnValue);
if (outAndRefValues == null) return;
if (this.outAndRefValues == null) return;

foreach (var positionedValue in this.outAndRefValues)
{
Expand All @@ -36,6 +36,7 @@ public void AddOutOrRefValue(int i, object value)
private class PositionedValue
{
public int Position { get; }

public object Value { get; }

public PositionedValue(int position, object value)
Expand Down
8 changes: 4 additions & 4 deletions Src/AutoFakeItEasy/MethodRule.cs
Expand Up @@ -6,7 +6,7 @@ namespace AutoFixture.AutoFakeItEasy
{
/// <summary>
/// A rule that intercepts method calls. Supplies the return and all out and ref values
/// from the fixture. When a method is called repeatedly with the same arguments, the
/// from the fixture. When a method is called repeatedly with the same arguments, the
/// same return value and out and ref values will be provided.
/// </summary>
internal class MethodRule : IFakeObjectCallRule
Expand Down Expand Up @@ -45,7 +45,7 @@ public void Apply(IInterceptedFakeObjectCall interceptedFakeObjectCall)
if (interceptedFakeObjectCall == null) throw new ArgumentNullException(nameof(interceptedFakeObjectCall));

var fakeObjectCall = new FakeObjectCall(interceptedFakeObjectCall);
var callResult = this.resultSource.GetOrAdd(CreateMethodCall(fakeObjectCall), () => CreateMethodCallResult(fakeObjectCall));
var callResult = this.resultSource.GetOrAdd(CreateMethodCall(fakeObjectCall), () => this.CreateMethodCallResult(fakeObjectCall));
callResult.ApplyToCall(fakeObjectCall);
}

Expand All @@ -57,8 +57,8 @@ private static MethodCall CreateMethodCall(FakeObjectCall fakeCall)

private MethodCallResult CreateMethodCallResult(FakeObjectCall fakeObjectCall)
{
var result = new MethodCallResult(ResolveReturnValue(fakeObjectCall));
AddOutAndRefValues(result, fakeObjectCall);
var result = new MethodCallResult(this.ResolveReturnValue(fakeObjectCall));
this.AddOutAndRefValues(result, fakeObjectCall);
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions Src/AutoFakeItEasy/Properties/AssemblyInfo.cs
Expand Up @@ -3,13 +3,13 @@
using System.Resources;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// 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: 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
// 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)]

Expand Down
4 changes: 2 additions & 2 deletions Src/AutoFakeItEasy/PropertySetterRule.cs
Expand Up @@ -6,7 +6,7 @@
namespace AutoFixture.AutoFakeItEasy
{
/// <summary>
/// A rule that intercepts property setter calls. Values will be saved into a result cache to be
/// A rule that intercepts property setter calls. Values will be saved into a result cache to be
/// provided as the return value from the matching get methods when the latter are called.
/// </summary>
internal class PropertySetterRule : IFakeObjectCallRule
Expand Down Expand Up @@ -37,7 +37,7 @@ public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)

/// <summary>
/// Stores the value provided in the property setter to be returned from later
/// calls to the corresponding getter.
/// calls to the corresponding getter.
/// </summary>
/// <param name="interceptedFakeObjectCall">The call to apply the rule to.</param>
public void Apply(IInterceptedFakeObjectCall interceptedFakeObjectCall)
Expand Down
2 changes: 1 addition & 1 deletion Src/AutoFakeItEasy2/FakeItEasyMethodQuery.cs
Expand Up @@ -52,7 +52,7 @@ private static class FakeMethod
Type type,
IEnumerable<ParameterInfo> parameterInfos)
{
var constructedType =
var constructedType =
typeof(FakeMethod<>).MakeGenericType(type);
return (IMethod)Activator.CreateInstance(
constructedType,
Expand Down
4 changes: 2 additions & 2 deletions Src/AutoFakeItEasy2/FakeItEasyType.cs
Expand Up @@ -10,10 +10,10 @@ internal static class FakeItEasyType
{
internal static bool IsFake(this Type type)
{
return (type != null
return type != null
&& type.IsGenericType
&& typeof(Fake<>).IsAssignableFrom(type.GetGenericTypeDefinition())
&& !type.GetFakedType().IsGenericParameter);
&& !type.GetFakedType().IsGenericParameter;
}

internal static ConstructorInfo GetDefaultConstructor(this Type type)
Expand Down
8 changes: 4 additions & 4 deletions Src/AutoFakeItEasy2/GlobalSuppressions.cs
@@ -1,10 +1,10 @@
// This file is used by Code Analysis to maintain SuppressMessage
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.

Expand Down

0 comments on commit b9a3f4d

Please sign in to comment.