Skip to content

Commit 21d4d2f

Browse files
authored
Merge pull request #1468 from autofac/feature/enable-analyzers
Enable analyzers; clean up missing docs, code order, etc.
2 parents ab7ca4d + 10cecca commit 21d4d2f

File tree

118 files changed

+1829
-1656
lines changed

Some content is hidden

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

118 files changed

+1829
-1656
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"netcoreapp",
1515
"netstandard",
1616
"notnull",
17+
"parameterless",
1718
"paramref",
1819
"startable",
1920
"subclassing",

build/Source.ruleset

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
55
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
66
<Rule Id="CA1032" Action="None" />
7+
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
8+
<Rule Id="CA1501" Action="Warning" />
9+
<!-- Avoid excessive complexity (must be explicitly enabled). -->
10+
<Rule Id="CA1502" Action="Warning" />
11+
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
12+
<Rule Id="CA1505" Action="Warning" />
13+
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
14+
<Rule Id="CA1506" Action="Warning" />
715
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
816
<Rule Id="CA1510" Action="None" />
917
<!-- Use ArgumentOutOfRangeException.ThrowIfNegative - this isn't available until we stop targeting anything below net8.0. -->
@@ -26,35 +34,7 @@
2634
<Rule Id="SA1121" Action="None" />
2735
<!-- Use String.Empty instead of "". -->
2836
<Rule Id="SA1122" Action="None" />
29-
<!-- Using statements must be inside a namespace. -->
30-
<Rule Id="SA1200" Action="None" />
31-
<!-- Enforce order of class members by member type. -->
32-
<Rule Id="SA1201" Action="None" />
33-
<!-- Enforce order of class members by member visibility. -->
34-
<Rule Id="SA1202" Action="None" />
35-
<!-- Enforce order of constantand static members. -->
36-
<Rule Id="SA1203" Action="None" />
37-
<!-- Enforce order of static vs. non-static members. -->
38-
<Rule Id="SA1204" Action="None" />
39-
<!-- Modifiers are not ordered - .editorconfig handles this. -->
40-
<Rule Id="SA1206" Action="None" />
41-
<!-- Enforce order of readonly vs. non-readonly members. -->
42-
<Rule Id="SA1214" Action="None" />
4337
<!-- Fields can't start with underscore. -->
4438
<Rule Id="SA1309" Action="None" />
45-
<!-- Suppressions must have a justification. -->
46-
<Rule Id="SA1404" Action="None" />
47-
<!-- Parameter documentation must be in the right order. -->
48-
<Rule Id="SA1612" Action="None" />
49-
<!-- Return value must be documented. -->
50-
<Rule Id="SA1615" Action="None" />
51-
<!-- Generic type parameters must be documented. -->
52-
<Rule Id="SA1618" Action="None" />
53-
<!-- Don't copy/paste documentation. -->
54-
<Rule Id="SA1625" Action="None" />
55-
<!-- Exception documentation must not be empty. -->
56-
<Rule Id="SA1627" Action="None" />
57-
<!-- Enable XML documentation output. -->
58-
<Rule Id="SA1652" Action="None" />
5939
</Rules>
6040
</RuleSet>

build/Test.ruleset

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
33
<IncludeAll Action="Warning" />
44
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
5+
<!-- Avoid excessive parameters on generic types (must be explicitly enabled). -->
6+
<Rule Id="CA1005" Action="Warning" />
57
<!-- Don't catch general exceptions - test scenarios sometimes require general exception handling. -->
68
<Rule Id="CA1031" Action="None" />
79
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
@@ -10,6 +12,14 @@
1012
<Rule Id="CA1040" Action="None" />
1113
<!-- Do not pass literals as localized parameters - tests don't need to localize. -->
1214
<Rule Id="CA1303" Action="None" />
15+
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
16+
<Rule Id="CA1501" Action="Warning" />
17+
<!-- Avoid excessive complexity (must be explicitly enabled). -->
18+
<Rule Id="CA1502" Action="Warning" />
19+
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
20+
<Rule Id="CA1505" Action="Warning" />
21+
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
22+
<Rule Id="CA1506" Action="Warning" />
1323
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
1424
<Rule Id="CA1510" Action="None" />
1525
<!-- Remove the underscores from member name - unit test scenarios may use underscores. -->
@@ -44,28 +54,22 @@
4454
<Rule Id="SA1121" Action="None" />
4555
<!-- Use String.Empty instead of "". -->
4656
<Rule Id="SA1122" Action="None" />
47-
<!-- Using statements must be inside a namespace. -->
48-
<Rule Id="SA1200" Action="None" />
49-
<!-- Enforce order of class members by member type. -->
57+
<!-- Enforce order of class members by member type - sometimes putting test classes/data by the test helps. -->
5058
<Rule Id="SA1201" Action="None" />
51-
<!-- Enforce order of class members by member visibility. -->
59+
<!-- Enforce order of class members by member visibility - sometimes putting test classes/data by the test helps. -->
5260
<Rule Id="SA1202" Action="None" />
53-
<!-- Enforce order of constantand static members. -->
54-
<Rule Id="SA1203" Action="None" />
55-
<!-- Enforce order of static vs. non-static members. -->
61+
<!-- Enforce order of static vs. non-static members - sometimes putting test classes/data by the test helps. -->
5662
<Rule Id="SA1204" Action="None" />
57-
<!-- Modifiers are not ordered - .editorconfig handles this. -->
58-
<Rule Id="SA1206" Action="None" />
59-
<!-- Enforce order of readonly vs. non-readonly members. -->
60-
<Rule Id="SA1214" Action="None" />
6163
<!-- Fields can't start with underscore. -->
6264
<Rule Id="SA1309" Action="None" />
63-
<!-- Suppressions must have a justification. -->
64-
<Rule Id="SA1404" Action="None" />
6565
<!-- Elements should be documented. -->
6666
<Rule Id="SA1600" Action="None" />
67-
<!-- Enuemration items should be documented. -->
67+
<!-- Partial items should be documented. -->
68+
<Rule Id="SA1601" Action="None" />
69+
<!-- Enumeration items should be documented. -->
6870
<Rule Id="SA1602" Action="None" />
71+
<!-- Parameter should be documented. -->
72+
<Rule Id="SA1611" Action="None" />
6973
<!-- Parameter documentation must be in the right order. -->
7074
<Rule Id="SA1612" Action="None" />
7175
<!-- Return value must be documented. -->
@@ -74,10 +78,6 @@
7478
<Rule Id="SA1618" Action="None" />
7579
<!-- Don't copy/paste documentation. -->
7680
<Rule Id="SA1625" Action="None" />
77-
<!-- Exception documentation must not be empty. -->
78-
<Rule Id="SA1627" Action="None" />
79-
<!-- Enable XML documentation output. -->
80-
<Rule Id="SA1652" Action="None" />
8181
<!-- Private member is unused - tests for reflection require members that may not get used. -->
8282
<Rule Id="IDE0051" Action="None" />
8383
<!-- Private member assigned value never read - tests for reflection require values that may not get used. -->

src/Autofac/Builder/BuildCallbackManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace Autofac.Builder;
1010
/// </summary>
1111
internal static class BuildCallbackManager
1212
{
13-
private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService));
14-
1513
private const string BuildCallbacksExecutedKey = nameof(BuildCallbacksExecutedKey);
1614

15+
private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService));
16+
1717
/// <summary>
1818
/// Executes the newly-registered build callbacks for a given scope/container..
1919
/// </summary>

src/Autofac/Builder/IHideObjectMembers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IHideObjectMembers
1818
/// Standard System.Object member.
1919
/// </summary>
2020
/// <returns>Standard result.</returns>
21-
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
21+
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Override for standard method to add attributes.")]
2222
[EditorBrowsable(EditorBrowsableState.Never)]
2323
Type GetType();
2424

src/Autofac/Builder/IRegistrationBuilder.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ namespace Autofac.Builder;
1010
/// <summary>
1111
/// Data structure used to construct registrations.
1212
/// </summary>
13-
/// <typeparam name="TLimit">The most specific type to which instances of the registration
14-
/// can be cast.</typeparam>
13+
/// <typeparam name="TLimit">The most specific type to which instances of the registration can be cast.</typeparam>
1514
/// <typeparam name="TActivatorData">Activator builder type.</typeparam>
1615
/// <typeparam name="TRegistrationStyle">Registration style type.</typeparam>
1716
public interface IRegistrationBuilder<out TLimit, out TActivatorData, out TRegistrationStyle>
@@ -157,8 +156,8 @@ IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService>()
157156
/// Configure the services that the component will provide. The generic parameter(s) to As()
158157
/// will be exposed as TypedService instances.
159158
/// </summary>
160-
/// <typeparam name="TService1">Service type.</typeparam>
161-
/// <typeparam name="TService2">Service type.</typeparam>
159+
/// <typeparam name="TService1">First service type.</typeparam>
160+
/// <typeparam name="TService2">Second service type.</typeparam>
162161
/// <returns>A registration builder allowing further configuration of the component.</returns>
163162
IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2>()
164163
where TService1 : notnull
@@ -168,9 +167,9 @@ IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, T
168167
/// Configure the services that the component will provide. The generic parameter(s) to As()
169168
/// will be exposed as TypedService instances.
170169
/// </summary>
171-
/// <typeparam name="TService1">Service type.</typeparam>
172-
/// <typeparam name="TService2">Service type.</typeparam>
173-
/// <typeparam name="TService3">Service type.</typeparam>
170+
/// <typeparam name="TService1">First service type.</typeparam>
171+
/// <typeparam name="TService2">Second service type.</typeparam>
172+
/// <typeparam name="TService3">Third service type.</typeparam>
174173
/// <returns>A registration builder allowing further configuration of the component.</returns>
175174
IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2, TService3>()
176175
where TService1 : notnull

src/Autofac/Builder/MetadataConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class MetadataConfiguration<TMetadata>
2929
/// <typeparam name="TProperty">The type of the property.</typeparam>
3030
/// <param name="propertyAccessor">An expression that accesses the property to set.</param>
3131
/// <param name="value">The property value to set.</param>
32+
/// <returns>
33+
/// The current <see cref="MetadataConfiguration{TMetadata}"/> for continued configuration.
34+
/// </returns>
3235
public MetadataConfiguration<TMetadata> For<TProperty>(Expression<Func<TMetadata, TProperty>> propertyAccessor, TProperty value)
3336
{
3437
if (propertyAccessor == null)

src/Autofac/Builder/ReflectionActivatorData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace Autofac.Builder;
1111
/// </summary>
1212
public class ReflectionActivatorData
1313
{
14+
private static readonly IConstructorFinder DefaultConstructorFinder = new DefaultConstructorFinder();
15+
private static readonly IConstructorSelector DefaultConstructorSelector = new MostParametersConstructorSelector();
16+
1417
private Type _implementer = default!;
1518
private IConstructorFinder _constructorFinder;
1619
private IConstructorSelector _constructorSelector;
1720

18-
private static readonly IConstructorFinder DefaultConstructorFinder = new DefaultConstructorFinder();
19-
private static readonly IConstructorSelector DefaultConstructorSelector = new MostParametersConstructorSelector();
20-
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="ReflectionActivatorData"/> class.
2323
/// </summary>

src/Autofac/Builder/RegistrationBuilder.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationSty
4343
/// <summary>
4444
/// Creates a registration builder for the provided delegate.
4545
/// </summary>
46-
/// <param name="delegate">Delegate to register.</param>
4746
/// <param name="limitType">Most specific type return value of delegate can be cast to.</param>
47+
/// <param name="delegate">Delegate to register.</param>
4848
/// <returns>A registration builder.</returns>
4949
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> ForDelegate(Type limitType, Func<IComponentContext, IEnumerable<Parameter>, object> @delegate)
5050
{
@@ -101,6 +101,9 @@ public static IRegistrationBuilder<object, ConcreteReflectionActivatorData, Sing
101101
/// Create an <see cref='IComponentRegistration'/> from a <see cref='RegistrationBuilder'/>.
102102
/// There is no need to call this method when registering components through a <see cref="ContainerBuilder"/>.
103103
/// </summary>
104+
/// <typeparam name="TLimit">The most specific type to which instances of the registration can be cast.</typeparam>
105+
/// <typeparam name="TActivatorData">Activator builder type.</typeparam>
106+
/// <typeparam name="TSingleRegistrationStyle">Registration style for individual components.</typeparam>
104107
/// <remarks>
105108
/// When called on the result of one of the <see cref='ContainerBuilder'/> methods,
106109
/// the returned registration will be different from the one the builder itself registers
@@ -253,7 +256,9 @@ public static IComponentRegistration CreateRegistration(
253256
/// Register a component in the component registry. This helper method is necessary
254257
/// in order to execute OnRegistered hooks and respect PreserveDefaults.
255258
/// </summary>
256-
/// <remarks>Hoping to refactor this out.</remarks>
259+
/// <typeparam name="TLimit">The most specific type to which instances of the registration can be cast.</typeparam>
260+
/// <typeparam name="TActivatorData">Activator builder type.</typeparam>
261+
/// <typeparam name="TSingleRegistrationStyle">Registration style for individual components.</typeparam>
257262
/// <param name="cr">Component registry to make registration in.</param>
258263
/// <param name="builder">Registration builder with data for new registration.</param>
259264
public static void RegisterSingleComponent<TLimit, TActivatorData, TSingleRegistrationStyle>(

src/Autofac/Builder/RegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TServ
238238
/// Configure the services that the component will provide. The generic parameter(s) to As()
239239
/// will be exposed as TypedService instances.
240240
/// </summary>
241-
/// <typeparam name="TService1">Service type.</typeparam>
242-
/// <typeparam name="TService2">Service type.</typeparam>
241+
/// <typeparam name="TService1">First service type.</typeparam>
242+
/// <typeparam name="TService2">Second service type.</typeparam>
243243
/// <returns>A registration builder allowing further configuration of the component.</returns>
244244
public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2>()
245245
where TService1 : notnull
@@ -252,9 +252,9 @@ public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TServ
252252
/// Configure the services that the component will provide. The generic parameter(s) to As()
253253
/// will be exposed as TypedService instances.
254254
/// </summary>
255-
/// <typeparam name="TService1">Service type.</typeparam>
256-
/// <typeparam name="TService2">Service type.</typeparam>
257-
/// <typeparam name="TService3">Service type.</typeparam>
255+
/// <typeparam name="TService1">First service type.</typeparam>
256+
/// <typeparam name="TService2">Second service type.</typeparam>
257+
/// <typeparam name="TService3">Third service type.</typeparam>
258258
/// <returns>A registration builder allowing further configuration of the component.</returns>
259259
public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2, TService3>()
260260
where TService1 : notnull

0 commit comments

Comments
 (0)