diff --git a/build/targets/codeanalysis/CodeAnalysis.props b/build/targets/codeanalysis/CodeAnalysis.props
index fdd666310..f25d9b626 100644
--- a/build/targets/codeanalysis/CodeAnalysis.props
+++ b/build/targets/codeanalysis/CodeAnalysis.props
@@ -22,6 +22,10 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/build/targets/codeanalysis/Packages.props b/build/targets/codeanalysis/Packages.props
index 1df4f30cf..8637327de 100644
--- a/build/targets/codeanalysis/Packages.props
+++ b/build/targets/codeanalysis/Packages.props
@@ -2,6 +2,7 @@
+
diff --git a/src/Analyzers/SquiggleCop.Baseline.yaml b/src/Analyzers/SquiggleCop.Baseline.yaml
index 5680b16b3..4b4a8be6e 100644
--- a/src/Analyzers/SquiggleCop.Baseline.yaml
+++ b/src/Analyzers/SquiggleCop.Baseline.yaml
@@ -848,6 +848,9 @@
- {Id: RemoveUnnecessaryImportsFixable, Title: '', Category: Style, DefaultSeverity: Note, IsEnabledByDefault: true, EffectiveSeverities: [Note], IsEverSuppressed: true}
- {Id: ROS0002, Title: Analyzer option is obsolete, Category: '', DefaultSeverity: Warning, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
- {Id: ROS0003, Title: Analyzer requires config option to be specified, Category: '', DefaultSeverity: Note, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
+- {Id: RS0030, Title: Do not use banned APIs, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: true}
+- {Id: RS0031, Title: The list of banned symbols contains a duplicate, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0035, Title: External access to internal symbols outside the restricted namespace(s) is prohibited, Category: ApiDesign, DefaultSeverity: Error, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1001, Title: Missing diagnostic analyzer attribute, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1002, Title: Missing kind argument when registering an analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1003, Title: Unsupported SymbolKind argument when registering a symbol analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
diff --git a/src/BannedSymbols.txt b/src/BannedSymbols.txt
new file mode 100644
index 000000000..9f786f1f4
--- /dev/null
+++ b/src/BannedSymbols.txt
@@ -0,0 +1,8 @@
+// Prefer our DiagnosticExtensions.CreateDiagnostic for readability and consistency
+M:Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor,Microsoft.CodeAnalysis.Location,System.Object[]);Use DiagnosticExtensions.CreateDiagnostic
+M:Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor,Microsoft.CodeAnalysis.Location,System.Collections.Immutable.ImmutableDictionary{System.String,System.String},System.Object[]);Use DiagnosticExtensions.CreateDiagnostic
+M:Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor,Microsoft.CodeAnalysis.Location,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Location},System.Object[]);Use DiagnosticExtensions.CreateDiagnostic
+M:Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor,Microsoft.CodeAnalysis.Location,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Location},System.Collections.Immutable.ImmutableDictionary{System.String,System.String},System.Object[]);Use DiagnosticExtensions.CreateDiagnostic
+M:Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor,Microsoft.CodeAnalysis.Location,Microsoft.CodeAnalysis.DiagnosticSeverity,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Location},System.Collections.Immutable.ImmutableDictionary{System.String,System.String},System.Object[]);Use DiagnosticExtensions.CreateDiagnostic;Use DiagnosticExtensions.CreateDiagnostic
+M:Microsoft.CodeAnalysis.Diagnostic.Create(System.String,System.String,Microsoft.CodeAnalysis.LocalizableString,Microsoft.CodeAnalysis.DiagnosticSeverity,Microsoft.CodeAnalysis.DiagnosticSeverity,System.Boolean,System.Int32,Microsoft.CodeAnalysis.LocalizableString,Microsoft.CodeAnalysis.LocalizableString,System.String,Microsoft.CodeAnalysis.Location,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Location},System.Collections.Generic.IEnumerable{System.String},System.Collections.Immutable.ImmutableDictionary{System.String,System.String});Use DiagnosticExtensions.CreateDiagnostic
+M:Microsoft.CodeAnalysis.Diagnostic.Create(System.String,System.String,Microsoft.CodeAnalysis.LocalizableString,Microsoft.CodeAnalysis.DiagnosticSeverity,Microsoft.CodeAnalysis.DiagnosticSeverity,System.Boolean,System.Int32,System.Boolean,Microsoft.CodeAnalysis.LocalizableString,Microsoft.CodeAnalysis.LocalizableString,System.String,Microsoft.CodeAnalysis.Location,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Location},System.Collections.Generic.IEnumerable{System.String},System.Collections.Immutable.ImmutableDictionary{System.String,System.String});Use DiagnosticExtensions.CreateDiagnostic
diff --git a/src/CodeFixes/SquiggleCop.Baseline.yaml b/src/CodeFixes/SquiggleCop.Baseline.yaml
index cfd419db8..ee47bd00a 100644
--- a/src/CodeFixes/SquiggleCop.Baseline.yaml
+++ b/src/CodeFixes/SquiggleCop.Baseline.yaml
@@ -848,6 +848,9 @@
- {Id: RemoveUnnecessaryImportsFixable, Title: '', Category: Style, DefaultSeverity: Note, IsEnabledByDefault: true, EffectiveSeverities: [Note], IsEverSuppressed: true}
- {Id: ROS0002, Title: Analyzer option is obsolete, Category: '', DefaultSeverity: Warning, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
- {Id: ROS0003, Title: Analyzer requires config option to be specified, Category: '', DefaultSeverity: Note, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
+- {Id: RS0030, Title: Do not use banned APIs, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: true}
+- {Id: RS0031, Title: The list of banned symbols contains a duplicate, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0035, Title: External access to internal symbols outside the restricted namespace(s) is prohibited, Category: ApiDesign, DefaultSeverity: Error, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1001, Title: Missing diagnostic analyzer attribute, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1002, Title: Missing kind argument when registering an analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1003, Title: Unsupported SymbolKind argument when registering a symbol analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
diff --git a/src/Common/DiagnosticExtensions.cs b/src/Common/DiagnosticExtensions.cs
index a05c29562..bbd44c96f 100644
--- a/src/Common/DiagnosticExtensions.cs
+++ b/src/Common/DiagnosticExtensions.cs
@@ -1,4 +1,6 @@
-namespace Moq.Analyzers.Common;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Moq.Analyzers.Common;
internal static class DiagnosticExtensions
{
@@ -37,6 +39,7 @@ public static Diagnostic CreateDiagnostic(
ImmutableDictionary? properties,
params object?[]? messageArgs) => location.CreateDiagnostic(rule, additionalLocations: null, properties, messageArgs);
+ [SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "This is the API that wraps the banned API, so it must be allowed to call banned APIs.")]
public static Diagnostic CreateDiagnostic(
this Location location,
DiagnosticDescriptor rule,
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
new file mode 100644
index 000000000..408a21f63
--- /dev/null
+++ b/src/Directory.Build.props
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/src/tools/PerfDiff/SquiggleCop.Baseline.yaml b/src/tools/PerfDiff/SquiggleCop.Baseline.yaml
index abcc5aec6..83a37668c 100644
--- a/src/tools/PerfDiff/SquiggleCop.Baseline.yaml
+++ b/src/tools/PerfDiff/SquiggleCop.Baseline.yaml
@@ -847,6 +847,9 @@
- {Id: RemoveUnnecessaryImportsFixable, Title: '', Category: Style, DefaultSeverity: Note, IsEnabledByDefault: true, EffectiveSeverities: [Note], IsEverSuppressed: true}
- {Id: ROS0002, Title: Analyzer option is obsolete, Category: '', DefaultSeverity: Warning, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
- {Id: ROS0003, Title: Analyzer requires config option to be specified, Category: '', DefaultSeverity: Note, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
+- {Id: RS0030, Title: Do not use banned APIs, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0031, Title: The list of banned symbols contains a duplicate, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0035, Title: External access to internal symbols outside the restricted namespace(s) is prohibited, Category: ApiDesign, DefaultSeverity: Error, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1001, Title: Missing diagnostic analyzer attribute, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1002, Title: Missing kind argument when registering an analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1003, Title: Unsupported SymbolKind argument when registering a symbol analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
diff --git a/tests/Moq.Analyzers.Benchmarks/SquiggleCop.Baseline.yaml b/tests/Moq.Analyzers.Benchmarks/SquiggleCop.Baseline.yaml
index 1df5f57c1..19b411a0f 100644
--- a/tests/Moq.Analyzers.Benchmarks/SquiggleCop.Baseline.yaml
+++ b/tests/Moq.Analyzers.Benchmarks/SquiggleCop.Baseline.yaml
@@ -849,6 +849,9 @@
- {Id: RemoveUnnecessaryImportsFixable, Title: '', Category: Style, DefaultSeverity: Note, IsEnabledByDefault: true, EffectiveSeverities: [Note], IsEverSuppressed: true}
- {Id: ROS0002, Title: Analyzer option is obsolete, Category: '', DefaultSeverity: Warning, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
- {Id: ROS0003, Title: Analyzer requires config option to be specified, Category: '', DefaultSeverity: Note, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
+- {Id: RS0030, Title: Do not use banned APIs, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0031, Title: The list of banned symbols contains a duplicate, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0035, Title: External access to internal symbols outside the restricted namespace(s) is prohibited, Category: ApiDesign, DefaultSeverity: Error, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1001, Title: Missing diagnostic analyzer attribute, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1002, Title: Missing kind argument when registering an analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1003, Title: Unsupported SymbolKind argument when registering a symbol analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
diff --git a/tests/Moq.Analyzers.Test.Analyzers/SquiggleCop.Baseline.yaml b/tests/Moq.Analyzers.Test.Analyzers/SquiggleCop.Baseline.yaml
index 43d04a53d..9717893de 100644
--- a/tests/Moq.Analyzers.Test.Analyzers/SquiggleCop.Baseline.yaml
+++ b/tests/Moq.Analyzers.Test.Analyzers/SquiggleCop.Baseline.yaml
@@ -847,6 +847,9 @@
- {Id: RemoveUnnecessaryImportsFixable, Title: '', Category: Style, DefaultSeverity: Note, IsEnabledByDefault: true, EffectiveSeverities: [Note], IsEverSuppressed: true}
- {Id: ROS0002, Title: Analyzer option is obsolete, Category: '', DefaultSeverity: Warning, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
- {Id: ROS0003, Title: Analyzer requires config option to be specified, Category: '', DefaultSeverity: Note, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
+- {Id: RS0030, Title: Do not use banned APIs, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0031, Title: The list of banned symbols contains a duplicate, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0035, Title: External access to internal symbols outside the restricted namespace(s) is prohibited, Category: ApiDesign, DefaultSeverity: Error, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1001, Title: Missing diagnostic analyzer attribute, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1002, Title: Missing kind argument when registering an analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1003, Title: Unsupported SymbolKind argument when registering a symbol analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
diff --git a/tests/Moq.Analyzers.Test/SquiggleCop.Baseline.yaml b/tests/Moq.Analyzers.Test/SquiggleCop.Baseline.yaml
index db19226d7..493242ccc 100644
--- a/tests/Moq.Analyzers.Test/SquiggleCop.Baseline.yaml
+++ b/tests/Moq.Analyzers.Test/SquiggleCop.Baseline.yaml
@@ -848,6 +848,9 @@
- {Id: RemoveUnnecessaryImportsFixable, Title: '', Category: Style, DefaultSeverity: Note, IsEnabledByDefault: true, EffectiveSeverities: [Note], IsEverSuppressed: true}
- {Id: ROS0002, Title: Analyzer option is obsolete, Category: '', DefaultSeverity: Warning, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
- {Id: ROS0003, Title: Analyzer requires config option to be specified, Category: '', DefaultSeverity: Note, IsEnabledByDefault: false, EffectiveSeverities: [None], IsEverSuppressed: true}
+- {Id: RS0030, Title: Do not use banned APIs, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0031, Title: The list of banned symbols contains a duplicate, Category: ApiDesign, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
+- {Id: RS0035, Title: External access to internal symbols outside the restricted namespace(s) is prohibited, Category: ApiDesign, DefaultSeverity: Error, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1001, Title: Missing diagnostic analyzer attribute, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1002, Title: Missing kind argument when registering an analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: RS1003, Title: Unsupported SymbolKind argument when registering a symbol analyzer action, Category: MicrosoftCodeAnalysisCorrectness, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}