Skip to main content

Side Project: Sweeper

So aside from a couple more minor touchups on the blog's theme, I'm also working fairly-actively on an add-in for Visual Studio. I plan on open-sourcing it although I have not yet done so. I'm not sure how exactly I want to release it and exactly what license I want to use.

Here's the low down. A while back I was introduced to StyleCop, a tool for enforcing a set of standard coding styles. Chris Trevino, a coworker of mine was the one that introduced it to me and talks about it in his blog post here. I bucked against it at first but quickly saw that it lead to clean, readable, consistent code. I found that sometimes it's a bit anal but hey, it's consistently anal.

What drove me nuts though is that some of the things are so absolutely simple, so completely trivial that it should take care of them for you,

So, I've begun an add-in to automate those trivial things for you. Take the following example, which throws 64 StyleCop violations:

  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8.  
  9. using System.Linq;
  10.  
  11.  
  12. namespace TestProjForAddin
  13. {
  14.  
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.  
  20.             InitializeComponent();
  21.         }
  22.  
  23.     }
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30. namespace test2
  31. {
  32.  
  33.  
  34.  
  35.     /// <summary>
  36.     /// Test class for testing the addin.
  37.     /// </summary>
  38.     public class Test
  39.     {
  40.  
  41.  
  42.  
  43.         /// <summary>
  44.         /// Is a monkey...
  45.         /// </summary>
  46.         private class Monkey
  47.         {
  48.             /// <summary>
  49.             /// private monkey
  50.             /// </summary>
  51.             private void monkey2()
  52.             {
  53.  
  54.                 for (int i = 0; i < 10; i++)
  55.                 {
  56.  
  57.                 }
  58.  
  59.             }
  60.  
  61.             public void monkey1()
  62.             {
  63.  
  64.                 if (true)
  65.                 {
  66.  
  67.                 }
  68.  
  69.             }
  70.  
  71.  
  72.         }
  73.  
  74.         /// <summary>
  75.         /// Gets or sets a test3
  76.         /// </summary>
  77.         private string Test3 { get; set; }
  78.  
  79.         public Test()
  80.         {
  81.  
  82.         }private List<string> test = new List<string>();
  83.         private string Test2()
  84.         {
  85.             return String.Empty;
  86.         }
  87.  
  88.         void test5()
  89.         {
  90.  
  91.         }
  92.  
  93.         /// <summary>
  94.         /// Look into the void.
  95.         /// </summary>
  96.         public void Test4()
  97.         {
  98.  
  99.         }
  100.  
  101.  
  102.     }
  103.  
  104. }

Then, after running Sweeper (so-called because you're sending in a sweeper team to take care of your mess before the StyleCop shows up...cheesy much?):

  1. namespace TestProjForAddin
  2. {
  3.     using System.Windows.Forms;
  4.  
  5.     public partial class Form1 : Form
  6.     {
  7.         public Form1()
  8.         {
  9.             InitializeComponent();
  10.         }
  11.     }
  12. }
  13.  
  14. namespace test2
  15. {
  16.     using System;
  17.     using System.Collections.Generic;
  18.  
  19.     /// <summary>
  20.     /// Test class for testing the addin.
  21.     /// </summary>
  22.     public class Test
  23.     {
  24.         private List<string> test = new List<string>();
  25.  
  26.         public Test()
  27.         {
  28.         }
  29.  
  30.         /// <summary>
  31.         /// Gets or sets a test3
  32.         /// </summary>
  33.         private string Test3 { get; set; }
  34.  
  35.         /// <summary>
  36.         /// Look into the void.
  37.         /// </summary>
  38.         public void Test4()
  39.         {
  40.         }
  41.  
  42.         void test5()
  43.         {
  44.         }
  45.  
  46.         private string Test2()
  47.         {
  48.             return String.Empty;
  49.         }
  50.  
  51.         /// <summary>
  52.         /// Is a monkey...
  53.         /// </summary>
  54.         private class Monkey
  55.         {
  56.             public void monkey1()
  57.             {
  58.                 if (true)
  59.                 {
  60.                 }
  61.             }
  62.  
  63.             /// <summary>
  64.             /// private monkey
  65.             /// </summary>
  66.             private void monkey2()
  67.             {
  68.                 for (int i = 0; i < 10; i++)
  69.                 {
  70.                 }
  71.             }
  72.         }
  73.     }
  74. }

And we're down to only 17 violations. These consist of:

  • A lack of documentation - you should be writing this on your own. There's other addins like GhostDoc which will help you with this. Maybe I can add support for automatically calling it on running Sweeper?
  • Lack of breaking the namespaces into 2 separate files - I'm not sure I want to automate this...at least not without prompting...
  • Lack of a file header - Personally I don't like the file headers, and also I don't know what to automatically populate it with.
  • Lack of access modifiers - probably could easily implement this, as long as I'm sure to avoid the things that shouldn't have modifiers like declarations within interfaces
  • Method names being of the wrong case - I don't think this should be automated.

So:

  1. What do you think?
  2. Would you use it?
  3. What features do you want added that can be safely automated?