|
1 | | -<?xml version="1.0" encoding="utf-8"?> |
2 | | -<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0"> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac test assemblies." ToolsVersion="16.0"> |
3 | 3 | <IncludeAll Action="Warning" /> |
4 | | - <Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage"> |
5 | | - <!-- Avoid excessive parameters on generic types (must be explicitly enabled). --> |
6 | | - <Rule Id="CA1005" Action="Warning" /> |
7 | | - <!-- Don't catch general exceptions - test scenarios sometimes require general exception handling. --> |
| 4 | + <Rules AnalyzerId="Microsoft.CodeAnalysis.Analyzers" RuleNamespace="Microsoft.CodeAnalysis.Analyzers"> |
| 5 | + <!-- Don't catch general exceptions - test scenarios sometimes require it. --> |
8 | 6 | <Rule Id="CA1031" Action="None" /> |
9 | | - <!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. --> |
10 | | - <Rule Id="CA1032" Action="None" /> |
11 | | - <!-- Avoid empty interfaces - in unit tests for service resolution, this happens a lot. --> |
| 7 | + <!-- Avoid empty interfaces - happens a lot in unit tests for service resolution. --> |
12 | 8 | <Rule Id="CA1040" Action="None" /> |
13 | | - <!-- Do not pass literals as localized parameters - tests don't need to localize. --> |
| 9 | + <!-- Do not pass literals as localized parameters - tests don't need to localize. --> |
14 | 10 | <Rule Id="CA1303" Action="None" /> |
15 | 11 | <!-- Avoid excessive inheritance (must be explicitly enabled). --> |
16 | 12 | <Rule Id="CA1501" Action="Warning" /> |
|
20 | 16 | <Rule Id="CA1505" Action="Warning" /> |
21 | 17 | <!-- Avoid excessive class coupling (must be explicitly enabled). --> |
22 | 18 | <Rule Id="CA1506" Action="Warning" /> |
23 | | - <!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. --> |
24 | | - <Rule Id="CA1510" Action="None" /> |
25 | | - <!-- Make API types internal - causes problems with tests and test assemblies. --> |
| 19 | + <!-- Make API types internal - causes problems with tests. --> |
26 | 20 | <Rule Id="CA1515" Action="None" /> |
27 | | - <!-- Remove the underscores from member name - unit test scenarios may use underscores. --> |
| 21 | + <!-- Remove underscores from member name - test naming conventions use underscore. --> |
28 | 22 | <Rule Id="CA1707" Action="None" /> |
29 | | - <!-- 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. --> |
30 | | - <Rule Id="CA1716" Action="None" /> |
31 | | - <!-- Internal class that appears to never be instantiated - lots of false positives here because they're test stubs created by Autofac registrations. --> |
| 23 | + <!-- Internal class that appears to never be instantiated - false positives from DI. --> |
32 | 24 | <Rule Id="CA1812" Action="None" /> |
33 | | - <!-- Change Dispose() to call GC.SuppressFinalize - in tests we don't really care and it can impact readability. --> |
| 25 | + <!-- Change Dispose() to call GC.SuppressFinalize - unimportant in tests. --> |
34 | 26 | <Rule Id="CA1816" Action="None" /> |
35 | | - <!-- Mark members static - test methods may not access member data but also can't be static. --> |
| 27 | + <!-- Mark members static - test methods may not access member data. --> |
36 | 28 | <Rule Id="CA1822" Action="None" /> |
37 | | - <!-- Seal internal types for performance - in tests we don't really care and it gets painful to enforce. --> |
| 29 | + <!-- Use the LoggerMessage delegates - noise in tests, performance irrelevant. --> |
| 30 | + <Rule Id="CA1848" Action="None" /> |
| 31 | + <!-- Seal internal types - unimportant in tests. --> |
38 | 32 | <Rule Id="CA1852" Action="None" /> |
39 | | - <!-- Prefer static readonly fields over constant array arguments - constant array arguments happen a lot in unit tests for assertions and test setup. --> |
| 33 | + <!-- Prefer static readonly fields over constant arrays - happens in test setup. --> |
40 | 34 | <Rule Id="CA1861" Action="None" /> |
41 | | - <!-- Cache a CompositeFormat object for use in String.Format - this makes unit tests harder to read, and performance isn't an issue. --> |
| 35 | + <!-- Cache a CompositeFormat - makes tests harder to read. --> |
42 | 36 | <Rule Id="CA1863" Action="None" /> |
43 | | - <!-- Call ConfigureAwait on tasks - you shouldn't do this in unit test libraries; XUnit has an opposite analyzer. --> |
| 37 | + <!-- Call ConfigureAwait - shouldn't in test libraries; XUnit has opposing analyzer. --> |
44 | 38 | <Rule Id="CA2007" Action="None" /> |
45 | | - <!-- Implement serialization constructors - false positive when building .NET Core. --> |
| 39 | + <!-- Implement serialization constructors - false positive in .NET Core. --> |
46 | 40 | <Rule Id="CA2229" Action="None" /> |
47 | 41 | <!-- Use Uri instead of string parameters - strings are easier for testing. --> |
48 | 42 | <Rule Id="CA2234" Action="None" /> |
49 | | - <!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. --> |
| 43 | + <!-- Mark ISerializable types with SerializableAttribute - false positive in .NET Core. --> |
50 | 44 | <Rule Id="CA2237" Action="None" /> |
51 | | - <!-- Prefer generic overloads to using Type parameters - we do a lot of reflection work in Autofac that needs to be tested. --> |
| 45 | + <!-- Prefer generic overloads - reflection work in Autofac needs to be tested. --> |
52 | 46 | <Rule Id="CA2263" Action="None" /> |
53 | 47 | </Rules> |
| 48 | + <Rules AnalyzerId="SonarAnalyzer.CSharp" RuleNamespace="SonarAnalyzer.CSharp"> |
| 49 | + <!-- Don't use hardcoded paths or URIs - needed in several test cases. --> |
| 50 | + <Rule Id="S1075" Action="None" /> |
| 51 | + <!-- Utility class should not be instantiated - test fixture classes with nested tests can't be static. --> |
| 52 | + <Rule Id="S1118" Action="None" /> |
| 53 | + <!-- Don't call GC.Collect - required for weak reference and disposal tests. --> |
| 54 | + <Rule Id="S1215" Action="None" /> |
| 55 | + <!-- Remove unused private members - reflection tests need non-public members. --> |
| 56 | + <Rule Id="S1144" Action="None" /> |
| 57 | + <!-- Empty method bodies - test stubs often have no-op implementations. --> |
| 58 | + <Rule Id="S1186" Action="None" /> |
| 59 | + <!-- Remove unused method parameters - reflection tests declare parameters not used in the body. --> |
| 60 | + <Rule Id="S1172" Action="None" /> |
| 61 | + <!-- Remove empty class - test stubs for DI resolution don't need implementation. --> |
| 62 | + <Rule Id="S2094" Action="None" /> |
| 63 | + <!-- Make member static - test fixture members may not access instance data. --> |
| 64 | + <Rule Id="S2325" Action="None" /> |
| 65 | + <!-- Remove unused type parameters - used in reflection testing. --> |
| 66 | + <Rule Id="S2326" Action="None" /> |
| 67 | + <!-- Write-only properties - reflection tests verify property setter behavior. --> |
| 68 | + <Rule Id="S2376" Action="None" /> |
| 69 | + <!-- Classes with only private constructors - reflection tests verify inaccessible constructors. --> |
| 70 | + <Rule Id="S3453" Action="None" /> |
| 71 | + <!-- Remove unassigned auto-property - reflection tests verify non-public property behavior. --> |
| 72 | + <Rule Id="S3459" Action="None" /> |
| 73 | + <!-- Complete the TODO - acceptable in tests for backlog items. --> |
| 74 | + <Rule Id="S1135" Action="None" /> |
| 75 | + <!-- Make instance property static - false positives in data/document types. --> |
| 76 | + <Rule Id="S2335" Action="None" /> |
| 77 | + <!-- Cognitive complexity (must be explicitly enabled). --> |
| 78 | + <Rule Id="S3776" Action="Warning" /> |
| 79 | + <!-- Split method for params check + iterator - overly prescriptive for our patterns. --> |
| 80 | + <Rule Id="S4456" Action="None" /> |
| 81 | + <!-- Don't use Thread.Sleep - required for concurrency and timing tests. --> |
| 82 | + <Rule Id="S2925" Action="None" /> |
| 83 | + <!-- NSubstitute mock verification is complete without property access. --> |
| 84 | + <Rule Id="S2970" Action="None" /> |
| 85 | + <!-- Fields only assigned in constructor - needed to prevent optimization in reflection tests. --> |
| 86 | + <Rule Id="S4487" Action="None" /> |
| 87 | + <!-- Set route attributes at top of controller - false positive. --> |
| 88 | + <Rule Id="S6934" Action="None" /> |
| 89 | + <!-- Use async dispose - sync dispose tests are intentional. --> |
| 90 | + <Rule Id="S6966" Action="None" /> |
| 91 | + </Rules> |
54 | 92 | <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers"> |
55 | 93 | <!-- Prefix local calls with this. --> |
56 | 94 | <Rule Id="SA1101" Action="None" /> |
57 | 95 | <!-- Use built-in type alias. --> |
58 | 96 | <Rule Id="SA1121" Action="None" /> |
59 | 97 | <!-- Use String.Empty instead of "". --> |
60 | 98 | <Rule Id="SA1122" Action="None" /> |
61 | | - <!-- Enforce order of class members by member type - sometimes putting test classes/data by the test helps. --> |
| 99 | + <!-- Enforce order of class members by member type. --> |
62 | 100 | <Rule Id="SA1201" Action="None" /> |
63 | | - <!-- Enforce order of class members by member visibility - sometimes putting test classes/data by the test helps. --> |
| 101 | + <!-- Enforce order of class members by visibility. --> |
64 | 102 | <Rule Id="SA1202" Action="None" /> |
65 | | - <!-- Enforce order of static vs. non-static members - sometimes putting test classes/data by the test helps. --> |
| 103 | + <!-- Enforce order of static vs. non-static members. --> |
66 | 104 | <Rule Id="SA1204" Action="None" /> |
67 | 105 | <!-- Fields can't start with underscore. --> |
68 | 106 | <Rule Id="SA1309" Action="None" /> |
|
82 | 120 | <Rule Id="SA1618" Action="None" /> |
83 | 121 | <!-- Don't copy/paste documentation. --> |
84 | 122 | <Rule Id="SA1625" Action="None" /> |
| 123 | + </Rules> |
| 124 | + <Rules AnalyzerId="xUnit" RuleNamespace="xUnit"> |
| 125 | + <!-- Use Assert.Single when there's only one collection entry. --> |
| 126 | + <Rule Id="xUnit2023" Action="Warning" /> |
| 127 | + </Rules> |
| 128 | + <!-- IDE rules for test assemblies. --> |
| 129 | + <Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp" RuleNamespace="Microsoft.CodeAnalysis.CSharp"> |
85 | 130 | <!-- Private member is unused - tests for reflection require members that may not get used. --> |
86 | 131 | <Rule Id="IDE0051" Action="None" /> |
87 | 132 | <!-- Private member assigned value never read - tests for reflection require values that may not get used. --> |
|
0 commit comments