mirror of
https://github.com/mgechev/revive.git
synced 2025-11-25 22:12:38 +02:00
refactor: remove tablewriter dependency (#1351)
* Rewrite Friendly.table method to replace tablewriter with fmt.Fprintf * Refactor Stylish formatter to use custom table rendering instead of tablewriter * Refactor Friendly and Stylish formatters to utilize a new custom table rendering function * Remove unused dependencies from go.mod and go.sum * Refactor table formatting by replacing formatTable with a new table function in friendly.go * Utilize text/tabwriter in fromatting a table * Refactor table function to use bytes.Buffer for improved performance
This commit is contained in:
@@ -31,6 +31,11 @@ func TestFriendly_printStatistics(t *testing.T) {
|
||||
stats: map[string]int{"rule2": 2, "rule1": 1, "rule3": 3},
|
||||
expected: "Warnings:\n 3 rule3 \n 2 rule2 \n 1 rule1 \n\n",
|
||||
},
|
||||
{
|
||||
name: "multiple stats with different length sorted by failures desc",
|
||||
stats: map[string]int{"rule2": 2, "rule1": 1, "rule3": 3, "rule100": 40},
|
||||
expected: "Warnings:\n 40 rule100 \n 3 rule3 \n 2 rule2 \n 1 rule1 \n\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -44,3 +49,41 @@ func TestFriendly_printStatistics(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFriendly_table(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input [][]string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "empty input",
|
||||
input: [][]string{},
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "single row",
|
||||
input: [][]string{{"1", "2", "3"}},
|
||||
expected: " 1 2 3 \n",
|
||||
},
|
||||
{
|
||||
name: "multiple rows",
|
||||
input: [][]string{{"1", "2", "3"}, {"4", "5", "6"}},
|
||||
expected: " 1 2 3 \n 4 5 6 \n",
|
||||
},
|
||||
{
|
||||
name: "multiple rows with different column lengths",
|
||||
input: [][]string{{"1", "22", "3"}, {"4", "5", "6"}},
|
||||
expected: " 1 22 3 \n 4 5 6 \n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := table(tt.input)
|
||||
if got != tt.expected {
|
||||
t.Errorf("got %q, want %q", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user