Skip to content

Commit

Permalink
Merge pull request #11 from k1LoW/msg-prefix
Browse files Browse the repository at this point in the history
Add message prefix
  • Loading branch information
k1LoW committed Sep 11, 2023
2 parents 8fccb0b + de3e054 commit 5b26582
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion analyzer/decisions/pkgnames/testdata/src/b_bar/b.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package b_bar // want "package"
package b_bar // want "gostyle.pkgnames"

func f() {}
2 changes: 1 addition & 1 deletion analyzer/decisions/pkgnames/testdata/src/util/util.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package util // want "package"
package util // want "gostyle.pkgnames"

func f() {}
3 changes: 2 additions & 1 deletion analyzer/effective/ifacenames/ifacenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
name = "ifacenames"
doc = "Analyzer based on https://go.dev/doc/effective_go#interface-names."
msg = "by convention, one-method interfaces are named by the method name plus an -er suffix or similar modification to construct an agent noun. (ref: https://go.dev/doc/effective_go#interface-names)"
msgc = "all interface names with the -er suffix are required. (THIS IS NOT IN Effective Go)"
)

var (
Expand Down Expand Up @@ -65,7 +66,7 @@ func run(pass *analysis.Pass) (any, error) {
}
}
if all && !strings.HasSuffix(ii.Name, "er") {
r.Append(n.Pos(), fmt.Sprintf("%s: %s", "all interface names with the -er suffix are required.", ii.Name))
r.Append(n.Pos(), fmt.Sprintf("%s: %s", msgc, ii.Name))
return
}
case *ast.Ident:
Expand Down
4 changes: 2 additions & 2 deletions analyzer/effective/ifacenames/testdata/src/a/a.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package a

type Query interface { // want "-er suffix"
type Query interface { // want "gostyle.ifacenames"
Do() error
}

type Closer interface { // want "-er suffix"
type Closer interface { // want "gostyle.ifacenames"
Do() error
}

Expand Down
6 changes: 3 additions & 3 deletions analyzer/effective/ifacenames/testdata/src/b/b.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package b

type Query interface { // want "-er suffix"
type Query interface { // want "gostyle.ifacenames"
Do() error
}

type Closer interface { // want "-er suffix"
type Closer interface { // want "gostyle.ifacenames"
Do() error
}

type Writer interface {
Write() error
}

type Add interface { // want "-er suffix"
type Add interface { // want "gostyle.ifacenames"
One() error
Two() error
}
Expand Down
10 changes: 5 additions & 5 deletions analyzer/guide/mixedcaps/testdata/src/a/a.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package a

const MAX_LENGTH = 10 // want "MixedCaps"
const MAX_LENGTH = 10 // want "gostyle.mixedcaps"

func f_a() { // want "MixedCaps"
var go_Pher int // want "MixedCaps"
print(go_Pher) // want "MixedCaps"
func f_a() { // want "gostyle.mixedcaps"
var go_Pher int // want "gostyle.mixedcaps"
print(go_Pher) // want "gostyle.mixedcaps"
}

type T_a struct { // want "MixedCaps"
type T_a struct { // want "gostyle.mixedcaps"
foo_bar int //nolint:all
}

Expand Down
3 changes: 2 additions & 1 deletion reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

const (
msgPrefix = "gostyle"
NoLintCommentAnnotation = "nolint:"
NoStyleCommentAnnotation = "nostyle:"
LintIgnore = "lint:ignore"
Expand Down Expand Up @@ -46,7 +47,7 @@ func (r *Reporter) Report() {
if r.IgnoreReport(report.Pos) {
continue
}
r.pass.Reportf(report.Pos, report.Msg)
r.pass.Reportf(report.Pos, fmt.Sprintf("[%s.%s] %s", msgPrefix, r.name, report.Msg))
}
}

Expand Down

0 comments on commit 5b26582

Please sign in to comment.