Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
Enable FxCop v11, clean up new violations, renumber old rules to new …
Browse files Browse the repository at this point in the history
…numbers
  • Loading branch information
bradwilson committed Sep 5, 2012
1 parent 7321853 commit 7169bcd
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .nuget/NuGet.targets
Expand Up @@ -69,9 +69,9 @@
Command='$(NuGetCommand) install StyleCop -source $(PackageSources) -o "$(PackagesDir)" -Version 4.7.10.0 > NUL'
LogStandardErrorAsError="true" />
<Exec
Command='$(NuGetCommand) install Microsoft.Web.FxCop -source $(PackageSources) -o "$(PackagesDir)" -ExcludeVersion > NUL'
Command='$(NuGetCommand) install Microsoft.Web.FxCop.v11 -source $(PackageSources) -o "$(PackagesDir)" -ExcludeVersion > NUL'
LogStandardErrorAsError="true"
Condition=" !Exists('$(PackagesDir)\Microsoft.Web.FxCop') " />
Condition=" !Exists('$(PackagesDir)\Microsoft.Web.FxCop.v11') " />
<Exec
Command='$(NuGetCommand) install Microsoft.Web.StyleCop -source $(PackageSources) -o "$(PackagesDir)" -ExcludeVersion > NUL'
LogStandardErrorAsError="true"
Expand Down
5 changes: 1 addition & 4 deletions Runtime.msbuild
@@ -1,10 +1,7 @@
<Project DefaultTargets="UnitTest" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>

<!-- TODO: CodeAnalysis is off by default in VS11 because FxCop cannot load custom rules built against Dev10 -->
<CodeAnalysis Condition=" '$(CodeAnalysis)' == '' and '$(VS110COMNTOOLS)' == ''">true</CodeAnalysis>

<CodeAnalysis Condition=" '$(CodeAnalysis)' == '' ">true</CodeAnalysis>
<StyleCopEnabled Condition=" '$(StyleCopEnabled)' == '' ">true</StyleCopEnabled>
<BuildInParallel Condition=" '$(BuildInParallel)' == '' And $(MSBuildNodeCount) &gt; 1 ">true</BuildInParallel>
<BuildInParallel Condition=" '$(BuildInParallel)' == '' ">false</BuildInParallel>
Expand Down
8 changes: 8 additions & 0 deletions src/CodeAnalysisDictionary.xml
Expand Up @@ -41,12 +41,20 @@
<Word>fwlink</Word>
<Word>Edm</Word>
<Word>Deserializer</Word>
<Word>Api</Word>
<Word>ws</Word>
<Word>enc</Word>
<Word>dir</Word>
<Word>Auth</Word>
<Word>bg</Word>
</Recognized>
<Compound>
<Term CompoundAlternate="WebPage">WebPage</Term>
<Term CompoundAlternate="WebPages">WebPages</Term>
<Term CompoundAlternate="TimeLine">TimeLine</Term>
<Term CompoundAlternate="OAuth">oAuth</Term>
<Term CompoundAlternate="UserName">userName</Term>
<Term CompoundAlternate="HasId">HasId</Term>
</Compound>
</Words>
<Acronyms>
Expand Down
4 changes: 2 additions & 2 deletions src/Common/TaskHelpers.cs
Expand Up @@ -301,7 +301,7 @@ internal static bool SetIfTaskFailed<TResult>(this TaskCompletionSource<TResult>
/// <param name="tcs">completion source to set</param>
/// <param name="source">Task to get values from.</param>
/// <returns>true if this successfully sets the completion source.</returns>
[SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Justification = "This is a known safe usage of Task.Result, since it only occurs when we know the task's state to be completed.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1201:DoNotCallProblematicMethodsOnTask", Justification = "This is a known safe usage of Task.Result, since it only occurs when we know the task's state to be completed.")]
internal static bool TrySetFromTask<TResult>(this TaskCompletionSource<TResult> tcs, Task source)
{
if (source.Status == TaskStatus.Canceled)
Expand Down Expand Up @@ -333,7 +333,7 @@ internal static bool TrySetFromTask<TResult>(this TaskCompletionSource<TResult>
/// <param name="tcs">completion source to set</param>
/// <param name="source">Task to get values from.</param>
/// <returns>true if this successfully sets the completion source.</returns>
[SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Justification = "This is a known safe usage of Task.Result, since it only occurs when we know the task's state to be completed.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1201:DoNotCallProblematicMethodsOnTask", Justification = "This is a known safe usage of Task.Result, since it only occurs when we know the task's state to be completed.")]
internal static bool TrySetFromTask<TResult>(this TaskCompletionSource<Task<TResult>> tcs, Task source)
{
if (source.Status == TaskStatus.Canceled)
Expand Down
38 changes: 19 additions & 19 deletions src/Common/TaskHelpersExtensions.cs

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/Strict.ruleset
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="FxCop rules for ASP.NET Web Stack" Description="This rule set contains the rules for ASP.NET Web Stack." ToolsVersion="10.0">
<RuleHintPaths>
<Path>..\packages\Microsoft.Web.FxCop</Path>
<Path>..\packages\Microsoft.Web.FxCop.v11</Path>
</RuleHintPaths>
<IncludeAll Action="Error" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1062" Action="None" />
<Rule Id="MW1000" Action="Warning" />
</Rules>
</RuleSet>
Expand Up @@ -20,8 +20,8 @@ public MultipartWriteDelegatingStream(Stream innerStream)
{
}

[SuppressMessage("Microsoft.WebAPI", "CR4000:DoNotUseProblematicTaskTypes", Justification = "FromAsync is used to get around a rave condition.")]
[SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Justification = "FromAsync is used to get around a rave condition.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1201:DoNotCallProblematicMethodsOnTaskRule", Justification = "FromAsync is used to get around a race condition.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1202:DoNotUseProblematicTaskTypesRule", Justification = "FromAsync is used to get around a race condition.")]
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
Task writeTask = Task.Factory.FromAsync(InnerStream.BeginWrite, InnerStream.EndWrite, buffer, offset, count, state);
Expand Down
38 changes: 1 addition & 37 deletions src/System.Web.Http.OData/Properties/SRResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions src/System.Web.Http.OData/Properties/SRResources.resx
Expand Up @@ -192,9 +192,6 @@
<data name="EntityClrTypeNotMatchEntitySet" xml:space="preserve">
<value>The EntityClrType '{0}' does not match with the given entitySet '{1}'.</value>
</data>
<data name="OrderByNodeNotFound" xml:space="preserve">
<value>There is no OrderByQueryNode found.</value>
</data>
<data name="OrderByPropertyNotFound" xml:space="preserve">
<value>It is unsupported that the OrderByQueryNode.Expression is not an instance of PropertyAccessQueryNode type.</value>
</data>
Expand Down Expand Up @@ -345,15 +342,6 @@
<data name="MustBeCollectionProperty" xml:space="preserve">
<value>The '{0}' property on '{1}' must be a Collection property.</value>
</data>
<data name="CannotPatchNavigationProperties" xml:space="preserve">
<value>Cannot apply PATCH navigation property '{0}' on entity type '{1}'.</value>
</data>
<data name="CollectionShouldHaveAddMethod" xml:space="preserve">
<value>The property '{0}' on type '{1}' has a non-null value. Collection properties with value should have the Add method.</value>
</data>
<data name="PropertyIsNotCollection" xml:space="preserve">
<value>The property '{0}' on type '{1}' must be a collection.</value>
</data>
<data name="PropertyMustBeString" xml:space="preserve">
<value>The property '{0}' on type '{1}' must be a string.</value>
</data>
Expand Down
Expand Up @@ -159,7 +159,7 @@ public override ArraySegment<byte> WriteMessage(Message message, int maxMessageS
}
}

[SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Justification = "The WriteMessage() API is synchronous, and Wait() won't deadlock in self-host.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1201:DoNotCallProblematicMethodsOnTask", Justification = "The WriteMessage() API is synchronous, and Wait() won't deadlock in self-host.")]
public override void WriteMessage(Message message, Stream stream)
{
if (message == null)
Expand Down
1 change: 1 addition & 0 deletions src/System.Web.Http.SelfHost/HttpSelfHostServer.cs
Expand Up @@ -166,6 +166,7 @@ protected override void Dispose(bool disposing)

[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "ReplyContext and HttpResponseMessage are disposed later.")]
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We never want to fail here so we have to catch all exceptions.")]
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "This method is a coordinator, so this coupling is expected.")]
private void ProcessRequestContext(ChannelContext channelContext, System.ServiceModel.Channels.RequestContext requestContext)
{
Contract.Assert(channelContext != null);
Expand Down
3 changes: 2 additions & 1 deletion src/System.Web.Http.WebHost/HttpControllerHandler.cs
Expand Up @@ -23,6 +23,7 @@ namespace System.Web.Http.WebHost
/// A <see cref="IHttpAsyncHandler"/> that passes ASP.NET requests into the <see cref="HttpServer"/>
/// pipeline and write the result back.
/// </summary>
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "This class is a coordinator, so this coupling is expected.")]
public class HttpControllerHandler : IHttpAsyncHandler
{
internal static readonly string HttpContextBaseKey = "MS_HttpContext";
Expand Down Expand Up @@ -143,7 +144,7 @@ protected virtual void ProcessRequest(HttpContextBase httpContextBase)
/// <param name="callback">The callback.</param>
/// <param name="state">The state.</param>
/// <returns>An <see cref="IAsyncResult"/> that contains information about the status of the process. </returns>
[SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Justification = "This is commented in great details.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1201:DoNotCallProblematicMethodsOnTask", Justification = "This is commented in great details.")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Object gets passed to a task")]
protected virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, object state)
{
Expand Down
1 change: 1 addition & 0 deletions src/System.Web.Http/ApiController.cs
Expand Up @@ -138,6 +138,7 @@ public IPrincipal User
get { return Thread.CurrentPrincipal; }
}

[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "This method is a coordinator, so this coupling is expected.")]
public virtual Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
{
if (_request != null)
Expand Down
4 changes: 2 additions & 2 deletions src/System.Web.Http/GlobalSuppressions.cs
Expand Up @@ -14,8 +14,8 @@
[assembly: SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "System.Web.Http.Filters.AuthorizationFilterAttribute.#System.Web.Http.Filters.IAuthorizationFilter.ExecuteAuthorizationFilterAsync(System.Web.Http.Controllers.HttpActionContext,System.Threading.CancellationToken,System.Func`1<System.Threading.Tasks.Task`1<System.Net.Http.HttpResponseMessage>>)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "System.Web.Http.Filters.ExceptionFilterAttribute.#System.Web.Http.Filters.IExceptionFilter.ExecuteExceptionFilterAsync(System.Web.Http.Filters.HttpActionExecutedContext,System.Threading.CancellationToken)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "System.Web.Http.Filters.ActionFilterAttribute.#System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync(System.Web.Http.Controllers.HttpActionContext,System.Threading.CancellationToken,System.Func`1<System.Threading.Tasks.Task`1<System.Net.Http.HttpResponseMessage>>)")]
[assembly: SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Scope = "member", Target = "System.Web.Http.Tracing.Tracers.ActionInvokerTracer.#System.Web.Http.Controllers.IHttpActionInvoker.InvokeActionAsync(System.Web.Http.Controllers.HttpActionContext,System.Threading.CancellationToken)", Justification = "Tracing layer needs to observe all Task completion paths")]
[assembly: SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Scope = "member", Target = "System.Web.Http.Tracing.Tracers.ApiControllerTracer.#System.Web.Http.Controllers.IHttpController.ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext,System.Threading.CancellationToken)", Justification = "Tracing layer needs to observe all Task completion paths")]
[assembly: SuppressMessage("Microsoft.WebAPI", "MW1201:DoNotCallProblematicMethodsOnTask", Scope = "member", Target = "System.Web.Http.Tracing.Tracers.ActionInvokerTracer.#System.Web.Http.Controllers.IHttpActionInvoker.InvokeActionAsync(System.Web.Http.Controllers.HttpActionContext,System.Threading.CancellationToken)", Justification = "Tracing layer needs to observe all Task completion paths")]
[assembly: SuppressMessage("Microsoft.WebAPI", "MW1201:DoNotCallProblematicMethodsOnTask", Scope = "member", Target = "System.Web.Http.Tracing.Tracers.ApiControllerTracer.#System.Web.Http.Controllers.IHttpController.ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext,System.Threading.CancellationToken)", Justification = "Tracing layer needs to observe all Task completion paths")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Formatting", Justification = "Namespace follows folder structure")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http.Dependencies", Justification = "Namespace follows folder structure")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http.Tracing.Tracers", Justification = "Namespace follows folder structure")]
Expand Down
Expand Up @@ -48,6 +48,7 @@ internal CultureInfo Culture
// This method turns a collection of name/value pairs into a Dictionary<string, object> for fast lookups
// We optimize for the common case of a name being associated with exactly one value by avoiding a List allocation if we can avoid it
// The first time the key appears, the value gets stored as a string. Only if the key appears a second time do we allocate a List to store the values for that key.
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "One of the casts is conditionally compiled")]
private static Dictionary<string, object> InitializeValues(IEnumerable<KeyValuePair<string, string>> nameValuePairs)
{
Dictionary<string, object> values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
Expand All @@ -68,7 +69,7 @@ internal CultureInfo Culture
else
{
valueStrings.Add(nameValuePair.Value);
}
}
}
else
{
Expand Down Expand Up @@ -111,6 +112,7 @@ public virtual ValueProviderResult GetValue(string key)
}
}

[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "One of the casts is conditionally compiled")]
private static string GetAttemptedValue(object value)
{
List<string> valueStrings = value as List<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/System.Web.Mvc/Async/TaskAsyncActionDescriptor.cs
Expand Up @@ -84,7 +84,7 @@ private string CreateUniqueId()
return base.UniqueId + DescriptorUtil.CreateUniqueId(TaskMethodInfo);
}

[SuppressMessage("Microsoft.WebAPI", "CR4001:DoNotCallProblematicMethodsOnTask", Justification = "This is commented in great detail.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1201:DoNotCallProblematicMethodsOnTask", Justification = "This is commented in great detail.")]
public override IAsyncResult BeginExecute(ControllerContext controllerContext, IDictionary<string, object> parameters, AsyncCallback callback, object state)
{
if (controllerContext == null)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Web.Razor/Parser/RazorParser.cs
Expand Up @@ -97,7 +97,7 @@ public virtual Task CreateParseTask(TextReader input, Action<Span> spanCallback,
});
}

[SuppressMessage("Microsoft.WebAPI", "CR4002:DoNotConstructTaskInstances", Justification = "This rule is not applicable to this assembly.")]
[SuppressMessage("Microsoft.Web.FxCop", "MW1200:DoNotConstructTaskInstances", Justification = "This rule is not applicable to this assembly.")]
public virtual Task CreateParseTask(TextReader input,
ParserVisitor consumer)
{
Expand Down

0 comments on commit 7169bcd

Please sign in to comment.