Skip to content

Commit a930d22

Browse files
authored
refactor: rename ToString functions to String, per go convention (#113)
1 parent 733cf99 commit a930d22

File tree

9 files changed

+29
-29
lines changed

9 files changed

+29
-29
lines changed

internal/reporter/report.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (r Report) describeIgnores() string {
9898
)
9999
}
100100

101-
func (r Report) ToString() string {
101+
func (r Report) String() string {
102102
count := r.countKnownVulnerabilities()
103103
ignoreMsg := r.describeIgnores()
104104
word := "known"

internal/reporter/report_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,19 @@ func TestReport_HasIgnoredVulnerabilities(t *testing.T) {
234234
}
235235
}
236236

237-
func TestReport_ToString_NoVulnerabilities(t *testing.T) {
237+
func TestReport_String_NoVulnerabilities(t *testing.T) {
238238
t.Parallel()
239239

240240
msg := "no known vulnerabilities found"
241241

242242
r := reporter.Report{}
243243

244-
if actual := r.ToString(); !strings.Contains(actual, msg) {
244+
if actual := r.String(); !strings.Contains(actual, msg) {
245245
t.Errorf("Expected \"%s\" to contain \"%s\" but it did not", actual, msg)
246246
}
247247
}
248248

249-
func TestReport_ToString_OneVulnerability(t *testing.T) {
249+
func TestReport_String_OneVulnerability(t *testing.T) {
250250
t.Parallel()
251251

252252
expected := strings.Join([]string{
@@ -276,12 +276,12 @@ func TestReport_ToString_OneVulnerability(t *testing.T) {
276276
},
277277
}
278278

279-
if actual := r.ToString(); expected != actual {
279+
if actual := r.String(); expected != actual {
280280
t.Errorf("\nExpected:\n%s\nActual:\n%s", expected, actual)
281281
}
282282
}
283283

284-
func TestReport_ToString_MultipleVulnerabilities(t *testing.T) {
284+
func TestReport_String_MultipleVulnerabilities(t *testing.T) {
285285
t.Parallel()
286286

287287
expected := strings.Join([]string{
@@ -334,12 +334,12 @@ func TestReport_ToString_MultipleVulnerabilities(t *testing.T) {
334334
},
335335
}
336336

337-
if actual := r.ToString(); expected != actual {
337+
if actual := r.String(); expected != actual {
338338
t.Errorf("\nExpected:\n%s\nActual:\n%s", expected, actual)
339339
}
340340
}
341341

342-
func TestReport_ToString_AllIgnoredVulnerabilities(t *testing.T) {
342+
func TestReport_String_AllIgnoredVulnerabilities(t *testing.T) {
343343
t.Parallel()
344344

345345
msg := "no new vulnerabilities found (2 were ignored)"
@@ -376,12 +376,12 @@ func TestReport_ToString_AllIgnoredVulnerabilities(t *testing.T) {
376376
},
377377
}
378378

379-
if actual := r.ToString(); !strings.Contains(actual, msg) {
379+
if actual := r.String(); !strings.Contains(actual, msg) {
380380
t.Errorf("Expected \"%s\" to contain \"%s\" but it did not", actual, msg)
381381
}
382382
}
383383

384-
func TestReport_ToString_SomeIgnoredVulnerability(t *testing.T) {
384+
func TestReport_String_SomeIgnoredVulnerability(t *testing.T) {
385385
t.Parallel()
386386

387387
expected := strings.Join([]string{
@@ -424,7 +424,7 @@ func TestReport_ToString_SomeIgnoredVulnerability(t *testing.T) {
424424
},
425425
}
426426

427-
if actual := r.ToString(); expected != actual {
427+
if actual := r.String(); expected != actual {
428428
t.Errorf("\nExpected:\n%s\nActual:\n%s", expected, actual)
429429
}
430430
}

internal/reporter/reporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r *Reporter) PrintText(msg string) {
4848
}
4949

5050
type Result interface {
51-
ToString() string
51+
String() string
5252
}
5353

5454
func (r *Reporter) PrintResult(result Result) {
@@ -58,7 +58,7 @@ func (r *Reporter) PrintResult(result Result) {
5858
return
5959
}
6060

61-
fmt.Fprint(r.stdout, result.ToString())
61+
fmt.Fprint(r.stdout, result.String())
6262
}
6363

6464
// PrintJSONResults prints any results that this reporter has collected to

internal/reporter/reporter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
)
1212

1313
type TestResult struct {
14-
String string `json:"value"`
14+
Value string `json:"value"`
1515
ErrorWhenMarshalling bool `json:"-"`
1616
}
1717

18-
func (r TestResult) ToString() string {
19-
return r.String
18+
func (r TestResult) String() string {
19+
return r.Value
2020
}
2121

2222
func (r TestResult) MarshalJSON() ([]byte, error) {
@@ -62,7 +62,7 @@ func TestReporter_PrintResult(t *testing.T) {
6262
stderr := &bytes.Buffer{}
6363
r := reporter.New(stdout, stderr, false)
6464

65-
r.PrintResult(TestResult{String: msg})
65+
r.PrintResult(TestResult{Value: msg})
6666

6767
if gotStdout := stdout.String(); gotStdout != msg {
6868
t.Errorf("Expected stdout to have \"%s\", but got \"%s\"", msg, gotStdout)
@@ -82,7 +82,7 @@ func TestReporter_PrintResult_OutputAsJSON(t *testing.T) {
8282
stderr := &bytes.Buffer{}
8383
r := reporter.New(stdout, stderr, true)
8484

85-
r.PrintResult(TestResult{String: msg})
85+
r.PrintResult(TestResult{Value: msg})
8686

8787
if gotStdout := stdout.String(); gotStdout != "" {
8888
t.Errorf("Expected stdout to be empty, but got \"%s\"", gotStdout)
@@ -112,7 +112,7 @@ func TestReporter_PrintResult_OutputAsJSON_Error(t *testing.T) {
112112
stderr := &bytes.Buffer{}
113113
r := reporter.New(stdout, stderr, true)
114114

115-
r.PrintResult(TestResult{String: msg, ErrorWhenMarshalling: true})
115+
r.PrintResult(TestResult{Value: msg, ErrorWhenMarshalling: true})
116116

117117
if gotStdout := stdout.String(); gotStdout != "" {
118118
t.Errorf("Expected stdout to be empty, but got \"%s\"", gotStdout)

pkg/lockfile/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type Lockfile struct {
8383
Packages Packages `json:"packages"`
8484
}
8585

86-
func (l Lockfile) ToString() string {
86+
func (l Lockfile) String() string {
8787
lines := make([]string, 0, len(l.Packages))
8888

8989
for _, details := range l.Packages {

pkg/lockfile/parse_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestListParsers(t *testing.T) {
136136
}
137137
}
138138

139-
func TestLockfile_ToString(t *testing.T) {
139+
func TestLockfile_String(t *testing.T) {
140140
t.Parallel()
141141

142142
expected := strings.Join([]string{
@@ -190,7 +190,7 @@ func TestLockfile_ToString(t *testing.T) {
190190
},
191191
}
192192

193-
if actual := lockf.ToString(); expected != actual {
193+
if actual := lockf.String(); expected != actual {
194194
t.Errorf("\nExpected:\n%s\nActual:\n%s", expected, actual)
195195
}
196196
}

pkg/semantic/compare_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func expectCompareResult(
3333
if actualResult := a.Compare(b); actualResult != expectedResult {
3434
t.Errorf(
3535
"Expected %s to be %s %s, but it was %s",
36-
a.ToString(),
36+
a.String(),
3737
compareWord(t, expectedResult),
38-
b.ToString(),
38+
b.String(),
3939
compareWord(t, actualResult),
4040
)
4141
}

pkg/semantic/parse_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ func expectParsedVersionToMatchOriginalString(t *testing.T, str string) semantic
5454

5555
actualVersion := semantic.Parse(str)
5656

57-
if actualVersion.ToString() != str {
57+
if actualVersion.String() != str {
5858
t.Errorf(
5959
"Parsed version as a string did not equal original: %s != %s",
60-
actualVersion.ToString(),
60+
actualVersion.String(),
6161
str,
6262
)
6363
}
@@ -85,10 +85,10 @@ func expectParsedVersionToMatchString(
8585

8686
actualVersion := semantic.Parse(str)
8787

88-
if actualVersion.ToString() != expectedString {
88+
if actualVersion.String() != expectedString {
8989
t.Errorf(
9090
"Parsed version as a string did not equal expected: %s != %s",
91-
actualVersion.ToString(),
91+
actualVersion.String(),
9292
expectedString,
9393
)
9494
}

pkg/semantic/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (components *Components) Fetch(n int) int {
2121
return (*components)[n]
2222
}
2323

24-
func (v Version) ToString() string {
24+
func (v Version) String() string {
2525
str := ""
2626

2727
if v.LeadingV {

0 commit comments

Comments
 (0)