diff --git a/README.md b/README.md index 8d0b618a8..3ae1860cb 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ If you are already using other analyzers, you can check [which rules are duplica |[MA0013](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0013.md)|Design|Types should not extend System.ApplicationException|⚠️|✔️|❌| |[MA0014](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0014.md)|Design|Do not raise System.ApplicationException type|⚠️|✔️|❌| |[MA0015](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0015.md)|Usage|Specify the parameter name in ArgumentException|⚠️|✔️|❌| -|[MA0016](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0016.md)|Design|Prefer returning collection abstraction instead of implementation|⚠️|✔️|❌| +|[MA0016](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0016.md)|Design|Prefer using collection abstraction instead of implementation|⚠️|✔️|❌| |[MA0017](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0017.md)|Design|Abstract types should not have public or internal constructors|⚠️|✔️|✔️| |[MA0018](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0018.md)|Design|Do not declare static members on generic types|⚠️|✔️|❌| |[MA0019](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0019.md)|Usage|Use EventArgs.Empty|⚠️|✔️|✔️| @@ -104,7 +104,7 @@ If you are already using other analyzers, you can check [which rules are duplica |[MA0086](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0086.md)|Design|Do not throw from a finalizer|⚠️|✔️|❌| |[MA0087](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0087.md)|Design|Parameters with \[DefaultParameterValue\] attributes should also be marked \[Optional\]|⚠️|✔️|❌| |[MA0088](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0088.md)|Design|Use \[DefaultParameterValue\] instead of \[DefaultValue\]|⚠️|✔️|❌| -|[MA0089](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md)|Performance|Optimize string method usage|ℹ️|✔️|❌| +|[MA0089](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md)|Performance|Optimize string method usage|ℹ️|✔️|✔️| |[MA0090](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0090.md)|Design|Remove empty else/finally block|ℹ️|✔️|❌| |[MA0091](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0091.md)|Usage|Sender should be 'this' for instance events|⚠️|✔️|✔️| |[MA0092](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0092.md)|Usage|Sender should be 'null' for static events|⚠️|✔️|❌| diff --git a/docs/README.md b/docs/README.md index 981be4653..d9a26a661 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,7 +16,7 @@ |[MA0013](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0013.md)|Design|Types should not extend System.ApplicationException|⚠️|✔️|❌| |[MA0014](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0014.md)|Design|Do not raise System.ApplicationException type|⚠️|✔️|❌| |[MA0015](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0015.md)|Usage|Specify the parameter name in ArgumentException|⚠️|✔️|❌| -|[MA0016](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0016.md)|Design|Prefer returning collection abstraction instead of implementation|⚠️|✔️|❌| +|[MA0016](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0016.md)|Design|Prefer using collection abstraction instead of implementation|⚠️|✔️|❌| |[MA0017](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0017.md)|Design|Abstract types should not have public or internal constructors|⚠️|✔️|✔️| |[MA0018](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0018.md)|Design|Do not declare static members on generic types|⚠️|✔️|❌| |[MA0019](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0019.md)|Usage|Use EventArgs.Empty|⚠️|✔️|✔️| @@ -88,7 +88,7 @@ |[MA0086](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0086.md)|Design|Do not throw from a finalizer|⚠️|✔️|❌| |[MA0087](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0087.md)|Design|Parameters with \[DefaultParameterValue\] attributes should also be marked \[Optional\]|⚠️|✔️|❌| |[MA0088](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0088.md)|Design|Use \[DefaultParameterValue\] instead of \[DefaultValue\]|⚠️|✔️|❌| -|[MA0089](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md)|Performance|Optimize string method usage|ℹ️|✔️|❌| +|[MA0089](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md)|Performance|Optimize string method usage|ℹ️|✔️|✔️| |[MA0090](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0090.md)|Design|Remove empty else/finally block|ℹ️|✔️|❌| |[MA0091](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0091.md)|Usage|Sender should be 'this' for instance events|⚠️|✔️|✔️| |[MA0092](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0092.md)|Usage|Sender should be 'null' for static events|⚠️|✔️|❌| @@ -189,7 +189,7 @@ dotnet_diagnostic.MA0014.severity = warning # MA0015: Specify the parameter name in ArgumentException dotnet_diagnostic.MA0015.severity = warning -# MA0016: Prefer returning collection abstraction instead of implementation +# MA0016: Prefer using collection abstraction instead of implementation dotnet_diagnostic.MA0016.severity = warning # MA0017: Abstract types should not have public or internal constructors @@ -592,7 +592,7 @@ dotnet_diagnostic.MA0014.severity = none # MA0015: Specify the parameter name in ArgumentException dotnet_diagnostic.MA0015.severity = none -# MA0016: Prefer returning collection abstraction instead of implementation +# MA0016: Prefer using collection abstraction instead of implementation dotnet_diagnostic.MA0016.severity = none # MA0017: Abstract types should not have public or internal constructors diff --git a/docs/Rules/MA0016.md b/docs/Rules/MA0016.md index d9760e17a..06750434a 100644 --- a/docs/Rules/MA0016.md +++ b/docs/Rules/MA0016.md @@ -1,11 +1,12 @@ -# MA0016 - Prefer returning collection abstraction instead of implementation +# MA0016 - Prefer using collection abstraction instead of implementation Methods and properties visible to other assemblies (`public` or `protected`) should use collection interfaces instead of collection implementations. ````c# -public List Prop { get; set; } // report diagnostic - +public List Prop { get; set; } // non-compliant public IList Prop { get; set; } // ok + +public void Method(Dictionary arg) {} // non-compliant ```` The analyzer detects `List`, `HashSet`, `Dictionary`, and `System.Collections.ObjectModel.Collection`. The rules is disabled if the property is decorated with an XML serialization attribute. diff --git a/src/Meziantou.Analyzer/Rules/PreferReturningCollectionAbstractionInsteadOfImplementationAnalyzer.cs b/src/Meziantou.Analyzer/Rules/PreferReturningCollectionAbstractionInsteadOfImplementationAnalyzer.cs index bc3c59484..5819e2a0b 100644 --- a/src/Meziantou.Analyzer/Rules/PreferReturningCollectionAbstractionInsteadOfImplementationAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/PreferReturningCollectionAbstractionInsteadOfImplementationAnalyzer.cs @@ -12,8 +12,8 @@ public sealed class PreferReturningCollectionAbstractionInsteadOfImplementationA { private static readonly DiagnosticDescriptor s_rule = new( RuleIdentifiers.PreferReturningCollectionAbstractionInsteadOfImplementation, - title: "Prefer returning collection abstraction instead of implementation", - messageFormat: "Prefer returning collection abstraction instead of implementation", + title: "Prefer using collection abstraction instead of implementation", + messageFormat: "Prefer using collection abstraction instead of implementation", RuleCategories.Design, DiagnosticSeverity.Warning, isEnabledByDefault: true,