Skip to content

Commit 9ca59cf

Browse files
committed
Updated analyzers, fixed issues (braces, headers).
1 parent e62b5d7 commit 9ca59cf

File tree

49 files changed

+235
-118
lines changed

Some content is hidden

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

49 files changed

+235
-118
lines changed

build/Analyzers.ruleset

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="14.0">
3-
<!-- https://github.com/dotnet/roslyn/blob/master/docs/compilers/Rule%20Set%20Format.md -->
2+
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
43
<IncludeAll Action="Warning" />
4+
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
5+
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
6+
<Rule Id="CA1032" Action="None" />
7+
<!-- Change names to avoid reserved word overlaps (e.g., Delegate, GetType, etc.) - too many of these in the public API, we'd break if we fixed it. -->
8+
<Rule Id="CA1716" Action="None" />
9+
<!-- Implement serialization constructors - false positive when building .NET Core -->
10+
<Rule Id="CA2229" Action="None" />
11+
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
12+
<Rule Id="CA2237" Action="None" />
13+
</Rules>
514
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
615
<!-- Prefix local calls with this -->
716
<Rule Id="SA1101" Action="None" />
@@ -11,39 +20,9 @@
1120
<Rule Id="SA1122" Action="None" />
1221
<!-- Using statements must be inside a namespace -->
1322
<Rule Id="SA1200" Action="None" />
14-
<!-- Enforce order of class members by member type -->
15-
<Rule Id="SA1201" Action="None" />
16-
<!-- Enforce order of class members by member visibility -->
17-
<Rule Id="SA1202" Action="None" />
18-
<!-- Enforce order of constantand static members -->
19-
<Rule Id="SA1203" Action="None" />
20-
<!-- Enforce order of static vs. non-static members -->
21-
<Rule Id="SA1204" Action="None" />
22-
<!-- Enforce order of readonly vs. non-readonly members -->
23-
<Rule Id="SA1214" Action="None" />
2423
<!-- Fields can't start with underscore -->
2524
<Rule Id="SA1309" Action="None" />
26-
<!-- Suppressions must have a justification -->
27-
<Rule Id="SA1404" Action="None" />
2825
<!-- No single-line statements involving braces -->
2926
<Rule Id="SA1501" Action="None" />
30-
<!-- Braces must not be omitted -->
31-
<Rule Id="SA1503" Action="None" />
32-
<!-- Element must be documented -->
33-
<Rule Id="SA1600" Action="None" />
34-
<!-- Parameter documentation mus be in the right order -->
35-
<Rule Id="SA1612" Action="None" />
36-
<!-- Return value must be documented -->
37-
<Rule Id="SA1615" Action="None" />
38-
<!-- Generic type parameters must be documented -->
39-
<Rule Id="SA1618" Action="None" />
40-
<!-- Don't copy/paste documentation -->
41-
<Rule Id="SA1625" Action="None" />
42-
<!-- Exception documentation must not be empty -->
43-
<Rule Id="SA1627" Action="None" />
44-
<!-- File must have header -->
45-
<Rule Id="SA1633" Action="None" />
46-
<!-- Enable XML documentation output-->
47-
<Rule Id="SA1652" Action="None" />
4827
</Rules>
49-
</RuleSet>
28+
</RuleSet>

build/stylecop.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3+
"settings": {
4+
"documentationRules": {
5+
"companyName": "Autofac Project",
6+
"copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} License. See {licenseFile} in the project root for license information.",
7+
"variables": {
8+
"licenseFile": "LICENSE",
9+
"licenseName": "MIT"
10+
},
11+
"xmlHeader": false
12+
}
13+
}
14+
}

src/Autofac.Extras.AttributeMetadata/AttributedMetadataModule.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public class AttributedMetadataModule : Module
2222
/// <param name="registration">The registration to attach functionality to.</param>
2323
protected override void AttachToComponentRegistration(IComponentRegistryBuilder componentRegistry, IComponentRegistration registration)
2424
{
25-
if (registration == null) throw new ArgumentNullException(nameof(registration));
25+
if (registration == null)
26+
{
27+
throw new ArgumentNullException(nameof(registration));
28+
}
2629

2730
foreach (var property in MetadataHelper.GetMetadata(registration.Activator.LimitType))
2831
{

src/Autofac.Extras.AttributeMetadata/Autofac.Extras.AttributeMetadata.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<None Include="..\..\build\icon.png" Pack="true" PackagePath="\" />
3737
</ItemGroup>
3838

39+
<ItemGroup>
40+
<AdditionalFiles Include="../../build/stylecop.json" Link="stylecop.json" />
41+
</ItemGroup>
42+
3943
<ItemGroup>
4044
<PackageReference Include="Autofac.Mef" Version="6.0.0" />
4145
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0">

src/Autofac.Extras.AttributeMetadata/AutofacAttributeExtensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public static IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistration
3030
WithAttributedMetadata<TLimit, TScanningActivatorData, TRegistrationStyle>(this IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle> builder)
3131
where TScanningActivatorData : ScanningActivatorData
3232
{
33-
if (builder == null) throw new ArgumentNullException(nameof(builder));
33+
if (builder == null)
34+
{
35+
throw new ArgumentNullException(nameof(builder));
36+
}
3437

3538
builder.ActivatorData.ConfigurationActions.Add(
3639
(t, rb) => rb.WithMetadata(MetadataHelper.GetMetadata(t)));
@@ -52,7 +55,10 @@ public static IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistration
5255
public static IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle>
5356
WithAttributedMetadata<TMetadata>(this IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle> builder)
5457
{
55-
if (builder == null) throw new ArgumentNullException(nameof(builder));
58+
if (builder == null)
59+
{
60+
throw new ArgumentNullException(nameof(builder));
61+
}
5662

5763
builder.ActivatorData.ConfigurationActions.Add(
5864
(t, rb) => rb.WithMetadata(MetadataHelper.GetMetadata<TMetadata>(t)));
@@ -89,7 +95,10 @@ public static IRegistrationBuilder<TLimit, TReflectionActivatorData, TRegistrati
8995
this IRegistrationBuilder<TLimit, TReflectionActivatorData, TRegistrationStyle> builder)
9096
where TReflectionActivatorData : ReflectionActivatorData
9197
{
92-
if (builder == null) throw new ArgumentNullException(nameof(builder));
98+
if (builder == null)
99+
{
100+
throw new ArgumentNullException(nameof(builder));
101+
}
93102

94103
#pragma warning disable CS0618
95104
return builder.WithParameter(

src/Autofac.Extras.AttributeMetadata/MetadataHelper.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ public static class MetadataHelper
2828
/// </exception>
2929
public static IEnumerable<KeyValuePair<string, object>> GetProperties(object target, Type instanceType)
3030
{
31-
if (target == null) throw new ArgumentNullException(nameof(target));
32-
if (instanceType == null) throw new ArgumentNullException(nameof(instanceType));
31+
if (target == null)
32+
{
33+
throw new ArgumentNullException(nameof(target));
34+
}
35+
36+
if (instanceType == null)
37+
{
38+
throw new ArgumentNullException(nameof(instanceType));
39+
}
3340

3441
if (target is IMetadataProvider asProvider)
3542
{
@@ -56,7 +63,10 @@ public static IEnumerable<KeyValuePair<string, object>> GetProperties(object tar
5663
/// </exception>
5764
public static IEnumerable<KeyValuePair<string, object>> GetMetadata(Type targetType)
5865
{
59-
if (targetType == null) throw new ArgumentNullException(nameof(targetType));
66+
if (targetType == null)
67+
{
68+
throw new ArgumentNullException(nameof(targetType));
69+
}
6070

6171
var propertyList = new List<KeyValuePair<string, object>>();
6272

@@ -82,7 +92,10 @@ public static IEnumerable<KeyValuePair<string, object>> GetMetadata(Type targetT
8292
/// </exception>
8393
public static IEnumerable<KeyValuePair<string, object>> GetMetadata<TMetadataType>(Type targetType)
8494
{
85-
if (targetType == null) throw new ArgumentNullException(nameof(targetType));
95+
if (targetType == null)
96+
{
97+
throw new ArgumentNullException(nameof(targetType));
98+
}
8699

87100
var attribute = (from p in targetType.GetCustomAttributes(typeof(TMetadataType), true) select p).FirstOrDefault();
88101

src/Autofac.Extras.AttributeMetadata/WithKeyAttribute.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ public sealed class WithKeyAttribute : ParameterFilterAttribute
110110
/// </exception>
111111
public override object ResolveParameter(ParameterInfo parameter, IComponentContext context)
112112
{
113-
if (parameter == null) throw new ArgumentNullException(nameof(parameter));
114-
if (context == null) throw new ArgumentNullException(nameof(context));
113+
if (parameter == null)
114+
{
115+
throw new ArgumentNullException(nameof(parameter));
116+
}
117+
118+
if (context == null)
119+
{
120+
throw new ArgumentNullException(nameof(context));
121+
}
115122

116123
context.TryResolveKeyed(Key, parameter.ParameterType, out var value);
117124
return value;

src/Autofac.Extras.AttributeMetadata/WithMetadataAttribute.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,15 @@ public WithMetadataAttribute(string key, object value)
144144
/// </exception>
145145
public override object ResolveParameter(ParameterInfo parameter, IComponentContext context)
146146
{
147-
if (parameter == null) throw new ArgumentNullException(nameof(parameter));
148-
if (context == null) throw new ArgumentNullException(nameof(context));
147+
if (parameter == null)
148+
{
149+
throw new ArgumentNullException(nameof(parameter));
150+
}
151+
152+
if (context == null)
153+
{
154+
throw new ArgumentNullException(nameof(context));
155+
}
149156

150157
// GetElementType currently is the effective equivalent of "Determine if the type
151158
// is in IEnumerable and if it is, get the type being enumerated." This doesn't support

test/Autofac.Extras.AttributeMetadata.Test/AttributeMetadataModuleTestFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Autofac Project. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
14
using Autofac.Extras.AttributeMetadata.Test.ScenarioTypes.NestedLifetimeScopeRegistrationScenario;
25
using Autofac.Features.Metadata;
36
using Xunit;
@@ -21,4 +24,4 @@ public void Does_not_throw_in_nested_lifetimeScope_builders()
2124
}
2225
}
2326
}
24-
}
27+
}

test/Autofac.Extras.AttributeMetadata.Test/Autofac.Extras.AttributeMetadata.Test.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
<NoWarn>$(NoWarn);CS1591</NoWarn>
5+
<NoWarn>$(NoWarn);CS1591;SA1600;</NoWarn>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<AssemblyOriginatorKeyFile>../../Autofac.snk</AssemblyOriginatorKeyFile>
88
<SignAssembly>true</SignAssembly>
@@ -17,6 +17,10 @@
1717
<None Remove="TestResults\**" />
1818
</ItemGroup>
1919

20+
<ItemGroup>
21+
<AdditionalFiles Include="../../build/stylecop.json" Link="stylecop.json" />
22+
</ItemGroup>
23+
2024
<ItemGroup>
2125
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
2226
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205">

0 commit comments

Comments
 (0)