Monday, May 13, 2013

My VS 2010 Extension to remove duplicate blank lines is online

The problem

In my current project, we deal with a large legacy code base on a day to day basis. Some of the files inside are of 4000 lines of code and more. One of the reason for these huge files, is the continuous white spaces or multiple blank lines along with other reasons such as lack of SOLID principles.

No of lines is not an issue for an experienced intelligent developer, if he think from the technical point of view. But there is a mental blocking, when a new person is assigned with a bug in these areas. They look at the code and thinks, it's huge and need more time to find out the location and fix which eventually leads to delivery problems. 

Simple solution

As far as I understand, there is no silver bullet to solve the issue of increasing lines due to lack of SOLID principles in the code. That  needs to come from the heart of each developer. So lets focus on the issue of increasing lines, due to multiple blanks lines.

There is regex and the Visual Studio search and replace box supports it. We can use the appropriate regex to find multiple blank lines and replace with single empty line. Below is a link to regex which replaces double blank lines to single.

But as I told in the problem, if the developers are intelligent, the no of lines will not be an issue to them and they will be familiar with regex too. The case is different here. People needs single click easy solution and it lead to Visual Studio extensions.

My solution

Its simple. I used a simple Visual studio menu extensibility project after installing VS 2010 sdk and on the menu click, replaced the editor text after removing multiple blank lines.

How you can use it

The beauty of the new Visual Studio extensibility, is the ease of sharing our extensions to the world. I hosted my extension in Visual Studio gallery and you can download and use from the below link.

But I would suggest you going to Visual Studio 2010 tools -> extension manager and search for "remove blank lines" in the online store and install from there.

Source code

Feel free to reuse / browse the code in code plex.
Do whatever you want with the code base. If you have any queries please post as comment here or send a mail.

Below are some links which helped me during development.

Disable / enable VS menus based on criteria
GUIDs of existing VS menu command GUIDs

No comments: