PSCodeHealth icon indicating copy to clipboard operation
PSCodeHealth copied to clipboard

Lines of code counts whitespace

Open mattmcnabb opened this issue 8 years ago • 1 comments

When counting lines of code in a script or function, I'd argue that it's most valuable to only consider significant lines of code. It appears that Get-FunctionLinesOfCode is already excluding comments from it's total count, but I think that blank lines should be excluded as well.

Have a look here to see this in practice. If acceptable, I'll submit a PR.

mattmcnabb avatar Jan 10 '18 02:01 mattmcnabb

Couldn't you skip re-parsing the file, and just count the unique line numbers that actually have non-comment tokens on them?

($FunctionDefinition.Copy().Findall({$true},$true).Extent | % { $_.StartLineNumber, $_.EndLineNumber } | Sort -Unique -ov Counted).Count

Jaykul avatar Mar 06 '19 23:03 Jaykul