Last active
July 20, 2016 12:10
-
-
Save cloudRoutine/eb697e87f87e099dd95f to your computer and use it in GitHub Desktop.
Since Visual Studio won't calculate code metrics for F# projects, this script will calculate some some rough stats.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
let find_files dir = Directory.GetFiles( dir, "*.fs?", SearchOption.AllDirectories ) | |
let not_start (s:string) p = not <| s.StartsWith p | |
let has_type (s:string) = if s.Contains @"type" then 1 else 0 | |
let has_module (s:string) = if s.Contains @"module" then 1 else 0 | |
let has_binding (s:string) = if s.Contains @"let" || | |
s.Contains @"member" then 1 else 0 | |
type Statistics = { ``Num Of Lines `` : int ; ``Num Of Files `` : int; | |
``Num Of Chars `` : int ; ``Num Of Types `` : int; | |
``Num Of Modules `` : int ; ``Num Of Bindings `` : int; | |
} | |
let generate_stats = | |
find_files | |
>> Array.filter (fun f -> f.EndsWith ".fs" || f.EndsWith ".fsx" || f.EndsWith ".fsi") | |
>> Array.fold (fun acc f -> | |
let contents = | |
f |> File.ReadAllLines | |
|> Array.filter ( fun s -> not <| String.IsNullOrWhiteSpace s) | |
|> Array.map ( fun s -> s.Trim() ) | |
|> Array.filter ( fun s -> not_start s "open" && | |
not_start s @"///" && | |
not_start s @"//" ) | |
{ ``Num Of Lines `` = acc.``Num Of Lines `` + Array.length contents ; | |
``Num Of Files `` = acc.``Num Of Files `` + 1 ; | |
``Num Of Chars `` = acc.``Num Of Chars `` + Array.sumBy String.length contents; | |
``Num Of Types `` = acc.``Num Of Types `` + Array.sumBy has_type contents; | |
``Num Of Modules `` = acc.``Num Of Modules `` + Array.sumBy has_module contents; | |
``Num Of Bindings `` = acc.``Num Of Bindings `` + Array.sumBy has_binding contents; | |
} | |
) | |
{ ``Num Of Lines `` = 0; ``Num Of Files `` = 0; | |
``Num Of Chars `` = 0; ``Num Of Types `` = 0; | |
``Num Of Modules `` = 0; ``Num Of Bindings `` = 0; | |
} | |
;; | |
Path.GetDirectoryName __SOURCE_DIRECTORY__ |> generate_stats ;; | |
@"C:\Users\jared\Github\Clones\visualfsharp\src\fsharp" |> generate_stats ;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment