Skip to content

Commit

Permalink
add in dryness calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 1, 2024
1 parent e349fb1 commit 6c45375
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func main() {
false,
"calculate the number of unique lines of code (ULOC) for the project",
)
flags.BoolVarP(
&processor.Dryness,
"dryness",
"a",
false,
"calculate the dryness/wetness of the project (implies --uloc)",
)
flags.BoolVar(
&processor.DisableCheckBinary,
"binary",
Expand Down
4 changes: 4 additions & 0 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@ func fileSummarizeShort(input chan *FileJob) string {

if UlocMode {
str.WriteString(fmt.Sprintf(tabularShortUlocGlobalFormatBody, len(ulocGlobalCount)))
if Dryness {
dryness := float64(len(ulocGlobalCount)) / float64(sumLines)
str.WriteString(fmt.Sprintf("DRYness %% %30.2f\n", dryness))
}
str.WriteString(getTabularShortBreak())
}

Expand Down
9 changes: 9 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ var DisableCheckBinary = false
// UlocMode toggles checking for binary files using NUL bytes
var UlocMode = false

// Dryness toggles checking for binary files using NUL bytes
var Dryness = false

// SortBy sets which column output in formatter should be sorted by
var SortBy = ""

Expand Down Expand Up @@ -467,6 +470,10 @@ func processFlags() {
Generated = true
}

if Dryness {
UlocMode = true
}

if Debug {
printDebug(fmt.Sprintf("Path Deny List: %v", PathDenyList))
printDebug(fmt.Sprintf("Sort By: %s", SortBy))
Expand All @@ -481,6 +488,8 @@ func processFlags() {
printDebug(fmt.Sprintf("Minified/Generated Detection: %t/%t", Minified, Generated))
printDebug(fmt.Sprintf("Ignore Minified/Generated: %t/%t", IgnoreMinified, IgnoreGenerated))
printDebug(fmt.Sprintf("IncludeSymLinks: %t", IncludeSymLinks))
printDebug(fmt.Sprintf("Uloc: %t", UlocMode))
printDebug(fmt.Sprintf("Dryness: %t", Dryness))
}
}

Expand Down

0 comments on commit 6c45375

Please sign in to comment.