Ticket T517589
Visible to All Users

Custom code cleanup action

created 8 years ago

Dear,

Is it possible to create my own code cleanup action?

For example, when I run code cleanup on a document, I want to replace multiple empty lines with single empty line.
The important thing is, I want to do that as part of code cleanup process, not as some standalone "extra tool".

Is this possible and if yes, how?

Thank you,
Zvonko

Comments (1)
DevExpress Support Team 8 years ago

    Hi Zvonko,

    Please, give us additional time to research the issue and prepare the demonstration project. We will update this ticket once we have any results.
    Your patience is greatly appreciated.

    Regards,
    Igor

    Answers approved by DevExpress Support

    created 7 years ago

    Zvonko,

    We have addressed code formatting for blank lines in recent CodeRush updates.
    Please refer to the following CodeRush documentation article to get more details on how to configure this:
    How To Add/Remove Line Breaks To/From Your Code

    Recent CodeRush 17.2.7 update can be installed via Visual Studio extensions gallery: CodeRush

      created 8 years ago (modified 8 years ago)

      Hi Zvonko,

      Thank you for your patience.
      Please note that if you need the mechanism for replacing multiple empty lines, you can take advantage of the Organize Members options page, which allows you to set how many line-breaks you wish to have between the members (methods, constructors, regions, etc.

      As for the extensibility, I've created a simple CRR-plugin that is run as part of the code cleanup process. The corresponding project is in the attachment. To make it work, just unpack the archive and run the CustomCodeCleanUp.vsix file from the Dist folder. After that, in VisualStudio, go to CodeRush \ Options \ Editor \ C# \ Code Cleanup, find the name "Remove multiple new lines" in the list of existing cleanup providers, and enable it. That's all; now every time you call for Code Cleanup, this plugin will remove all extra ends of lines.
      The source code of the plugin is also in the attachment. Take a look.
      Hope it helps.
      Regards,
      Igor

        Show previous comments (10)
        DevExpress Support Team 8 years ago

          Zvonko,

          Thanks for the settings, I was able to see the issue with them.
          I have reworked the sample so that it uses a different approach to rewriting syntax and directives.
          Now it works with your settings in the following code:

          C#
          namespace ClassLibrary105 { public class TestClass { private void TestMethod1() { } private void TestMethod2() { } } }

          See this screencast:
          https://www.screencast.com/t/zA4x6IooGWXR

          Please check the attached code. If you find situations that are not handled by the code, it should now be more clear how to correct them.

          ZB ZB
          Zvonko Boštjančič 8 years ago

            It works, however I noticed weird side effect:If you disable "Organize Members" rule, this rule does not work.
            Did you try to disable "Organize Members" rule?

            DevExpress Support Team 8 years ago

              Zvonko,

              I have tried it with the disabled "Organize Members" rule and it works for me, new lines are added after #region and before the #endregion directives.
              Please see the following screencast:
              https://www.screencast.com/t/OineK1XSUU

              It is likely that you have tried it on different code.
              Please check it on the following code:

              C#
              namespace ClassLibrary105 { public class TestClass { #region First private void TestMethod1() { } #endregion #region Second private void TestMethod2() { } #endregion } }

              Here is the result I get:

              C#
              namespace ClassLibrary105 { public class TestClass { #region First private void TestMethod1() { } #endregion #region Second private void TestMethod2() { } #endregion } }

              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.