From 68b93a22e21feec5808c56114bf88ec1b1641529 Mon Sep 17 00:00:00 2001 From: Martin Strecker <103252490+martin-strecker-sonarsource@users.noreply.github.com> Date: Thu, 2 Feb 2023 13:55:59 +0100 Subject: [PATCH] New rule S1133: Deprecated code should be removed (#6669) --- ...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 ++ 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 | 27 + .../Rules/RemoveObsoleteCodeBase.cs | 42 ++ .../Rules/RemoveObsoleteCode.cs | 27 + .../PackagingTests/RuleTypeMappingCS.cs | 2 +- .../PackagingTests/RuleTypeMappingVB.cs | 2 +- .../Rules/RemoveObsoleteCodeTest.cs | 150 ++++++ .../TestCases/RemoveObsoleteCode.CSharp10.cs | 19 + .../TestCases/RemoveObsoleteCode.cs | 21 + .../TestCases/RemoveObsoleteCode.vb | 15 + 30 files changed, 1652 insertions(+), 2 deletions(-) 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 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.CSharp10.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/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 +} +} +} +] +} 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..10696f62db9 --- /dev/null +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RemoveObsoleteCode.cs @@ -0,0 +1,27 @@ +/* + * 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. + */ + +namespace SonarAnalyzer.Rules.CSharp; + +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class RemoveObsoleteCode : RemoveObsoleteCodeBase +{ + protected override ILanguageFacade Language => CSharpFacade.Instance; +} diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs new file mode 100644 index 00000000000..b7e704d6bd0 --- /dev/null +++ b/analyzers/src/SonarAnalyzer.Common/Rules/RemoveObsoleteCodeBase.cs @@ -0,0 +1,42 @@ +/* + * 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. + */ + +namespace SonarAnalyzer.Rules; + +public abstract class RemoveObsoleteCodeBase : SonarDiagnosticAnalyzer + where TSyntaxKind : struct +{ + private const string DiagnosticId = "S1133"; + + 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 new file mode 100644 index 00000000000..a6c5aa4e1c7 --- /dev/null +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/RemoveObsoleteCode.cs @@ -0,0 +1,27 @@ +/* + * 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. + */ + +namespace SonarAnalyzer.Rules.VisualBasic; + +[DiagnosticAnalyzer(LanguageNames.VisualBasic)] +public sealed class RemoveObsoleteCode : RemoveObsoleteCodeBase +{ + protected override ILanguageFacade Language => VisualBasicFacade.Instance; +} 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..d1a301fc8b6 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/RemoveObsoleteCodeTest.cs @@ -0,0 +1,150 @@ +/* + * 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(); + private readonly VerifierBuilder builderVB = new VerifierBuilder(); + + [TestMethod] + 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(); + + [DataTestMethod] + // All attribute targets of [Obsolete] + [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_CS(string attributeTargetDeclaration) + { + 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) => + $$""" + using System; + + [AttributeUsage(AttributeTargets.All)] + public sealed class CustomAttribute: Attribute + { + } + + public class Test + { + {{attribute}} + {{attributeTargetDeclaration}} + } + """; + } + + [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 + """; + } +} 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..5bd4074405a --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.CSharp10.cs @@ -0,0 +1,19 @@ +using System; + +[ObsoleteAttribute()] // Noncompliant +void Local() +{ + +} + +[Obsolete] // Noncompliant +record R +{ + void M() + { + [Obsolete] // Noncompliant + void Local() + { + } + } +} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs new file mode 100644 index 00000000000..e28da777c61 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.cs @@ -0,0 +1,21 @@ +using System; + +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; + + [ObsoleteAttribute()] // Noncompliant + public 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..247235ac1c7 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RemoveObsoleteCode.vb @@ -0,0 +1,15 @@ +Imports System + + ' Noncompliant ^2#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 Event OnClose As CloseDelegate + + ' Noncompliant + Public Sub New() + End Sub +End Class