Skip to content

Commit 902a2cd

Browse files
committed
[LFT-2087] Removed Statics.Unaudited and Mutability.Unaudited attributes.
1 parent 95c7801 commit 902a2cd

File tree

6 files changed

+16
-170
lines changed

6 files changed

+16
-170
lines changed

src/D2L.CodeStyle.Analyzers/AnnotationsContext.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#nullable disable
22

33
using System.Collections.Immutable;
4-
using System.Linq;
54
using Microsoft.CodeAnalysis;
65

76
namespace D2L.CodeStyle.Analyzers {
@@ -20,25 +19,19 @@ public static bool TryCreate( Compilation compilation, out AnnotationsContext ct
2019
}
2120

2221
private AnnotationsContext( Compilation compilation ) {
23-
Statics = (
24-
Audited: GetAttr( compilation, "D2L.CodeStyle.Annotations.Statics+Audited" ),
25-
Unaudited: GetAttr( compilation, "D2L.CodeStyle.Annotations.Statics+Unaudited" )
26-
);
22+
Statics_Audited = GetAttr( compilation, "D2L.CodeStyle.Annotations.Statics+Audited" );
23+
Mutability_Audited = GetAttr( compilation, "D2L.CodeStyle.Annotations.Mutability+AuditedAttribute" );
2724
Objects = (
2825
Immutable: GetAttr( compilation, "D2L.CodeStyle.Annotations.Objects+Immutable" ),
2926
ImmutableBaseClass: GetAttr( compilation, "D2L.CodeStyle.Annotations.Objects+ImmutableBaseClassAttribute" ),
3027
ConditionallyImmutable: GetAttr( compilation, "D2L.CodeStyle.Annotations.Objects+ConditionallyImmutable" ),
3128
OnlyIf: GetAttr( compilation, "D2L.CodeStyle.Annotations.Objects+ConditionallyImmutable+OnlyIf" )
3229
);
33-
Mutability = (
34-
Audited: GetAttr( compilation, "D2L.CodeStyle.Annotations.Mutability+AuditedAttribute" ),
35-
Unaudited: GetAttr( compilation, "D2L.CodeStyle.Annotations.Mutability+UnauditedAttribute" )
36-
);
3730
}
3831

39-
internal (Attr Audited, Attr Unaudited) Statics { get; }
32+
internal Attr Statics_Audited { get; }
33+
internal Attr Mutability_Audited { get; }
4034
internal (Attr Immutable, Attr ImmutableBaseClass, Attr ConditionallyImmutable, Attr OnlyIf) Objects { get; }
41-
internal (Attr Audited, Attr Unaudited) Mutability { get; }
4235

4336
private static Attr GetAttr( Compilation compilation, string metadataName )
4437
=> new( compilation.GetTypeByMetadataName( metadataName ) );

src/D2L.CodeStyle.Analyzers/Diagnostics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public static class Diagnostics {
117117

118118
public static readonly DiagnosticDescriptor UnnecessaryMutabilityAnnotation = new DiagnosticDescriptor(
119119
id: "D2L0030",
120-
title: "Unnecessary Mutability.(Un)Audited Attribute",
121-
messageFormat: "There is a Mutability.Audited or Mutability.Unaudited attribute on an immutable member. Remove the unnecessary attribute.",
120+
title: "Unnecessary Mutability.Audited Attribute",
121+
messageFormat: "There is a Mutability.Audited attribute on an immutable member. Remove the unnecessary attribute.",
122122
category: "Cleanliness",
123123
defaultSeverity: DiagnosticSeverity.Error,
124124
isEnabledByDefault: true

src/D2L.CodeStyle.Analyzers/Immutability/MutabilityAuditor.cs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#nullable disable
22

3-
using System.Linq;
43
using Microsoft.CodeAnalysis;
54
using static D2L.CodeStyle.Analyzers.Immutability.ImmutableDefinitionChecker;
65

@@ -15,17 +14,11 @@ out Location location
1514
) {
1615

1716
// Collect audit information
18-
var hasStaticAudited = annotationsContext.Statics.Audited.IsDefined( symbol );
19-
var hasStaticUnaudited = annotationsContext.Statics.Unaudited.IsDefined( symbol );
20-
var hasMutabilityAudited = annotationsContext.Mutability.Audited.IsDefined( symbol );
21-
var hasMutabilityUnaudited = annotationsContext.Mutability.Unaudited.IsDefined( symbol );
22-
var hasBothStaticsAttributes = hasStaticAudited && hasStaticUnaudited;
23-
var hasBothMutabilityAttributes = hasMutabilityAudited && hasMutabilityUnaudited;
24-
var hasEitherStaticsAttributes = hasStaticAudited || hasStaticUnaudited;
25-
var hasEitherMutabilityAttributes = hasMutabilityAudited || hasMutabilityUnaudited;
17+
var hasStaticAudited = annotationsContext.Statics_Audited.IsDefined( symbol );
18+
var hasMutabilityAudited = annotationsContext.Mutability_Audited.IsDefined( symbol );
2619

2720
// If there are no audits, don't do anything
28-
if( !hasEitherStaticsAttributes && !hasEitherMutabilityAttributes ) {
21+
if( !hasStaticAudited && !hasMutabilityAudited ) {
2922
location = null;
3023
return false;
3124
}
@@ -36,33 +29,11 @@ out Location location
3629
.GetLastToken()
3730
.GetLocation();
3831

39-
// Check if both static audits are applied
40-
if( hasBothStaticsAttributes ) {
41-
var diagnostic = Diagnostic.Create(
42-
Diagnostics.ConflictingImmutability,
43-
syntaxLocation,
44-
"Statics.Audited",
45-
"Statics.Unaudited",
46-
symbol.Kind.ToString().ToLower() );
47-
diagnosticSink( diagnostic );
48-
}
49-
50-
// Check if both mutability audits are applied
51-
if( hasBothMutabilityAttributes ) {
52-
var diagnostic = Diagnostic.Create(
53-
Diagnostics.ConflictingImmutability,
54-
syntaxLocation,
55-
"Mutability.Audited",
56-
"Mutability.Unaudited",
57-
symbol.Kind.ToString().ToLower() );
58-
diagnosticSink( diagnostic );
59-
}
60-
6132
AttributeData attr = null;
6233

6334
if( symbol.IsStatic ) {
6435
// Check if a static member is using mutability audits
65-
if( hasEitherMutabilityAttributes ) {
36+
if( hasMutabilityAudited ) {
6637
var diagnostic = Diagnostic.Create(
6738
Diagnostics.InvalidAuditType,
6839
syntaxLocation,
@@ -72,11 +43,10 @@ out Location location
7243
diagnosticSink( diagnostic );
7344
}
7445

75-
attr = annotationsContext.Statics.Audited.GetAll( symbol ).FirstOrDefault()
76-
?? annotationsContext.Statics.Unaudited.GetAll( symbol ).FirstOrDefault();
46+
attr = annotationsContext.Statics_Audited.GetAll( symbol ).FirstOrDefault();
7747
} else {
7848
// Check if a non-static member is using static audits
79-
if( hasEitherStaticsAttributes ) {
49+
if( hasStaticAudited ) {
8050
var diagnostic = Diagnostic.Create(
8151
Diagnostics.InvalidAuditType,
8252
syntaxLocation,
@@ -86,8 +56,7 @@ out Location location
8656
diagnosticSink( diagnostic );
8757
}
8858

89-
attr = annotationsContext.Mutability.Audited.GetAll( symbol ).FirstOrDefault()
90-
?? annotationsContext.Mutability.Unaudited.GetAll( symbol ).FirstOrDefault();
59+
attr = annotationsContext.Mutability_Audited.GetAll( symbol ).FirstOrDefault();
9160
}
9261

9362
if( attr != null ) {

src/D2L.CodeStyle.Annotations/Mutability/UnauditedAttribute.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/D2L.CodeStyle.Annotations/Statics/Unaudited.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)