diff --git a/main.go b/main.go index 0075ea331..98e4edae6 100644 --- a/main.go +++ b/main.go @@ -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, diff --git a/processor/formatters.go b/processor/formatters.go index bb037e16c..6458e01fe 100644 --- a/processor/formatters.go +++ b/processor/formatters.go @@ -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" @@ -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) @@ -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) @@ -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)) + } } } } @@ -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 { diff --git a/processor/processor.go b/processor/processor.go index 230696c56..22c981839 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -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 = "" @@ -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 { diff --git a/processor/workers.go b/processor/workers.go index b1f759272..fdbd1ac6d 100644 --- a/processor/workers.go +++ b/processor/workers.go @@ -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 } @@ -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 }