From 913e3b5b1fa0427037f06a764cb690dda3f92219 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 14:29:08 +0100 Subject: [PATCH 01/21] Scaffolding after rspec script run --- analyzers/rspec/cs/S1133_c#.html | 10 ++++ analyzers/rspec/cs/S1133_c#.json | 17 +++++++ analyzers/rspec/cs/Sonar_way_profile.json | 1 + analyzers/rspec/vbnet/S1133_vb.net.html | 8 ++++ analyzers/rspec/vbnet/S1133_vb.net.json | 17 +++++++ analyzers/rspec/vbnet/Sonar_way_profile.json | 1 + .../Rules/RemoveObsoleteCode.cs | 48 +++++++++++++++++++ .../Rules/RemoveObsoleteCodeBase.cs | 36 ++++++++++++++ .../Rules/RemoveObsoleteCode.cs | 48 +++++++++++++++++++ .../PackagingTests/RuleTypeMappingCS.cs | 2 +- .../PackagingTests/RuleTypeMappingVB.cs | 2 +- .../Rules/RemoveObsoleteCodeTest.cs | 41 ++++++++++++++++ .../TestCases/RemoveObsoleteCode.cs | 5 ++ .../TestCases/RemoveObsoleteCode.vb | 7 +++ 14 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 analyzers/rspec/cs/S1133_c#.html create mode 100644 analyzers/rspec/cs/S1133_c#.json create mode 100644 analyzers/rspec/vbnet/S1133_vb.net.html create mode 100644 analyzers/rspec/vbnet/S1133_vb.net.json create mode 100644 analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs create mode 100644 analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs create mode 100644 analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb diff --git a/analyzers/rspec/cs/S1133_c#.html b/analyzers/rspec/cs/S1133_c#.html new file mode 100644 index 00000000000..68fbe2f2300 --- /dev/null +++ b/analyzers/rspec/cs/S1133_c#.html @@ -0,0 +1,10 @@ +

This rule is meant to be used as a way to track code which is marked as being deprecated. Deprecated code should eventually be removed.

+

Noncompliant Code Example

+
+[Obsolete] // Noncompliant
+void Method()
+{
+    // ..
+}
+
+ diff --git a/analyzers/rspec/cs/S1133_c#.json b/analyzers/rspec/cs/S1133_c#.json new file mode 100644 index 00000000000..df8aa39d333 --- /dev/null +++ b/analyzers/rspec/cs/S1133_c#.json @@ -0,0 +1,17 @@ +{ + "title": "Deprecated code should be removed", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "10min" + }, + "tags": [ + "obsolete" + ], + "defaultSeverity": "Info", + "ruleSpecification": "RSPEC-1133", + "sqKey": "S1133", + "scope": "All", + "quickfix": "unknown" +} diff --git a/analyzers/rspec/cs/Sonar_way_profile.json b/analyzers/rspec/cs/Sonar_way_profile.json index 608da404352..444cf4210f6 100644 --- a/analyzers/rspec/cs/Sonar_way_profile.json +++ b/analyzers/rspec/cs/Sonar_way_profile.json @@ -22,6 +22,7 @@ "S1121", "S1123", "S1125", + "S1133", "S1134", "S1135", "S1144", diff --git a/analyzers/rspec/vbnet/S1133_vb.net.html b/analyzers/rspec/vbnet/S1133_vb.net.html new file mode 100644 index 00000000000..9a1691a1c1d --- /dev/null +++ b/analyzers/rspec/vbnet/S1133_vb.net.html @@ -0,0 +1,8 @@ +

This rule is meant to be used as a way to track code which is marked as being deprecated. Deprecated code should eventually be removed.

+

Noncompliant Code Example

+
+<Obsolete> ' Noncompliant
+Sub Procedure()
+End Sub
+
+ diff --git a/analyzers/rspec/vbnet/S1133_vb.net.json b/analyzers/rspec/vbnet/S1133_vb.net.json new file mode 100644 index 00000000000..df8aa39d333 --- /dev/null +++ b/analyzers/rspec/vbnet/S1133_vb.net.json @@ -0,0 +1,17 @@ +{ + "title": "Deprecated code should be removed", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "10min" + }, + "tags": [ + "obsolete" + ], + "defaultSeverity": "Info", + "ruleSpecification": "RSPEC-1133", + "sqKey": "S1133", + "scope": "All", + "quickfix": "unknown" +} diff --git a/analyzers/rspec/vbnet/Sonar_way_profile.json b/analyzers/rspec/vbnet/Sonar_way_profile.json index 64c3988b67b..11efa1e3eb7 100644 --- a/analyzers/rspec/vbnet/Sonar_way_profile.json +++ b/analyzers/rspec/vbnet/Sonar_way_profile.json @@ -15,6 +15,7 @@ "S1110", "S1123", "S1125", + "S1133", "S1134", "S1135", "S1155", diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs new file mode 100644 index 00000000000..41437101878 --- /dev/null +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs @@ -0,0 +1,48 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using System.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Diagnostics; +using SonarAnalyzer.Common; +using SonarAnalyzer.Helpers; + +namespace SonarAnalyzer.Rules.CSharp; + +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class RemoveObsoleteCode : RemoveObsoleteCodeBase +{ + + protected override ILanguageFacade Language => CSharpFacade.Instance; + + protected override void Initialize(SonarAnalysisContext context) => + context.RegisterSyntaxNodeActionInNonGenerated(c => + { + var node = c.Node; + if (true) + { + c.ReportIssue(Diagnostic.Create(Rule, node.GetLocation())); + } + }, + SyntaxKind.InvocationExpression); +} diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs new file mode 100644 index 00000000000..afdd2befc29 --- /dev/null +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -0,0 +1,36 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; +using SonarAnalyzer.Common; +using SonarAnalyzer.Helpers; + +namespace SonarAnalyzer.Rules; + +public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnalyzer + where TSyntaxKind : struct +{ + private const string DiagnosticId = "S1133"; + + protected override string MessageFormat => "FIXME"; + + protected RemoveObsoleteCodeBase() : base(DiagnosticId) { } +} diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs new file mode 100644 index 00000000000..aaaa2e34eee --- /dev/null +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs @@ -0,0 +1,48 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using System.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.VisualBasic; +using Microsoft.CodeAnalysis.VisualBasic.Syntax; +using SonarAnalyzer.Common; +using SonarAnalyzer.Helpers; + +namespace SonarAnalyzer.Rules.VisualBasic; + +[DiagnosticAnalyzer(LanguageNames.VisualBasic)] +public sealed class RemoveObsoleteCode : RemoveObsoleteCodeBase +{ + + protected override ILanguageFacade Language => VisualBasicFacade.Instance; + + protected override void Initialize(SonarAnalysisContext context) => + context.RegisterSyntaxNodeActionInNonGenerated(c => + { + var node = c.Node; + if (true) + { + c.ReportIssue(Diagnostic.Create(Rule, node.GetLocation())); + } + }, + SyntaxKind.InvocationExpression); +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs index 8a7a979b11d..0cb1259d864 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingCS.cs @@ -1057,7 +1057,7 @@ internal static class RuleTypeMappingCS // ["S1130"], // ["S1131"], // ["S1132"], - // ["S1133"], + ["S1133"] = "CODE_SMELL", ["S1134"] = "CODE_SMELL", ["S1135"] = "CODE_SMELL", // ["S1136"], diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs index b86fec111e4..755f2ef4aa9 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/PackagingTests/RuleTypeMappingVB.cs @@ -1057,7 +1057,7 @@ internal static class RuleTypeMappingVB // ["S1130"], // ["S1131"], // ["S1132"], - // ["S1133"], + ["S1133"] = "CODE_SMELL", ["S1134"] = "CODE_SMELL", ["S1135"] = "CODE_SMELL", // ["S1136"], diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs new file mode 100644 index 00000000000..14bea8adcbe --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -0,0 +1,41 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +using CS = SonarAnalyzer.Rules.CSharp; +using VB = SonarAnalyzer.Rules.VisualBasic; + +namespace SonarAnalyzer.UnitTest.Rules; + +[TestClass] +public class RemoveObsoleteCodeTest +{ + private readonly VerifierBuilder builderCS = new VerifierBuilder(); + + [TestMethod] + public void RemoveObsoleteCode_CS() => + builderCS.AddPaths("RemoveObsoleteCode.cs").Verify(); + + private readonly VerifierBuilder builderVB = new VerifierBuilder(); // FIXME: Move this up + + [TestMethod] + public void RemoveObsoleteCode_VB() => + builderVB.AddPaths("RemoveObsoleteCode.vb").Verify(); +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs new file mode 100644 index 00000000000..a790d6d1f92 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs @@ -0,0 +1,5 @@ +using System; + +public class Program +{ +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb new file mode 100644 index 00000000000..f5b9e9276c6 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb @@ -0,0 +1,7 @@ +Public Class Program + + Public Sub Test() + + End Sub + +End Class From b9909c817c34b2e89a4b452082ad53db7c771279 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 14:41:00 +0100 Subject: [PATCH 02/21] Fixes after scaffolding --- .../Rules/RemoveObsoleteCode.cs | 21 ------------------- .../Rules/RemoveObsoleteCodeBase.cs | 16 ++++++++++---- .../Rules/RemoveObsoleteCode.cs | 21 ------------------- .../Rules/RemoveObsoleteCodeTest.cs | 3 +-- 4 files changed, 13 insertions(+), 48 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs index 41437101878..10696f62db9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs @@ -18,31 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using System.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; -using SonarAnalyzer.Common; -using SonarAnalyzer.Helpers; - namespace SonarAnalyzer.Rules.CSharp; [DiagnosticAnalyzer(LanguageNames.CSharp)] public sealed class RemoveObsoleteCode : RemoveObsoleteCodeBase { - protected override ILanguageFacade Language => CSharpFacade.Instance; - - protected override void Initialize(SonarAnalysisContext context) => - context.RegisterSyntaxNodeActionInNonGenerated(c => - { - var node = c.Node; - if (true) - { - c.ReportIssue(Diagnostic.Create(Rule, node.GetLocation())); - } - }, - SyntaxKind.InvocationExpression); } diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs index afdd2befc29..376ef1c1426 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -18,9 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using System.Collections.Immutable; -using Microsoft.CodeAnalysis; -using SonarAnalyzer.Common; using SonarAnalyzer.Helpers; namespace SonarAnalyzer.Rules; @@ -30,7 +27,18 @@ public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnaly { private const string DiagnosticId = "S1133"; - protected override string MessageFormat => "FIXME"; + protected override string MessageFormat => "Do not forget to remove this deprecated code someday."; protected RemoveObsoleteCodeBase() : base(DiagnosticId) { } + + protected override void Initialize(SonarAnalysisContext context) => + context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => + { + if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + && attribute.IsInType(KnownType.System_ObsoleteAttribute)) + { + c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); + } + }, + Language.SyntaxKind.Attribute); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs index aaaa2e34eee..a6c5aa4e1c7 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs @@ -18,31 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using System.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.VisualBasic; -using Microsoft.CodeAnalysis.VisualBasic.Syntax; -using SonarAnalyzer.Common; -using SonarAnalyzer.Helpers; - namespace SonarAnalyzer.Rules.VisualBasic; [DiagnosticAnalyzer(LanguageNames.VisualBasic)] public sealed class RemoveObsoleteCode : RemoveObsoleteCodeBase { - protected override ILanguageFacade Language => VisualBasicFacade.Instance; - - protected override void Initialize(SonarAnalysisContext context) => - context.RegisterSyntaxNodeActionInNonGenerated(c => - { - var node = c.Node; - if (true) - { - c.ReportIssue(Diagnostic.Create(Rule, node.GetLocation())); - } - }, - SyntaxKind.InvocationExpression); } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index 14bea8adcbe..6640e98dee0 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -28,13 +28,12 @@ namespace SonarAnalyzer.UnitTest.Rules; public class RemoveObsoleteCodeTest { private readonly VerifierBuilder builderCS = new VerifierBuilder(); + private readonly VerifierBuilder builderVB = new VerifierBuilder(); [TestMethod] public void RemoveObsoleteCode_CS() => builderCS.AddPaths("RemoveObsoleteCode.cs").Verify(); - private readonly VerifierBuilder builderVB = new VerifierBuilder(); // FIXME: Move this up - [TestMethod] public void RemoveObsoleteCode_VB() => builderVB.AddPaths("RemoveObsoleteCode.vb").Verify(); From 55841aa9817f32ad3bac5f4fe11d71632ed6a725 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 14:56:29 +0100 Subject: [PATCH 03/21] Add test cases --- .../TestCases/RemoveObsoleteCode.cs | 18 +++++++++++++++++- .../TestCases/RemoveObsoleteCode.vb | 18 ++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs index a790d6d1f92..fa1459c1acd 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs @@ -1,5 +1,21 @@ using System; -public class Program +namespace Tests { + [Obsolete] // Noncompliant {{Do not forget to remove this deprecated code someday.}} +// ^^^^^^^^ + public class Program + { + [Obsolete("Message")] // Noncompliant + public delegate void CloseDelegate(object sender, EventArgs eventArgs); + + [Obsolete("Message", error: true)] // Noncompliant + public event CloseDelegate OnClose; + + [Obsolete()] // Noncompliant + public Program() + { + + } + } } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb index f5b9e9276c6..3e4d81ee08d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb @@ -1,7 +1,17 @@ -Public Class Program +Imports System - Public Sub Test() +Namespace Tests + ' Noncompliant {{Do not forget to remove this deprecated code someday.}} + Public Class Program - End Sub + ' Noncompliant + Public Delegate Sub CloseDelegate(ByVal sender As Object, ByVal eventArgs As EventArgs) -End Class + ' Noncompliant + Public Event OnClose As CloseDelegate + + ' Noncompliant + Public Sub New() + End Sub + End Class +End Namespace From 8071442a314cf8285ee3004373ffdc211b1470e6 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 14:59:37 +0100 Subject: [PATCH 04/21] Improve tests --- .../SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs | 2 +- .../SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs index fa1459c1acd..a2e8bb1761f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs @@ -12,7 +12,7 @@ public class Program [Obsolete("Message", error: true)] // Noncompliant public event CloseDelegate OnClose; - [Obsolete()] // Noncompliant + [ObsoleteAttribute()] // Noncompliant public Program() { diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb index 3e4d81ee08d..72f934e16d8 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb @@ -1,7 +1,8 @@ Imports System Namespace Tests - ' Noncompliant {{Do not forget to remove this deprecated code someday.}} + + ' Noncompliant ^6#8 {{Do not forget to remove this deprecated code someday.}} Public Class Program ' Noncompliant @@ -10,7 +11,7 @@ Namespace Tests ' Noncompliant Public Event OnClose As CloseDelegate - ' Noncompliant + ' Noncompliant Public Sub New() End Sub End Class From 48c2e160a56efc1bd6f50be61785a31e2c57ff7a Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 16:42:13 +0100 Subject: [PATCH 05/21] Update ITs --- ...5E-C6AE-4D2D-A9DD-B6EFD19A4279}-S1133.json | 173 +++++++ .../its/expected/Net5/Net5--net5.0-S1133.json | 17 + .../its/expected/Net7/Net7--net7.0-S1133.json | 30 ++ .../akka.net/Akka--netstandard2.0-S1133.json | 472 ++++++++++++++++++ .../Akka.Cluster--netstandard2.0-S1133.json | 69 +++ ...a.Cluster.Tools--netstandard2.0-S1133.json | 30 ++ .../Akka.DI.Core--netstandard2.0-S1133.json | 17 + ...kka.Persistence--netstandard2.0-S1133.json | 30 ++ ...rsistence.Query--netstandard2.0-S1133.json | 17 + ...ence.Sql.Common--netstandard2.0-S1133.json | 17 + .../Akka.Remote--netstandard2.0-S1133.json | 56 +++ ...zation.Hyperion--netstandard2.0-S1133.json | 17 + .../Akka.Streams--netstandard2.0-S1133.json | 264 ++++++++++ .../Akka.TestKit--netstandard2.0-S1133.json | 43 ++ ...hared.Internals--netstandard2.0-S1133.json | 43 ++ 15 files changed, 1295 insertions(+) create mode 100644 analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S1133.json create mode 100644 analyzers/its/expected/Net5/Net5--net5.0-S1133.json create mode 100644 analyzers/its/expected/Net7/Net7--net7.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.DI.Core--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence.Query--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Serialization.Hyperion--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S1133.json create mode 100644 analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S1133.json diff --git a/analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S1133.json b/analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S1133.json new file mode 100644 index 00000000000..9e03269ce23 --- /dev/null +++ b/analyzers/its/expected/Ember-MM/EmberAPI-{208AA35E-C6AE-4D2D-A9DD-B6EFD19A4279}-S1133.json @@ -0,0 +1,173 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 572, +"startColumn": 10, +"endLine": 572, +"endColumn": 80 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 583, +"startColumn": 10, +"endLine": 583, +"endColumn": 90 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 592, +"startColumn": 10, +"endLine": 592, +"endColumn": 98 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 686, +"startColumn": 10, +"endLine": 686, +"endColumn": 83 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 697, +"startColumn": 10, +"endLine": 697, +"endColumn": 89 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 705, +"startColumn": 10, +"endLine": 705, +"endColumn": 95 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 748, +"startColumn": 10, +"endLine": 748, +"endColumn": 98 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 760, +"startColumn": 10, +"endLine": 760, +"endColumn": 92 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 782, +"startColumn": 10, +"endLine": 782, +"endColumn": 95 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 794, +"startColumn": 10, +"endLine": 794, +"endColumn": 90 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 1543, +"startColumn": 10, +"endLine": 1543, +"endColumn": 84 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 1554, +"startColumn": 10, +"endLine": 1554, +"endColumn": 90 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Ember-MM\EmberAPI\clsAPIMediaContainers.vb", +"region": { +"startLine": 1562, +"startColumn": 10, +"endLine": 1562, +"endColumn": 96 +} +} +} +] +} diff --git a/analyzers/its/expected/Net5/Net5--net5.0-S1133.json b/analyzers/its/expected/Net5/Net5--net5.0-S1133.json new file mode 100644 index 00000000000..b592f8749b9 --- /dev/null +++ b/analyzers/its/expected/Net5/Net5--net5.0-S1133.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Net5\Net5\AttributesOnLocalFunctions.cs", +"region": { +"startLine": 11, +"startColumn": 14, +"endLine": 11, +"endColumn": 22 +} +} +} +] +} diff --git a/analyzers/its/expected/Net7/Net7--net7.0-S1133.json b/analyzers/its/expected/Net7/Net7--net7.0-S1133.json new file mode 100644 index 00000000000..3b0a1eae052 --- /dev/null +++ b/analyzers/its/expected/Net7/Net7--net7.0-S1133.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Net7\Net7\features\ExtendedNameofScope.cs", +"region": { +"startLine": 5, +"startColumn": 10, +"endLine": 5, +"endColumn": 35 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\Net7\Net7\features\ExtendedNameofScope.cs", +"region": { +"startLine": 11, +"startColumn": 10, +"endLine": 11, +"endColumn": 38 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka--netstandard2.0-S1133.json new file mode 100644 index 00000000000..87118a12823 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka--netstandard2.0-S1133.json @@ -0,0 +1,472 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorCell.Children.cs", +"region": { +"startLine": 359, +"startColumn": 10, +"endLine": 359, +"endColumn": 51 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorCell.cs", +"region": { +"startLine": 236, +"startColumn": 10, +"endLine": 236, +"endColumn": 62 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs", +"region": { +"startLine": 21, +"startColumn": 6, +"endLine": 21, +"endColumn": 70 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs", +"region": { +"startLine": 49, +"startColumn": 6, +"endLine": 49, +"endColumn": 70 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs", +"region": { +"startLine": 80, +"startColumn": 6, +"endLine": 80, +"endColumn": 70 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs", +"region": { +"startLine": 121, +"startColumn": 6, +"endLine": 121, +"endColumn": 70 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorProducerPipeline.cs", +"region": { +"startLine": 237, +"startColumn": 6, +"endLine": 237, +"endColumn": 70 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRef.cs", +"region": { +"startLine": 399, +"startColumn": 10, +"endLine": 399, +"endColumn": 71 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRef.cs", +"region": { +"startLine": 444, +"startColumn": 10, +"endLine": 444, +"endColumn": 60 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRef.cs", +"region": { +"startLine": 493, +"startColumn": 10, +"endLine": 493, +"endColumn": 68 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRef.cs", +"region": { +"startLine": 568, +"startColumn": 10, +"endLine": 568, +"endColumn": 71 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Cancellation\Cancelable.cs", +"region": { +"startLine": 79, +"startColumn": 10, +"endLine": 79, +"endColumn": 81 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Cell.cs", +"region": { +"startLine": 92, +"startColumn": 10, +"endLine": 92, +"endColumn": 55 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\EmptyLocalActorRef.cs", +"region": { +"startLine": 50, +"startColumn": 10, +"endLine": 50, +"endColumn": 71 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ExtendedActorSystem.cs", +"region": { +"startLine": 46, +"startColumn": 10, +"endLine": 46, +"endColumn": 74 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\FSM.cs", +"region": { +"startLine": 740, +"startColumn": 10, +"endLine": 740, +"endColumn": 99 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Props.cs", +"region": { +"startLine": 384, +"startColumn": 10, +"endLine": 384, +"endColumn": 113 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Props.cs", +"region": { +"startLine": 562, +"startColumn": 10, +"endLine": 562, +"endColumn": 121 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Scheduler\DeprecatedSchedulerExtensions.cs", +"region": { +"startLine": 16, +"startColumn": 6, +"endLine": 16, +"endColumn": 53 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Scheduler\DeprecatedSchedulerExtensions.cs", +"region": { +"startLine": 27, +"startColumn": 10, +"endLine": 27, +"endColumn": 245 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\Stash\IWithBoundedStash.cs", +"region": { +"startLine": 20, +"startColumn": 6, +"endLine": 20, +"endColumn": 106 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\TypedActor.cs", +"region": { +"startLine": 29, +"startColumn": 6, +"endLine": 29, +"endColumn": 73 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Dispatch\MessageQueues\UnboundedPriorityMessageQueue.cs", +"region": { +"startLine": 28, +"startColumn": 10, +"endLine": 28, +"endColumn": 130 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\IO\Udp.cs", +"region": { +"startLine": 173, +"startColumn": 14, +"endLine": 173, +"endColumn": 142 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\IO\UdpConnected.cs", +"region": { +"startLine": 155, +"startColumn": 14, +"endLine": 155, +"endColumn": 142 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Pattern\BackoffOptions.cs", +"region": { +"startLine": 26, +"startColumn": 10, +"endLine": 26, +"endColumn": 82 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Pattern\BackoffOptions.cs", +"region": { +"startLine": 55, +"startColumn": 10, +"endLine": 55, +"endColumn": 82 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\PatternMatch.cs", +"region": { +"startLine": 15, +"startColumn": 6, +"endLine": 15, +"endColumn": 79 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\Broadcast.cs", +"region": { +"startLine": 284, +"startColumn": 10, +"endLine": 284, +"endColumn": 102 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\ConsistentHashRouter.cs", +"region": { +"startLine": 653, +"startColumn": 10, +"endLine": 653, +"endColumn": 110 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\RoundRobin.cs", +"region": { +"startLine": 334, +"startColumn": 10, +"endLine": 334, +"endColumn": 96 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\RouterConfig.cs", +"region": { +"startLine": 47, +"startColumn": 10, +"endLine": 47, +"endColumn": 59 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\RouterConfig.cs", +"region": { +"startLine": 160, +"startColumn": 10, +"endLine": 160, +"endColumn": 85 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\ScatterGatherFirstCompleted.cs", +"region": { +"startLine": 405, +"startColumn": 10, +"endLine": 405, +"endColumn": 128 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Serialization\Serialization.cs", +"region": { +"startLine": 134, +"startColumn": 10, +"endLine": 134, +"endColumn": 102 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Serialization\Serialization.cs", +"region": { +"startLine": 325, +"startColumn": 10, +"endLine": 325, +"endColumn": 106 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S1133.json new file mode 100644 index 00000000000..beb328ca28a --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S1133.json @@ -0,0 +1,69 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\ClusterSettings.cs", +"region": { +"startLine": 261, +"startColumn": 10, +"endLine": 261, +"endColumn": 75 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\Routing\ClusterRoutingConfig.cs", +"region": { +"startLine": 31, +"startColumn": 10, +"endLine": 31, +"endColumn": 55 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\Routing\ClusterRoutingConfig.cs", +"region": { +"startLine": 45, +"startColumn": 10, +"endLine": 45, +"endColumn": 55 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\Routing\ClusterRoutingConfig.cs", +"region": { +"startLine": 117, +"startColumn": 10, +"endLine": 117, +"endColumn": 55 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\Routing\ClusterRoutingConfig.cs", +"region": { +"startLine": 130, +"startColumn": 10, +"endLine": 130, +"endColumn": 55 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S1133.json new file mode 100644 index 00000000000..12abc4e600d --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Cluster.Tools--netstandard2.0-S1133.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Tools\PublishSubscribe\DistributedPubSubSettings.cs", +"region": { +"startLine": 121, +"startColumn": 10, +"endLine": 121, +"endColumn": 134 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\contrib\cluster\Akka.Cluster.Tools\Singleton\ClusterSingletonProxySettings.cs", +"region": { +"startLine": 147, +"startColumn": 10, +"endLine": 147, +"endColumn": 96 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.DI.Core--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.DI.Core--netstandard2.0-S1133.json new file mode 100644 index 00000000000..8d009c9f3db --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.DI.Core--netstandard2.0-S1133.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\contrib\dependencyinjection\Akka.DI.Core\DIActorContextAdapter.cs", +"region": { +"startLine": 46, +"startColumn": 10, +"endLine": 46, +"endColumn": 106 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S1133.json new file mode 100644 index 00000000000..4d22b276b53 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S1133.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Fsm\PersistentFSM.cs", +"region": { +"startLine": 387, +"startColumn": 14, +"endLine": 389, +"endColumn": 59 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\JournalProtocol.cs", +"region": { +"startLine": 290, +"startColumn": 10, +"endLine": 290, +"endColumn": 132 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.Query--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Persistence.Query--netstandard2.0-S1133.json new file mode 100644 index 00000000000..0a353b6745c --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence.Query--netstandard2.0-S1133.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence.Query\EventEnvelope.cs", +"region": { +"startLine": 26, +"startColumn": 10, +"endLine": 26, +"endColumn": 69 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S1133.json new file mode 100644 index 00000000000..6d8eb006469 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S1133.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\QueryExecutor.cs", +"region": { +"startLine": 472, +"startColumn": 10, +"endLine": 472, +"endColumn": 18 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S1133.json new file mode 100644 index 00000000000..ecfaa8e0ca7 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Remote--netstandard2.0-S1133.json @@ -0,0 +1,56 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\AckedDelivery.cs", +"region": { +"startLine": 286, +"startColumn": 10, +"endLine": 286, +"endColumn": 55 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\DeadlineFailureDetector.cs", +"region": { +"startLine": 32, +"startColumn": 10, +"endLine": 32, +"endColumn": 118 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\RemoteActorRef.cs", +"region": { +"startLine": 99, +"startColumn": 10, +"endLine": 99, +"endColumn": 71 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote\Transport\Transport.cs", +"region": { +"startLine": 385, +"startColumn": 10, +"endLine": 385, +"endColumn": 104 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Serialization.Hyperion--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Serialization.Hyperion--netstandard2.0-S1133.json new file mode 100644 index 00000000000..696e82ff0fd --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Serialization.Hyperion--netstandard2.0-S1133.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\contrib\serializers\Akka.Serialization.Hyperion\HyperionSerializer.cs", +"region": { +"startLine": 265, +"startColumn": 10, +"endLine": 265, +"endColumn": 18 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S1133.json new file mode 100644 index 00000000000..77a751ed736 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Streams--netstandard2.0-S1133.json @@ -0,0 +1,264 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Attributes.cs", +"region": { +"startLine": 366, +"startColumn": 10, +"endLine": 366, +"endColumn": 90 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Attributes.cs", +"region": { +"startLine": 383, +"startColumn": 10, +"endLine": 383, +"endColumn": 90 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\FlowOperations.cs", +"region": { +"startLine": 83, +"startColumn": 10, +"endLine": 83, +"endColumn": 61 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\FlowOperations.cs", +"region": { +"startLine": 473, +"startColumn": 10, +"endLine": 473, +"endColumn": 82 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\FlowOperations.cs", +"region": { +"startLine": 1252, +"startColumn": 10, +"endLine": 1252, +"endColumn": 58 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\Internal\InternalFlowOperations.cs", +"region": { +"startLine": 106, +"startColumn": 10, +"endLine": 106, +"endColumn": 61 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\Internal\InternalFlowOperations.cs", +"region": { +"startLine": 475, +"startColumn": 10, +"endLine": 475, +"endColumn": 82 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\SourceOperations.cs", +"region": { +"startLine": 81, +"startColumn": 10, +"endLine": 81, +"endColumn": 61 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\SourceOperations.cs", +"region": { +"startLine": 447, +"startColumn": 10, +"endLine": 447, +"endColumn": 82 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\SourceOperations.cs", +"region": { +"startLine": 1171, +"startColumn": 10, +"endLine": 1171, +"endColumn": 58 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\SubFlowOperations.cs", +"region": { +"startLine": 83, +"startColumn": 10, +"endLine": 83, +"endColumn": 61 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Dsl\SubFlowOperations.cs", +"region": { +"startLine": 1179, +"startColumn": 10, +"endLine": 1179, +"endColumn": 58 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Implementation\Fusing\Ops.cs", +"region": { +"startLine": 542, +"startColumn": 10, +"endLine": 542, +"endColumn": 78 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\AbstractStage.cs", +"region": { +"startLine": 383, +"startColumn": 6, +"endLine": 383, +"endColumn": 56 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\AbstractStage.cs", +"region": { +"startLine": 522, +"startColumn": 6, +"endLine": 522, +"endColumn": 56 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\Stage.cs", +"region": { +"startLine": 34, +"startColumn": 6, +"endLine": 34, +"endColumn": 56 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\Stage.cs", +"region": { +"startLine": 91, +"startColumn": 6, +"endLine": 91, +"endColumn": 56 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\Stage.cs", +"region": { +"startLine": 99, +"startColumn": 6, +"endLine": 99, +"endColumn": 56 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\Stage.cs", +"region": { +"startLine": 134, +"startColumn": 6, +"endLine": 134, +"endColumn": 56 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams\Stage\Stage.cs", +"region": { +"startLine": 244, +"startColumn": 6, +"endLine": 244, +"endColumn": 56 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S1133.json new file mode 100644 index 00000000000..70b48eefff8 --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.TestKit--netstandard2.0-S1133.json @@ -0,0 +1,43 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.TestKit\TestBarrier.cs", +"region": { +"startLine": 29, +"startColumn": 10, +"endLine": 29, +"endColumn": 68 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.TestKit\TestLatch.cs", +"region": { +"startLine": 36, +"startColumn": 10, +"endLine": 36, +"endColumn": 99 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.TestKit\TestProbe.cs", +"region": { +"startLine": 91, +"startColumn": 10, +"endLine": 91, +"endColumn": 70 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S1133.json b/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S1133.json new file mode 100644 index 00000000000..9a4fe641ecc --- /dev/null +++ b/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S1133.json @@ -0,0 +1,43 @@ +{ +"issues": [ +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Shared.Internals\AkkaSpec.cs", +"region": { +"startLine": 171, +"startColumn": 10, +"endLine": 171, +"endColumn": 73 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Shared.Internals\AkkaSpec.cs", +"region": { +"startLine": 177, +"startColumn": 10, +"endLine": 177, +"endColumn": 75 +} +} +}, +{ +"id": "S1133", +"message": "Do not forget to remove this deprecated code someday.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Shared.Internals\AkkaSpec.cs", +"region": { +"startLine": 183, +"startColumn": 10, +"endLine": 183, +"endColumn": 75 +} +} +} +] +} From cb02f16287b03f66430d6caf4866d7c8e30ffead Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 16:42:22 +0100 Subject: [PATCH 06/21] Unsued using --- .../src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs index 376ef1c1426..b7e704d6bd0 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -18,8 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using SonarAnalyzer.Helpers; - namespace SonarAnalyzer.Rules; public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnalyzer From 15e5c832bdf2f8f96528a817da0b1f89c8548bc2 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 24 Jan 2023 16:44:14 +0100 Subject: [PATCH 07/21] Formatting --- .../SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs | 2 +- .../SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs index a2e8bb1761f..e28da777c61 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs @@ -12,7 +12,7 @@ public class Program [Obsolete("Message", error: true)] // Noncompliant public event CloseDelegate OnClose; - [ObsoleteAttribute()] // Noncompliant + [ObsoleteAttribute()] // Noncompliant public Program() { diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb index 72f934e16d8..229d1544b71 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb @@ -11,7 +11,7 @@ Namespace Tests ' Noncompliant Public Event OnClose As CloseDelegate - ' Noncompliant + ' Noncompliant Public Sub New() End Sub End Class From 1a2afe89e217a4476a2d723aeb213bc3866455a0 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Wed, 25 Jan 2023 13:46:38 +0100 Subject: [PATCH 08/21] Fix code smell --- .../tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index 6640e98dee0..ab8325c971f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -18,7 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - using CS = SonarAnalyzer.Rules.CSharp; using VB = SonarAnalyzer.Rules.VisualBasic; From 6dc53a241a64f370f212d11256e131f85c7b0234 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 14:02:51 +0100 Subject: [PATCH 09/21] Add tests for attribute targets --- .../Rules/RemoveObsoleteCodeTest.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index ab8325c971f..f739152eec3 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -33,6 +33,47 @@ public class RemoveObsoleteCodeTest public void RemoveObsoleteCode_CS() => builderCS.AddPaths("RemoveObsoleteCode.cs").Verify(); + [DataTestMethod] + // All attribute targets of [Obsolete] + [DataRow("private bool field;")] // AttributeTargets.Field + [DataRow("private event EventHandler SomeEvent;")] // AttributeTargets.Event + [DataRow("private bool Prop { get; set; }")] // AttributeTargets.Property + [DataRow("private void Method() { }")] // AttributeTargets.Method + [DataRow("class C { }")] // AttributeTargets.Class + [DataRow("struct S { }")] // AttributeTargets.Struct + [DataRow("interface I { }")] // AttributeTargets.Interface + [DataRow("enum E { A }")] // AttributeTargets.Enum + [DataRow("public Test() { }")] // AttributeTargets.Constructor + [DataRow("delegate void Del();")] // AttributeTargets.Delegate + [DataRow("int this[int i] => 1;")] // Indexer + public void RemoveObsoleteCode_AttributeTargetTest(string attributeTargetDeclaration) + { + builderCS.AddSnippet(WrapInTestCode(attribute: null)).VerifyNoIssueReported(); + builderCS.AddSnippet(WrapInTestCode(attribute: "[Obsolete] // Noncompliant")).Verify(); + builderCS.AddSnippet(WrapInTestCode(attribute: "[Custom]")).VerifyNoIssueReported(); + builderCS.AddSnippet(WrapInTestCode(attribute: """ + [Obsolete] // Noncompliant + [Custom] + """)).Verify(); + + string WrapInTestCode(string attribute) + { + return $$""" + using System; + + [AttributeUsage(AttributeTargets.All)] + public sealed class CustomAttribute: Attribute + { + } + public class Test + { + {{attribute}} + {{attributeTargetDeclaration}} + } + """; + } + } + [TestMethod] public void RemoveObsoleteCode_VB() => builderVB.AddPaths("RemoveObsoleteCode.vb").Verify(); From fdcf0834660f36a7c96e64c7c6c837b157cc3f4a Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 14:09:10 +0100 Subject: [PATCH 10/21] Use `c.ContainingSymbol` as primary check. --- .../src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs index b7e704d6bd0..e918af876ea 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -32,7 +32,8 @@ public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnaly protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + if (c.ContainingSymbol?.HasAttribute(KnownType.System_ObsoleteAttribute) is true + && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute && attribute.IsInType(KnownType.System_ObsoleteAttribute)) { c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); From 5f8c18ceef5b414741d013f7abc72f636edfa420 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 14:23:42 +0100 Subject: [PATCH 11/21] Do c.ContainingSymbol check in ObsoleteAttributesNeedExplanationBase too. --- .../ObsoleteAttributesNeedExplanationBase.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs index 6cdff528ed5..4881156bbdc 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs @@ -30,16 +30,15 @@ public abstract class ObsoleteAttributesNeedExplanationBase : Sonar protected ObsoleteAttributesNeedExplanationBase() : base(DiagnosticId) { } protected sealed override void Initialize(SonarAnalysisContext context) => - context.RegisterNodeAction( - Language.GeneratedCodeRecognizer, - c => + context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => + { + if (c.ContainingSymbol?.HasAttribute(KnownType.System_ObsoleteAttribute) is true + && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + && attribute.IsInType(KnownType.System_ObsoleteAttribute) + && !attribute.GetParameters().Any()) { - if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute - && attribute.IsInType(KnownType.System_ObsoleteAttribute) - && !attribute.GetParameters().Any()) - { - c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); - } - }, - Language.SyntaxKind.Attribute); + c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); + } + }, + Language.SyntaxKind.Attribute); } From 38acf5fd490081e92b41820da034252f82537934 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 14:28:18 +0100 Subject: [PATCH 12/21] Refactor tests --- .../Rules/RemoveObsoleteCodeTest.cs | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index f739152eec3..f27ba7e6a29 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -33,6 +33,10 @@ public class RemoveObsoleteCodeTest public void RemoveObsoleteCode_CS() => builderCS.AddPaths("RemoveObsoleteCode.cs").Verify(); + [TestMethod] + public void RemoveObsoleteCode_VB() => + builderVB.AddPaths("RemoveObsoleteCode.vb").Verify(); + [DataTestMethod] // All attribute targets of [Obsolete] [DataRow("private bool field;")] // AttributeTargets.Field @@ -48,33 +52,28 @@ public class RemoveObsoleteCodeTest [DataRow("int this[int i] => 1;")] // Indexer public void RemoveObsoleteCode_AttributeTargetTest(string attributeTargetDeclaration) { - builderCS.AddSnippet(WrapInTestCode(attribute: null)).VerifyNoIssueReported(); - builderCS.AddSnippet(WrapInTestCode(attribute: "[Obsolete] // Noncompliant")).Verify(); - builderCS.AddSnippet(WrapInTestCode(attribute: "[Custom]")).VerifyNoIssueReported(); - builderCS.AddSnippet(WrapInTestCode(attribute: """ + builderCS.AddSnippet(WrapInTestCode(string.Empty)).VerifyNoIssueReported(); + builderCS.AddSnippet(WrapInTestCode("[Obsolete] // Noncompliant")).Verify(); + builderCS.AddSnippet(WrapInTestCode("[Custom]")).VerifyNoIssueReported(); + builderCS.AddSnippet(WrapInTestCode(""" [Obsolete] // Noncompliant [Custom] """)).Verify(); - string WrapInTestCode(string attribute) - { - return $$""" - using System; + string WrapInTestCode(string attribute) => + $$""" + using System; - [AttributeUsage(AttributeTargets.All)] - public sealed class CustomAttribute: Attribute - { - } - public class Test - { - {{attribute}} - {{attributeTargetDeclaration}} - } - """; - } - } + [AttributeUsage(AttributeTargets.All)] + public sealed class CustomAttribute: Attribute + { + } - [TestMethod] - public void RemoveObsoleteCode_VB() => - builderVB.AddPaths("RemoveObsoleteCode.vb").Verify(); + public class Test + { + {{attribute}} + {{attributeTargetDeclaration}} + } + """; + } } From f3fa1649cc0bc6fd31731d924d411f13a0c342a4 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 14:58:28 +0100 Subject: [PATCH 13/21] Add CS 10 test with top level statements and add support for it. --- .../SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs | 2 +- .../SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs | 4 ++++ .../TestCases/RemoveObsoleteCode.CSharp10.cs | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs index e918af876ea..fbbf13ae44b 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -32,7 +32,7 @@ public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnaly protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if (c.ContainingSymbol?.HasAttribute(KnownType.System_ObsoleteAttribute) is true + if ((c.ContainingSymbol?.HasAttribute(KnownType.System_ObsoleteAttribute) is true || c.ContainingSymbol.IsTopLevelMain()) && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute && attribute.IsInType(KnownType.System_ObsoleteAttribute)) { diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index f27ba7e6a29..05b344e732a 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -33,6 +33,10 @@ public class RemoveObsoleteCodeTest public void RemoveObsoleteCode_CS() => builderCS.AddPaths("RemoveObsoleteCode.cs").Verify(); + [TestMethod] + public void RemoveObsoleteCode_CSharp10() => + builderCS.AddPaths("RemoveObsoleteCode.CSharp10.cs").WithTopLevelStatements().WithOptions(ParseOptionsHelper.FromCSharp10).Verify(); + [TestMethod] public void RemoveObsoleteCode_VB() => builderVB.AddPaths("RemoveObsoleteCode.vb").Verify(); diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs new file mode 100644 index 00000000000..c4fb3fa2163 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs @@ -0,0 +1,7 @@ +using System; + +[ObsoleteAttribute()] // Noncompliant +void Local() +{ + +} From 027d8a2ec6668d4d7fdebe1401406b7a78278a29 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 15:47:08 +0100 Subject: [PATCH 14/21] Formatting --- .../SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index 05b344e732a..6fc1a2ee5d5 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -35,7 +35,10 @@ public class RemoveObsoleteCodeTest [TestMethod] public void RemoveObsoleteCode_CSharp10() => - builderCS.AddPaths("RemoveObsoleteCode.CSharp10.cs").WithTopLevelStatements().WithOptions(ParseOptionsHelper.FromCSharp10).Verify(); + builderCS.AddPaths("RemoveObsoleteCode.CSharp10.cs") + .WithTopLevelStatements() + .WithOptions(ParseOptionsHelper.FromCSharp10) + .Verify(); [TestMethod] public void RemoveObsoleteCode_VB() => From 41be4b2ffe803b4d35759d005ca1a7f18121bc23 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 16:08:15 +0100 Subject: [PATCH 15/21] Revert changes to ObsoleteAttributesNeedExplanationBase --- .../Rules/ObsoleteAttributesNeedExplanationBase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs index 4881156bbdc..cdbd53e9ce0 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs @@ -32,8 +32,7 @@ public abstract class ObsoleteAttributesNeedExplanationBase : Sonar protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if (c.ContainingSymbol?.HasAttribute(KnownType.System_ObsoleteAttribute) is true - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute && attribute.IsInType(KnownType.System_ObsoleteAttribute) && !attribute.GetParameters().Any()) { From b79961830c1b7784ef6bce2b9fc2f478237ebdf4 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 16:10:33 +0100 Subject: [PATCH 16/21] Add test for local functions and fix the missing diagnostic --- .../Rules/RemoveObsoleteCodeBase.cs | 3 +-- .../TestCases/RemoveObsoleteCode.CSharp10.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs index fbbf13ae44b..b7e704d6bd0 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -32,8 +32,7 @@ public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnaly protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if ((c.ContainingSymbol?.HasAttribute(KnownType.System_ObsoleteAttribute) is true || c.ContainingSymbol.IsTopLevelMain()) - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute && attribute.IsInType(KnownType.System_ObsoleteAttribute)) { c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs index c4fb3fa2163..5bd4074405a 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs @@ -5,3 +5,15 @@ void Local() { } + +[Obsolete] // Noncompliant +record R +{ + void M() + { + [Obsolete] // Noncompliant + void Local() + { + } + } +} From 308b1da0747f7da27c92f5fa625cb2758480160b Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 16:12:05 +0100 Subject: [PATCH 17/21] Revert changes to ObsoleteAttributesNeedExplanationBase --- .../ObsoleteAttributesNeedExplanationBase.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs index cdbd53e9ce0..6cdff528ed5 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/ObsoleteAttributesNeedExplanationBase.cs @@ -30,14 +30,16 @@ public abstract class ObsoleteAttributesNeedExplanationBase : Sonar protected ObsoleteAttributesNeedExplanationBase() : base(DiagnosticId) { } protected sealed override void Initialize(SonarAnalysisContext context) => - context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => - { - if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute - && attribute.IsInType(KnownType.System_ObsoleteAttribute) - && !attribute.GetParameters().Any()) + context.RegisterNodeAction( + Language.GeneratedCodeRecognizer, + c => { - c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); - } - }, - Language.SyntaxKind.Attribute); + if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + && attribute.IsInType(KnownType.System_ObsoleteAttribute) + && !attribute.GetParameters().Any()) + { + c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation())); + } + }, + Language.SyntaxKind.Attribute); } From b4b3cfec6bf4b2a9c52a6047af5353d4b4f33a2d Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 16:19:35 +0100 Subject: [PATCH 18/21] Simplify test case --- .../Rules/RemoveObsoleteCodeTest.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index 6fc1a2ee5d5..fabc9a38a8d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -46,17 +46,17 @@ public class RemoveObsoleteCodeTest [DataTestMethod] // All attribute targets of [Obsolete] - [DataRow("private bool field;")] // AttributeTargets.Field - [DataRow("private event EventHandler SomeEvent;")] // AttributeTargets.Event - [DataRow("private bool Prop { get; set; }")] // AttributeTargets.Property - [DataRow("private void Method() { }")] // AttributeTargets.Method - [DataRow("class C { }")] // AttributeTargets.Class - [DataRow("struct S { }")] // AttributeTargets.Struct - [DataRow("interface I { }")] // AttributeTargets.Interface - [DataRow("enum E { A }")] // AttributeTargets.Enum - [DataRow("public Test() { }")] // AttributeTargets.Constructor - [DataRow("delegate void Del();")] // AttributeTargets.Delegate - [DataRow("int this[int i] => 1;")] // Indexer + [DataRow("bool field;")] // AttributeTargets.Field + [DataRow("event EventHandler SomeEvent;")] // AttributeTargets.Event + [DataRow("bool Prop { get; set; }")] // AttributeTargets.Property + [DataRow("void Method() { }")] // AttributeTargets.Method + [DataRow("class C { }")] // AttributeTargets.Class + [DataRow("struct S { }")] // AttributeTargets.Struct + [DataRow("interface I { }")] // AttributeTargets.Interface + [DataRow("enum E { A }")] // AttributeTargets.Enum + [DataRow("public Test() { }")] // AttributeTargets.Constructor + [DataRow("delegate void Del();")] // AttributeTargets.Delegate + [DataRow("int this[int i] => 1;")] // Indexer public void RemoveObsoleteCode_AttributeTargetTest(string attributeTargetDeclaration) { builderCS.AddSnippet(WrapInTestCode(string.Empty)).VerifyNoIssueReported(); From 71e0078fd66d47c85508370096a96fa6e5f1290e Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 18:04:01 +0100 Subject: [PATCH 19/21] Add VB attribute target tests. --- .../Rules/RemoveObsoleteCodeTest.cs | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index fabc9a38a8d..6d24ce639d5 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -57,7 +57,7 @@ public class RemoveObsoleteCodeTest [DataRow("public Test() { }")] // AttributeTargets.Constructor [DataRow("delegate void Del();")] // AttributeTargets.Delegate [DataRow("int this[int i] => 1;")] // Indexer - public void RemoveObsoleteCode_AttributeTargetTest(string attributeTargetDeclaration) + public void RemoveObsoleteCode_AttributeTargetTest_CS(string attributeTargetDeclaration) { builderCS.AddSnippet(WrapInTestCode(string.Empty)).VerifyNoIssueReported(); builderCS.AddSnippet(WrapInTestCode("[Obsolete] // Noncompliant")).Verify(); @@ -83,4 +83,68 @@ public class Test } """; } + + [DataTestMethod] + // All attribute targets of [Obsolete] + [DataRow("Private field As Boolean")] // AttributeTargets.Field + [DataRow("Event SomeEvent As EventHandler")] // AttributeTargets.Event + [DataRow("Property Prop As Boolean")] // AttributeTargets.Property + [DataRow(""" + Private Sub Method() + End Sub + """)] // AttributeTargets.Method + [DataRow(""" + Class C + End Class + """)] // AttributeTargets.Class + [DataRow(""" + Structure S + End Structure + """)] // AttributeTargets.Struct + [DataRow(""" + Interface I + End Interface + """)] // AttributeTargets.Interface + [DataRow(""" + Enum E + A + End Enum + """)] // AttributeTargets.Enum + [DataRow(""" + Public Sub New() + End Sub + """)] // AttributeTargets.Constructor + [DataRow("Delegate Sub Del()")] // AttributeTargets.Delegate + [DataRow(""" + Default ReadOnly Property Item(ByVal i As Integer) As Integer + Get + Return 1 + End Get + End Property + """)] // Indexer + public void RemoveObsoleteCode_AttributeTargetTest_VB(string attributeTargetDeclaration) + { + builderVB.AddSnippet(WrapInTestCode(string.Empty)).VerifyNoIssueReported(); + builderVB.AddSnippet(WrapInTestCode(" ' Noncompliant")).Verify(); + builderVB.AddSnippet(WrapInTestCode("")).VerifyNoIssueReported(); + builderVB.AddSnippet(WrapInTestCode(""" + ' Noncompliant + + """)).Verify(); + + string WrapInTestCode(string attribute) => + $$""" + Imports System + + + Public NotInheritable Class CustomAttribute + Inherits Attribute + End Class + + Public Class Test + {{attribute}} + {{attributeTargetDeclaration}} + End Class + """; + } } From 6922f421e027acd7543c0c09571363acee5bafc0 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 31 Jan 2023 18:04:59 +0100 Subject: [PATCH 20/21] Formatting --- .../SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs index 6d24ce639d5..d1a301fc8b6 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -86,7 +86,7 @@ public class Test [DataTestMethod] // All attribute targets of [Obsolete] - [DataRow("Private field As Boolean")] // AttributeTargets.Field + [DataRow("Private field As Boolean")] // AttributeTargets.Field [DataRow("Event SomeEvent As EventHandler")] // AttributeTargets.Event [DataRow("Property Prop As Boolean")] // AttributeTargets.Property [DataRow(""" From 81eaaabee9049588df2d353dcd0339688153af21 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Wed, 1 Feb 2023 16:14:42 +0100 Subject: [PATCH 21/21] Remove namespace in VB test --- .../TestCases/RemoveObsoleteCode.vb | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb index 229d1544b71..247235ac1c7 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb @@ -1,18 +1,15 @@ Imports System -Namespace Tests + ' Noncompliant ^2#8 {{Do not forget to remove this deprecated code someday.}} +Public Class Program - ' Noncompliant ^6#8 {{Do not forget to remove this deprecated code someday.}} - Public Class Program + ' Noncompliant + Public Delegate Sub CloseDelegate(sender As Object, eventArgs As EventArgs) - ' Noncompliant - Public Delegate Sub CloseDelegate(ByVal sender As Object, ByVal eventArgs As EventArgs) + ' Noncompliant + Public Event OnClose As CloseDelegate - ' Noncompliant - Public Event OnClose As CloseDelegate - - ' Noncompliant - Public Sub New() - End Sub - End Class -End Namespace + ' Noncompliant + Public Sub New() + End Sub +End Class