Bug Report T743951
Visible to All Users

Code Cleanup – Code Cleanup does not work with an unused local constant declared in a private sub in Visual Basic

created 6 years ago (modified 6 years ago)

Hello,

I have a bunch of constants declared, and given a value but they are never used. Is there a way that CodeRush can delete all of these? I am having no luck with all of the options in the code cleanup for VB.NET. Thanks.

Here is an example of my code

Visual Basic
Const procName As String = "my name"

Visual Studio even notices these and flags them as a Warning since they are unused local constant.s

Answers approved by DevExpress Support

created 6 years ago

We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

    Comments (1)
    DevExpress Support Team 6 years ago

      We have published the requested patched build and are looking forward to hearing about your results. Meanwhile, we would like to mark this ticket as Public, if you do not mind, to include it in the What's New lists for future maintenance updates.

      created 6 years ago

      Hi Michelle,

      To accomplish your task I suggest you take advantage of the Remove unused members Code Cleanup rule which detects private members with no references and applies the Remove unused member refactoring to them:

      Note please, that this rule matches not only constants, but also fields, properties, methods, etc.
      Enable it on the CodeRush | Options | Editor | Visual Basic | Code Cleanup option page, then apply Code Cleanup for any document which contains unused private members using the Ctrl+. shortcut.
      I have recorded this video to illustrate the process.

      Additionally, Code Cleanup can be applied at a project or a solution level using the context menu in Visual Studio Solution Explorer tool window.

      Please keep in mind the changes of solution or project level cleanup will reflect in Visual Studio`s Undo only when a document is open.

      Please let me know whether or not this addresses your issue.

        Comments (2)
        MB MB
        Michelle Baldwin 6 years ago

          This does not work when the constant is declared inside of a private sub. For example.

          Visual Basic
          Public Sub RecordAuditString() Const procName As String = "clsAuditTrail.RecordAuditString" End Sub

          Visual studio has it marked as an unused local constant but CodeRush does not clean this up. Is there another setting I am overlooking?

          DevExpress Support Team 6 years ago

            Hi Michelle,

            Thank you for letting us know about the issue.
            I have managed to reproduce this behavior locally. Please give us some time to research it in greater detail.

            We will update this ticket once we have any news.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.