CodeWatch 1.0 released

      8 Comments on CodeWatch 1.0 released

Few days ago I decided to release my CodeWatch library. It’s the first version to show the concept.

Why is this useful

In .NET world we have couple of tools for keeping code quality. FxCop, NDepend, R# or SourceMonitor are those most known. In addition we have number for unit tests frameworks like NUnit or xUnit. All them are really useful when used properly.

Unfortunately due to various reasons there is still a gap. For example:

  • Developer running VS Code or other alternative editor like OmniSharp does not have benefits of FxCop or R#.
  • It’s hard to keep Coding Convention Guidelines defined for particular project aligned with the code in (sometimes long) development process.
  • Addressing all issues found by NDepend or SourceMonitor may become very cumbersome and time consuming.
  • Doing code reviews and reporting something that could be automatically reported is waste of time. Read my post on automation

My intention behind writing CodeWatch was to mitigate and preferable remove the issues above 🙂

What is it

CodeWatch is a NuGet package meant to keep your code following defined code conventions.

At the moment it can do 3 things:

  • Check fields naming (upper or lower case)
  • Check properties naming (upper or lower case)
  • Check if exceptions are handled i try/catch block

Sample usage

Here is sample code to demonstrate how the dll works:

//Our production code
public class Test
{
    public int myProp {get;set;}

    public void MyMethodThrowingException()
    {
         try
         {
             throw new Exception("Error!");
         }
         catch
         {
             //don't do nothing
         }
    }
}

//CodeQuality guard code (in tests dll)
using NUnit.Framework;

[TestFixture]
public class CodeQualityWatcher
{
    [Test]
    public void CheckThatAllPropertiesAreUppercase()
    {
        PropertyNamingWatcher watcher = new PropertyNamingWatcher();

        //Add types (or assemblies with WatchAssembly) to watch
        watcher.WatchType(typeof(Test));

        //Execute check
        watcher.Execute(); //This will throw exception because we expect Uppercase property names and Test class has myProp
    }  

    [Test]
    public void CheckThatAllTryCatchBlockHandleExceptions()
    {
        ExceptionHandlingWatcher watcher = new ExceptionHandlingWatcher();

        //Add types (or assemblies with WatchAssembly) to watch
        watcher.WatchType(typeof(Test));

        //Execute check
        watcher.Execute(); //This will throw exception because we don't handle exception in MyMethodThrowingException method
    }   
}

Sample project is also available here.

How to get it

Here is it’s NuGet gallery page. All sources are available on GitHub. More to come.

Follow me:

8 thoughts on “CodeWatch 1.0 released

    1. Pawel Post author

      Yes, I’m modeling a ‘configuration feature’. The idea is that such configuration will be stored with the project. Configurations would be based on rulesets.

      I have to thing how to solve this is a proper way. To not screw it 🙂

      Reply
  1. Lech

    Although Polish double negation is fabulous, “don’t do nothing” should be “do nothing” or “don’t do anything” 😉

    Reply
    1. Pawel Post author

      Thank you. I will remember 😛 “double negation” does not exist in English.

      Reply
  2. Pingback: dotnetomaniak.pl

  3. Pingback: Szumma #062 – 2016 42. hét | d/fuel

Leave a Reply

Your email address will not be published. Required fields are marked *