Skip to content

Commit

Permalink
Add option to remove complexity calculation if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Apr 12, 2018
1 parent 91e901d commit 97711d8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ func main() {
Usage: "Set to check for and remove duplicate files from stats and output",
Destination: &processor.Duplicates,
},
cli.BoolFlag{
Name: "complexity, c",
Usage: "Set to skip complexity calculations note will be overridden if wide is set",
Destination: &processor.Complexity,
},
cli.BoolFlag{
Name: "wide, w",
Usage: "Set to check produce more output such as code vs complexity ranking",
Usage: "Set to check produce more output such as complexity and code vs complexity ranking",
Destination: &processor.More,
},
cli.Int64Flag{
Name: "averageage, aw",
Name: "averagewage, aw",
Usage: "Set as integer to set the average wage used for basic COCOMO calculation",
Destination: &processor.AverageWage,
Value: 56286,
Expand Down
30 changes: 26 additions & 4 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var tabularShortFormatBody = "%-20s %9d %9d %8d %9d %8d %10d\n"
var tabularShortFormatFile = "%-30s %9d %8d %9d %8d %10d\n"
var shortFormatFileTrucate = 29

var tabularShortFormatHeadNoComplexity = "%-22s %11s %11s %9s %11s %10s\n"
var tabularShortFormatBodyNoComplexity = "%-22s %11d %11d %9d %11d %10d\n"
var tabularShortFormatFileNoComplexity = "%-34s %11d %9d %11d %10d\n"
var shortFormatFileTrucateNoComplexity = 33

var tabularWideBreak = "-------------------------------------------------------------------------------------------------------------\n"
var tabularWideFormatHead = "%-33s %9s %9s %8s %9s %8s %10s %16s\n"
var tabularWideFormatBody = "%-33s %9d %9d %8d %9d %8d %10d %16.2f\n"
Expand Down Expand Up @@ -221,7 +226,12 @@ func fileSummerizeShort(input *chan *FileJob) string {
var str strings.Builder

str.WriteString(tabularShortBreak)
str.WriteString(fmt.Sprintf(tabularShortFormatHead, "Language", "Files", "Lines", "Code", "Comments", "Blanks", "Complexity"))
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatHead, "Language", "Files", "Lines", "Code", "Comments", "Blanks", "Complexity"))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatHeadNoComplexity, "Language", "Files", "Lines", "Code", "Comments", "Blanks"))

}

if !Files {
str.WriteString(tabularShortBreak)
Expand Down Expand Up @@ -315,7 +325,11 @@ func fileSummerizeShort(input *chan *FileJob) string {
str.WriteString(tabularShortBreak)
}

str.WriteString(fmt.Sprintf(tabularShortFormatBody, summary.Name, summary.Count, summary.Lines, summary.Code, summary.Comment, summary.Blank, summary.Complexity))
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatBody, summary.Name, summary.Count, summary.Lines, summary.Code, summary.Comment, summary.Blank, summary.Complexity))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatBodyNoComplexity, summary.Name, summary.Count, summary.Lines, summary.Code, summary.Comment, summary.Blank))
}

if Files {
sortSummaryFiles(&summary)
Expand All @@ -329,7 +343,11 @@ func fileSummerizeShort(input *chan *FileJob) string {
tmp = "~" + tmp[totrim:]
}

str.WriteString(fmt.Sprintf(tabularShortFormatFile, tmp, res.Lines, res.Code, res.Comment, res.Blank, res.Complexity))
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatFile, tmp, res.Lines, res.Code, res.Comment, res.Blank, res.Complexity))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatFileNoComplexity, tmp, res.Lines, res.Code, res.Comment, res.Blank))
}
}
}
}
Expand All @@ -339,7 +357,11 @@ func fileSummerizeShort(input *chan *FileJob) string {
}

str.WriteString(tabularShortBreak)
str.WriteString(fmt.Sprintf(tabularShortFormatBody, "Total", sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity))
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortFormatBody, "Total", sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity))
} else {
str.WriteString(fmt.Sprintf(tabularShortFormatBodyNoComplexity, "Total", sumFiles, sumLines, sumCode, sumComment, sumBlank))
}
str.WriteString(tabularShortBreak)

if !Cocomo {
Expand Down
23 changes: 23 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Verbose = false
var Debug = false
var Trace = false
var Duplicates = false
var Complexity = false
var More = false
var Cocomo = false
var SortBy = ""
Expand Down Expand Up @@ -101,8 +102,30 @@ func processConstants() {
}
}

func processFlags() {
// If wide/more mode is enabled we want the complexity calculation
// to happen regardless as thats the only purpose of the flag
if More && Complexity {
Complexity = false
}

if Debug {
printDebug(fmt.Sprintf("Path Black List: %s", PathBlacklist))
printDebug(fmt.Sprintf("Sort By: %s", SortBy))
printDebug(fmt.Sprintf("White List: %s", WhiteListExtensions))
printDebug(fmt.Sprintf("Files Output: %t", Files))
printDebug(fmt.Sprintf("Verbose: %t", Verbose))
printDebug(fmt.Sprintf("Duplicates Detection: %t", Duplicates))
printDebug(fmt.Sprintf("Complexity Calculation: %t", !Complexity))
printDebug(fmt.Sprintf("Wide: %t", More))
printDebug(fmt.Sprintf("Average Wage: %d", AverageWage))
printDebug(fmt.Sprintf("Cocomo: %t", !Cocomo))
}
}

func Process() {
processConstants()
processFlags()

// Clean up and invlid arguments before setting everything up
if len(DirFilePaths) == 0 {
Expand Down
16 changes: 10 additions & 6 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ func countStats(fileJob *FileJob) {
if !isWhitespace(fileJob.Content[index]) {
currentState = S_CODE

offsetJump = checkComplexity(fileJob.Content[index], index, endPoint, complexityChecks, fileJob)
if offsetJump != 0 {
fileJob.Complexity++
if !Complexity {
offsetJump = checkComplexity(fileJob.Content[index], index, endPoint, complexityChecks, fileJob)
if offsetJump != 0 {
fileJob.Complexity++
}
}
break state
}
Expand All @@ -258,9 +260,11 @@ func countStats(fileJob *FileJob) {
currentState = S_STRING
break state
} else {
offsetJump = checkComplexity(fileJob.Content[index], index, endPoint, complexityChecks, fileJob)
if offsetJump != 0 {
fileJob.Complexity++
if !Complexity {
offsetJump = checkComplexity(fileJob.Content[index], index, endPoint, complexityChecks, fileJob)
if offsetJump != 0 {
fileJob.Complexity++
}
}
break state
}
Expand Down

0 comments on commit 97711d8

Please sign in to comment.