Jump to content

CodeWatch 1.0 released

Posted on:October 17, 2016 at 02:00 AM

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:

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:

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.