LineCounter 1.1.1

dotnet add package LineCounter --version 1.1.1                
NuGet\Install-Package LineCounter -Version 1.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LineCounter" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LineCounter --version 1.1.1                
#r "nuget: LineCounter, 1.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LineCounter as a Cake Addin
#addin nuget:?package=LineCounter&version=1.1.1

// Install LineCounter as a Cake Tool
#tool nuget:?package=LineCounter&version=1.1.1                

LineCounter.Net

A library to do "sensible line counting" - and - generating "shields" for Github readme's.

Features

  • Support single-line and multi-line comments
  • Auto detects test code
  • Supports parsing C#, F#, CSHtml, Javascript, C, Sql, and Typescript

Project statistics:

Stats Stats Stats

Getting started

First install the nuget package: LineCounter (it is a .Net Standard 2.0 package)

The simplest way to automate using this library is to add a unit test that on each time it runs, mutates your readme file. That way your stats are always up to date. E.g.

     [Test]
    public void MutateReadme()
    {
        var basePath = Path.Combine(Assembly.GetExecutingAssembly().Location, "..", "..", "..","..","..");
        
        var linecounter = new LineCounting();
        linecounter.ReplaceWebshieldsInFile(basePath, Path.Combine(basePath, "README.md"));
    }

The file to mutate must contain two magic markers and which will be where LineCounter.Net will replace content. (tags must be on a separate line)

Sensible line counting

What is "sensible line counting"? The idea is to count lines of code in such a way that

  • Only lines with semantic value are counted.
  • Various coding styles for the same code should roughly yield the same line counting.
  • Take into account "you get what you measure".

Why is that important? Because we want an estimate of size of code irregardles of coding style. For example

class Foo { // example 1
    public void Bar() {
        if(moons == 9) {
             Planet = Pluto;
        } else {
             Planet = Mars;
        }
    }
    public string Another() {
        Console.WriteLine("*")
    }
}

Should roughly yield the same lines of code as the less compact style

class Foo // example 2
{
    public void Bar() 
    {
        if(moons == 9) 
        {
             Planet = Pluto;
        } 
        else 
        {
             Planet = Mars;
        }
    }
    
    public string Another() 
    {
        Console.WriteLine("*")
    }
}

Example 1 takes up 12 lines of code while example 2 takes 19 lines -- 58% longer! Linecounter will report 8 lines of code for both code examples.

You get what you measure

The theory "you get what you measure" means exactly that. By whatever metric you measure, people will adapt seeking the easiest way to perform within the confinements of the measurements. E.g. when you praise programmers for the number of lines of code, they'll start making long-winded code. I've withnessed this first-hand a couple of times with outsourcing.

I'm well aware that this is far from perfect with respect to only counting semantic lines, but its a start.. and another reason I wrote this was to test on live data some string-algorithm optimizations I will blog about on http://firstclassthoughts.co.uk/ some day 😃

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 456 2/4/2024
1.0.5 805 8/9/2021
1.0.4 1,120 3/11/2018
1.0.0 982 3/10/2018

Add support for test-code detection and readme-mutator helper method