Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 6df288b

Browse files
committed
Correct StyleCop violations
- StyleCop working again (handles C# 6.0 additions) though only locally for me - disable some new rules: - ConstFieldNamesMustBeginWithUpperCaseLetter - InstanceReadonlyElementsMustAppearBeforeInstanceNonReadonlyElements - StaticReadonlyElementsMustAppearBeforeStaticNonReadonlyElements - StaticReadonlyFieldsMustBeginWithUpperCaseLetter - PrefixCallsCorrectly - correct remaining violations - lots of long lines for example - use more `var`; some manual updates since StyleCop doesn't check seemingly-unused blocks nit: remove new trailing whitespace (was paranoid about adding it w/ fixes)
1 parent 227f564 commit 6df288b

File tree

90 files changed

+674
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+674
-444
lines changed

Diff for: Settings.StyleCop

+26-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<Analyzers>
1313
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
1414
<Rules>
15+
<Rule Name="ConstFieldNamesMustBeginWithUpperCaseLetter">
16+
<RuleSettings>
17+
<BooleanProperty Name="Enabled">False</BooleanProperty>
18+
</RuleSettings>
19+
</Rule>
1520
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
1621
<RuleSettings>
1722
<BooleanProperty Name="Enabled">False</BooleanProperty>
@@ -22,6 +27,11 @@
2227
<BooleanProperty Name="Enabled">False</BooleanProperty>
2328
</RuleSettings>
2429
</Rule>
30+
<Rule Name="StaticReadonlyFieldsMustBeginWithUpperCaseLetter">
31+
<RuleSettings>
32+
<BooleanProperty Name="Enabled">False</BooleanProperty>
33+
</RuleSettings>
34+
</Rule>
2535
</Rules>
2636
<AnalyzerSettings>
2737
<CollectionProperty Name="Hungarian">
@@ -274,6 +284,11 @@
274284
<BooleanProperty Name="Enabled">False</BooleanProperty>
275285
</RuleSettings>
276286
</Rule>
287+
<Rule Name="PrefixCallsCorrectly">
288+
<RuleSettings>
289+
<BooleanProperty Name="Enabled">False</BooleanProperty>
290+
</RuleSettings>
291+
</Rule>
277292
<Rule Name="PrefixLocalCallsWithThis">
278293
<RuleSettings>
279294
<BooleanProperty Name="Enabled">False</BooleanProperty>
@@ -384,11 +399,21 @@
384399
<BooleanProperty Name="Enabled">False</BooleanProperty>
385400
</RuleSettings>
386401
</Rule>
402+
<Rule Name="InstanceReadonlyElementsMustAppearBeforeInstanceNonReadonlyElements">
403+
<RuleSettings>
404+
<BooleanProperty Name="Enabled">False</BooleanProperty>
405+
</RuleSettings>
406+
</Rule>
387407
<Rule Name="StaticElementsMustAppearBeforeInstanceElements">
388408
<RuleSettings>
389409
<BooleanProperty Name="Enabled">False</BooleanProperty>
390410
</RuleSettings>
391411
</Rule>
412+
<Rule Name="StaticReadonlyElementsMustAppearBeforeStaticNonReadonlyElements">
413+
<RuleSettings>
414+
<BooleanProperty Name="Enabled">False</BooleanProperty>
415+
</RuleSettings>
416+
</Rule>
392417
</Rules>
393418
<AnalyzerSettings />
394419
</Analyzer>
@@ -399,7 +424,7 @@
399424
<BooleanProperty Name="Enabled">False</BooleanProperty>
400425
</RuleSettings>
401426
</Rule>
402-
427+
403428
<!-- Creates a lot of noise with anonymous objects -->
404429
<Rule Name="OpeningCurlyBracketsMustBeSpacedCorrectly">
405430
<RuleSettings>

Diff for: src/Microsoft.AspNet.Mvc.Common/TypeExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private static bool EqualTo([NotNull] this Type[] t1, [NotNull] Type[] t2)
1919
return false;
2020
}
2121

22-
for (int idx = 0; idx < t1.Length; ++idx)
22+
for (var idx = 0; idx < t1.Length; ++idx)
2323
{
2424
if (t1[idx] != t2[idx])
2525
{

Diff for: src/Microsoft.AspNet.Mvc.Core/ActionResults/FilePathResult.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ internal string ResolveFilePath(IFileSystem fileSystem)
119119
throw new FileNotFoundException(message, path);
120120
}
121121

122-
// Internal for unit testing purposes only
123122
/// <summary>
124123
/// Creates a normalized representation of the given <paramref name="path"/>. The default
125124
/// implementation doesn't support files with '\' in the file name and treats the '\' as
@@ -128,6 +127,7 @@ internal string ResolveFilePath(IFileSystem fileSystem)
128127
/// </summary>
129128
/// <param name="path">The path to normalize.</param>
130129
/// <returns>The normalized path.</returns>
130+
// Internal for unit testing purposes only
131131
protected internal virtual string NormalizePath([NotNull] string path)
132132
{
133133
// Unix systems support '\' as part of the file name. So '\' is not
@@ -153,13 +153,13 @@ protected internal virtual string NormalizePath([NotNull] string path)
153153
return path.Replace('\\', '/');
154154
}
155155

156-
// Internal for unit testing purposes only
157156
/// <summary>
158157
/// Determines if the provided path is absolute or relative. The default implementation considers
159158
/// paths starting with '/' to be relative.
160159
/// </summary>
161160
/// <param name="path">The path to examine.</param>
162161
/// <returns>True if the path is absolute.</returns>
162+
// Internal for unit testing purposes only
163163
protected internal virtual bool IsPathRooted([NotNull] string path)
164164
{
165165
// We consider paths to be rooted if they start with '<<VolumeLetter>>:' and do

Diff for: src/Microsoft.AspNet.Mvc.Core/ActionResults/FileResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static void AddByteToStringBuilder(byte b, StringBuilder builder)
8484
{
8585
builder.Append('%');
8686

87-
int i = b;
87+
var i = b;
8888
AddHexDigitToStringBuilder(i >> 4, builder);
8989
AddHexDigitToStringBuilder(i % 16, builder);
9090
}

Diff for: src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryToken.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
54
namespace Microsoft.AspNet.Mvc
65
{
76
internal sealed class AntiForgeryToken

Diff for: src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenStore.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ internal AntiForgeryTokenStore([NotNull] AntiForgeryOptions config,
2323

2424
public AntiForgeryToken GetCookieToken(HttpContext httpContext)
2525
{
26-
var contextAccessor = httpContext.RequestServices.GetRequiredService<IContextAccessor<AntiForgeryContext>>();
26+
var contextAccessor =
27+
httpContext.RequestServices.GetRequiredService<IContextAccessor<AntiForgeryContext>>();
2728
if (contextAccessor.Value != null)
2829
{
2930
return contextAccessor.Value.CookieToken;
@@ -56,7 +57,8 @@ public void SaveCookieToken(HttpContext httpContext, AntiForgeryToken token)
5657
{
5758
// Add the cookie to the request based context.
5859
// This is useful if the cookie needs to be reloaded in the context of the same request.
59-
var contextAccessor = httpContext.RequestServices.GetRequiredService<IContextAccessor<AntiForgeryContext>>();
60+
var contextAccessor =
61+
httpContext.RequestServices.GetRequiredService<IContextAccessor<AntiForgeryContext>>();
6062
Debug.Assert(contextAccessor.Value == null, "AntiForgeryContext should be set only once per request.");
6163
contextAccessor.SetValue(new AntiForgeryContext() { CookieToken = token });
6264

Diff for: src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultActionModelBuilder.cs

-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ private bool IsIDisposableMethod(MethodInfo methodInfo, TypeInfo typeInfo)
233233
typeInfo.GetRuntimeInterfaceMap(typeof(IDisposable)).TargetMethods[0] == methodInfo);
234234
}
235235

236-
237236
/// <summary>
238237
/// Creates an <see cref="ActionModel"/> for the given <see cref="MethodInfo"/>.
239238
/// </summary>

Diff for: src/Microsoft.AspNet.Mvc.Core/Controller.cs

+16-17
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ public IViewEngine ViewEngine
6767
{
6868
if (_viewEngine == null)
6969
{
70-
_viewEngine = ActionContext?.
71-
HttpContext?.
72-
RequestServices.GetRequiredService<ICompositeViewEngine>();
70+
_viewEngine =
71+
ActionContext?.HttpContext?.RequestServices.GetRequiredService<ICompositeViewEngine>();
7372
}
7473

7574
return _viewEngine;
@@ -797,7 +796,7 @@ public virtual async Task OnActionExecutionAsync(
797796
}
798797

799798
/// <summary>
800-
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
799+
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
801800
/// <see cref="IValueProvider"/>.
802801
/// </summary>
803802
/// <typeparam name="TModel">The type of the model object.</typeparam>
@@ -811,7 +810,7 @@ public virtual Task<bool> TryUpdateModelAsync<TModel>([NotNull] TModel model)
811810
}
812811

813812
/// <summary>
814-
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
813+
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
815814
/// <see cref="IValueProvider"/> and a <paramref name="prefix"/>.
816815
/// </summary>
817816
/// <typeparam name="TModel">The type of the model object.</typeparam>
@@ -826,7 +825,7 @@ public virtual async Task<bool> TryUpdateModelAsync<TModel>([NotNull] TModel mod
826825
{
827826
if (BindingContextProvider == null)
828827
{
829-
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
828+
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
830829
GetType().FullName);
831830
throw new InvalidOperationException(message);
832831
}
@@ -836,7 +835,7 @@ public virtual async Task<bool> TryUpdateModelAsync<TModel>([NotNull] TModel mod
836835
}
837836

838837
/// <summary>
839-
/// Updates the specified <paramref name="model"/> instance using the <paramref name="valueProvider"/> and a
838+
/// Updates the specified <paramref name="model"/> instance using the <paramref name="valueProvider"/> and a
840839
/// <paramref name="prefix"/>.
841840
/// </summary>
842841
/// <typeparam name="TModel">The type of the model object.</typeparam>
@@ -853,7 +852,7 @@ public virtual async Task<bool> TryUpdateModelAsync<TModel>([NotNull] TModel mod
853852
{
854853
if (BindingContextProvider == null)
855854
{
856-
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
855+
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
857856
GetType().FullName);
858857
throw new InvalidOperationException(message);
859858
}
@@ -870,14 +869,14 @@ public virtual async Task<bool> TryUpdateModelAsync<TModel>([NotNull] TModel mod
870869
}
871870

872871
/// <summary>
873-
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
872+
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
874873
/// <see cref="IValueProvider"/> and a <paramref name="prefix"/>.
875874
/// </summary>
876875
/// <typeparam name="TModel">The type of the model object.</typeparam>
877876
/// <param name="model">The model instance to update.</param>
878877
/// <param name="prefix">The prefix to use when looking up values in the current <see cref="IValueProvider"/>.
879878
/// </param>
880-
/// <param name="includeExpressions"> <see cref="Expression"/>(s) which represent top-level properties
879+
/// <param name="includeExpressions"> <see cref="Expression"/>(s) which represent top-level properties
881880
/// which need to be included for the current model.</param>
882881
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful</returns>
883882
[NonAction]
@@ -907,7 +906,7 @@ public async Task<bool> TryUpdateModelAsync<TModel>(
907906
}
908907

909908
/// <summary>
910-
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
909+
/// Updates the specified <paramref name="model"/> instance using values from the controller's current
911910
/// <see cref="IValueProvider"/> and a <paramref name="prefix"/>.
912911
/// </summary>
913912
/// <typeparam name="TModel">The type of the model object.</typeparam>
@@ -925,7 +924,7 @@ public async Task<bool> TryUpdateModelAsync<TModel>(
925924
{
926925
if (BindingContextProvider == null)
927926
{
928-
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
927+
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
929928
GetType().FullName);
930929
throw new InvalidOperationException(message);
931930
}
@@ -943,15 +942,15 @@ public async Task<bool> TryUpdateModelAsync<TModel>(
943942
}
944943

945944
/// <summary>
946-
/// Updates the specified <paramref name="model"/> instance using the <paramref name="valueProvider"/> and a
945+
/// Updates the specified <paramref name="model"/> instance using the <paramref name="valueProvider"/> and a
947946
/// <paramref name="prefix"/>.
948947
/// </summary>
949948
/// <typeparam name="TModel">The type of the model object.</typeparam>
950949
/// <param name="model">The model instance to update.</param>
951950
/// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>
952951
/// </param>
953952
/// <param name="valueProvider">The <see cref="IValueProvider"/> used for looking up values.</param>
954-
/// <param name="includeExpressions"> <see cref="Expression"/>(s) which represent top-level properties
953+
/// <param name="includeExpressions"> <see cref="Expression"/>(s) which represent top-level properties
955954
/// which need to be included for the current model.</param>
956955
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful</returns>
957956
[NonAction]
@@ -964,7 +963,7 @@ public async Task<bool> TryUpdateModelAsync<TModel>(
964963
{
965964
if (BindingContextProvider == null)
966965
{
967-
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
966+
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
968967
GetType().FullName);
969968
throw new InvalidOperationException(message);
970969
}
@@ -982,7 +981,7 @@ public async Task<bool> TryUpdateModelAsync<TModel>(
982981
}
983982

984983
/// <summary>
985-
/// Updates the specified <paramref name="model"/> instance using the <paramref name="valueProvider"/> and a
984+
/// Updates the specified <paramref name="model"/> instance using the <paramref name="valueProvider"/> and a
986985
/// <paramref name="prefix"/>.
987986
/// </summary>
988987
/// <typeparam name="TModel">The type of the model object.</typeparam>
@@ -1002,7 +1001,7 @@ public async Task<bool> TryUpdateModelAsync<TModel>(
10021001
{
10031002
if (BindingContextProvider == null)
10041003
{
1005-
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
1004+
var message = Resources.FormatPropertyOfTypeCannotBeNull(nameof(BindingContextProvider),
10061005
GetType().FullName);
10071006
throw new InvalidOperationException(message);
10081007
}

Diff for: src/Microsoft.AspNet.Mvc.Core/ControllerActionDescriptorProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using Microsoft.AspNet.Mvc.ApplicationModels;
8-
using Microsoft.AspNet.Mvc.Logging;
98
using Microsoft.AspNet.Mvc.Filters;
9+
using Microsoft.AspNet.Mvc.Logging;
1010
using Microsoft.Framework.Logging;
1111
using Microsoft.Framework.OptionsModel;
1212

Diff for: src/Microsoft.AspNet.Mvc.Core/DefaultAssemblyProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc
1313
public class DefaultAssemblyProvider : IAssemblyProvider
1414
{
1515
/// <summary>
16-
/// Gets the set of assembly names that are used as root for discovery of
16+
/// Gets the set of assembly names that are used as root for discovery of
1717
/// MVC controllers, view components and views.
1818
/// </summary>
1919
protected virtual HashSet<string> ReferenceAssemblies { get; } = new HashSet<string>(StringComparer.Ordinal)
@@ -44,7 +44,7 @@ public IEnumerable<Assembly> CandidateAssemblies
4444

4545
/// <summary>
4646
/// Returns a list of libraries that references the assemblies in <see cref="ReferenceAssemblies"/>.
47-
/// By default it returns all assemblies that reference any of the primary MVC assemblies
47+
/// By default it returns all assemblies that reference any of the primary MVC assemblies
4848
/// while ignoring MVC assemblies.
4949
/// </summary>
5050
/// <returns>A set of <see cref="ILibraryInformation"/>.</returns>

Diff for: src/Microsoft.AspNet.Mvc.Core/DefaultControllerActionArgumentBinder.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ private async Task PopulateArgumentAsync(
8787
foreach (var parameter in parameterMetadata)
8888
{
8989
var parameterType = parameter.ModelType;
90-
var modelBindingContext = GetModelBindingContext(parameter, actionBindingContext, operationBindingContext);
90+
var modelBindingContext =
91+
GetModelBindingContext(parameter, actionBindingContext, operationBindingContext);
9192
if (await actionBindingContext.ModelBinder.BindModelAsync(modelBindingContext))
9293
{
9394
arguments[parameter.PropertyName] = modelBindingContext.Model;

Diff for: src/Microsoft.AspNet.Mvc.Core/DefaultPropertyBindingPredicateProvider.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace Microsoft.AspNet.Mvc
1717
public class DefaultPropertyBindingPredicateProvider<TModel> : IPropertyBindingPredicateProvider
1818
where TModel : class
1919
{
20-
private static readonly Func<ModelBindingContext, string, bool> _defaultFilter = (context, propertyName) => true;
20+
private static readonly Func<ModelBindingContext, string, bool> _defaultFilter =
21+
(context, propertyName) => true;
2122

2223
/// <summary>
2324
/// The prefix which is used while generating the property filter.
@@ -57,7 +58,8 @@ public virtual Func<ModelBindingContext, string, bool> PropertyFilter
5758
}
5859
}
5960

60-
private Func<ModelBindingContext, string, bool> GetPredicateFromExpression(IEnumerable<Expression<Func<TModel, object>>> includeExpressions)
61+
private Func<ModelBindingContext, string, bool> GetPredicateFromExpression(
62+
IEnumerable<Expression<Func<TModel, object>>> includeExpressions)
6163
{
6264
var expression = ModelBindingHelper.GetIncludePredicateExpression(Prefix, includeExpressions.ToArray());
6365
return expression.Compile();

Diff for: src/Microsoft.AspNet.Mvc.Core/Description/DefaultApiDescriptionProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public int Order
4545
get { return DefaultOrder.DefaultFrameworkSortOrder; }
4646
}
4747

48-
4948
/// <inheritdoc />
5049
public void Invoke(ApiDescriptionProviderContext context, Action callNext)
5150
{
@@ -157,7 +156,8 @@ private void GetParameters(
157156
// Process parameters that only appear on the path template if any.
158157
foreach (var templateParameter in templateParameters)
159158
{
160-
var parameterDescription = GetParameter(parameterDescriptor: null, templateParameter: templateParameter);
159+
var parameterDescription =
160+
GetParameter(parameterDescriptor: null, templateParameter: templateParameter);
161161
apiDescription.ParameterDescriptions.Add(parameterDescription);
162162
}
163163
}

Diff for: src/Microsoft.AspNet.Mvc.Core/Filters/IAuthorizationFilter.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
54
namespace Microsoft.AspNet.Mvc
65
{
76
public interface IAuthorizationFilter : IFilter

Diff for: src/Microsoft.AspNet.Mvc.Core/Filters/IExceptionFilter.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
54
namespace Microsoft.AspNet.Mvc
65
{
76
public interface IExceptionFilter : IFilter

Diff for: src/Microsoft.AspNet.Mvc.Core/Formatters/IInputFormatterSelector.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
54
namespace Microsoft.AspNet.Mvc
65
{
76
public interface IInputFormatterSelector

Diff for: src/Microsoft.AspNet.Mvc.Core/HttpMethodAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Mvc
1313
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
1414
public abstract class HttpMethodAttribute : Attribute, IActionHttpMethodProvider, IRouteTemplateProvider
1515
{
16-
private int? _order;
1716
private readonly IEnumerable<string> _httpMethods;
17+
private int? _order;
1818

1919
/// <summary>
2020
/// Creates a new <see cref="HttpMethodAttribute"/> with the given

0 commit comments

Comments
 (0)