diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index 2c9c060cf4..3d919c5415 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -619,9 +619,12 @@ func ComputeStringDiffs(dmp *diffmatchpatch.DiffMatchPatch, text1, text2 string) // Enable line mode for faster processing on large texts diffs := dmp.DiffMain(text1, text2, true) diffs = dmp.DiffCleanupSemantic(diffs) // Optional: Clean up diff for better readability - return FormatDiffs(diffs) + diffString := FormatDiffs(diffs) + return diffString } + + func FormatDiffs(diffs []diffmatchpatch.Diff) string { var parts []string @@ -635,11 +638,11 @@ func FormatDiffs(diffs []diffmatchpatch.Diff) string { var prefix string switch diff.Type { case diffmatchpatch.DiffInsert: - prefix = colorGreen + "+" + diff.Text + colorReset + prefix = colorGreen + "+" + CheckEmptyTrim(diff.Text) + colorReset case diffmatchpatch.DiffDelete: - prefix = colorRed + "-" + diff.Text + colorReset + prefix = colorRed + "-" + CheckEmptyTrim(diff.Text) + colorReset case diffmatchpatch.DiffEqual: - prefix = colorWhite + " " + diff.Text + colorReset + prefix = colorWhite + " " + CheckEmptyTrim(diff.Text) + colorReset } parts = append(parts, prefix) } @@ -967,7 +970,7 @@ func compareNodes(dmp *diffmatchpatch.DiffMatchPatch, nodeOne, nodeTwo Node) (No } } } - } + } return diffedNode, diffs, nil } func CompareTwoPaths(dmp *diffmatchpatch.DiffMatchPatch, analysisListOne, analysisListTwo []*Node) ([]Node, [][]string, int, error) { @@ -1007,7 +1010,7 @@ func CompareTwoPaths(dmp *diffmatchpatch.DiffMatchPatch, analysisListOne, analys dumnode.NodeType = "DependencyPackage" dumnode.DepPkg = model.AllIsDependencyTreeDependencyPackage{} } - + diffNode, diffs, err = compareNodes(dmp, *node, *dumnode) } else { diffNode, diffs, err = compareNodes(dmp, *node, *shorterPath[i]) @@ -1128,7 +1131,6 @@ func CompareAllPaths(listOne, listTwo [][]*Node) (DiffResult, error) { for i, val := range big { _, ok := used[i] if !ok { - //diff each missing path and append to result var missingPath []Node @@ -1143,11 +1145,11 @@ func CompareAllPaths(listOne, listTwo [][]*Node) (DiffResult, error) { } dmp := diffmatchpatch.New() diffNode, _, err := compareNodes(dmp, *node, *dumnode) - if err != nil { + if err != nil { return DiffResult{}, fmt.Errorf(err.Error()) } missingPath = append(missingPath, diffNode) - + } pathResults = append(pathResults, DiffedPath{PathOne: val, NodeDiffs: missingPath}) } diff --git a/pkg/analyzer/print_analysis.go b/pkg/analyzer/print_analysis.go index 59d3e90779..1653befb38 100644 --- a/pkg/analyzer/print_analysis.go +++ b/pkg/analyzer/print_analysis.go @@ -10,7 +10,7 @@ import ( const ( colMinWidth = 50 - trimLength = 20 + trimLength = 150 ) func GetNodeString(node Node) (string, error) { @@ -47,29 +47,30 @@ func GetNodeString(node Node) (string, error) { return message, nil case "DependencyPackage": depPkg := node.DepPkg - message := "Type:" + CheckEmptyTrim(depPkg.Type) + "\n" + message := "Type:" + depPkg.Type + "\n" for _, namespace := range depPkg.Namespaces { - message += "Namespace: " + CheckEmptyTrim(namespace.Namespace) + "\n" + message += "Namespace: " + namespace.Namespace + "\n" for _, name := range namespace.Names { message += "\t" - message += "Name: " + CheckEmptyTrim(name.Name) + message += "Name: " + name.Name message += "\n" for _, version := range name.Versions { message += "\t\t" - message += "Version: " + CheckEmptyTrim(version.Version) + "\n" + message += "Version: " + version.Version + "\n" message += "\t\t" - message += "Subpath: " + CheckEmptyTrim(version.Subpath) + "\n" + message += "Subpath: " + version.Subpath + "\n" message += "\t\tQualifiers: {\n" for _, outlier := range version.Qualifiers { message += "\t\t\t" - message += CheckEmptyTrim(outlier.Key) + ": " + CheckEmptyTrim(outlier.Value) + "\n" + message += outlier.Key + ": " + outlier.Value + "\n" } message += "\t\t}\n" } } + message += "\n" } return message, nil @@ -161,6 +162,8 @@ func PrintDiffedNodeTable(diffs DiffResult) error { table.SetColumnSeparator("\t\t") table.SetAutoMergeCells(false) + table.SetAutoWrapText(false) + table.SetRowLine(true) table.SetHeader([]string{"Node Differences"}) var row []string @@ -185,7 +188,6 @@ func PrintDiffedNodeTable(diffs DiffResult) error { row = append(row, s) table.Append(row) table.Append([]string{fmt.Sprintf("Node pair causing %v paths to differ", diff.Count)}) - table.Append([]string{"+------------------------------------------------------------------+"}) } table.SetAlignment(tablewriter.ALIGN_LEFT) @@ -204,8 +206,9 @@ func PrintDiffedPathTable(diffs DiffResult) error { table.SetBorders(tablewriter.Border{Left: true, Bottom: true}) table.SetNoWhiteSpace(true) + table.SetRowLine(true) + - table.SetColumnSeparator("\t\t") table.SetAutoMergeCells(false) table.SetHeader([]string{"Path Differences"}) @@ -227,10 +230,8 @@ func PrintDiffedPathTable(diffs DiffResult) error { } row = append(row, s) } - + table.Append(row) - - table.Append([]string{"+------------------------------------------------------------------+"}) } table.SetAlignment(tablewriter.ALIGN_LEFT)