Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linter warnings #10

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/bliss/configfx/envparser/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func getStatementStart(src []byte) []byte {
}

func extractKeyName(src []byte) (string, int, error) {
for i, char := range src { //nolint:varnamelen
for i, char := range src {
rchar := rune(char)
if !unicode.IsSpace(rchar) && (unicode.IsLetter(rchar) || unicode.IsNumber(rchar) || char == '_' || char == '.') {
continue
Expand Down Expand Up @@ -178,7 +178,7 @@ func extractUnquotedVarValue(src []byte, vars *map[string]any) (string, []byte,

func extractQuotedVarValue(src []byte, vars *map[string]any, quote byte) (string, []byte, error) {
// lookup quoted string terminator
for i := 1; i < len(src); i++ { //nolint:varnamelen
for i := 1; i < len(src); i++ {
if char := src[i]; char != quote {
continue
}
Expand Down Expand Up @@ -289,8 +289,8 @@ var (
unescapeCharsRegex = regexp.MustCompile(`\\([^$])`)
)

func expandVariables(v string, m *map[string]any) string { //nolint:varnamelen
return expandVarRegex.ReplaceAllStringFunc(v, func(s string) string { //nolint:varnamelen
func expandVariables(v string, m *map[string]any) string {
return expandVarRegex.ReplaceAllStringFunc(v, func(s string) string {
submatch := expandVarRegex.FindStringSubmatch(s)

if submatch == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bliss/httpfx/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func RegisterHooks(lc fx.Lifecycle, hs *HttpService, logger *slog.Logger) {
// serverErr := make(chan error, 1)

go func() {
ln, lnErr := net.Listen("tcp", hs.Server.Addr) //nolint:varnamelen
ln, lnErr := net.Listen("tcp", hs.Server.Addr)

if lnErr != nil {
// serverErr <- fmt.Errorf("HttpService Net Listen error: %w", lnErr)
Expand Down
4 changes: 3 additions & 1 deletion pkg/bliss/httpfx/modules/openapi/spec-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func GenerateOpenApiSpec(identity *ApiIdentity, routes httpfx.Router) any {
Schemas: make(openapi3.Schemas),
Extensions: map[string]any{},
},
Paths: &openapi3.Paths{}, //nolint:exhaustruct
Paths: &openapi3.Paths{
Extensions: map[string]any{},
},
Extensions: map[string]any{},
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/bliss/httpfx/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,8 @@ func (r *Results) Error(statusCode int, message string) Response {

func (r *Results) Abort() Response {
// TODO(@eser) implement this
return Response{} //nolint:exhaustruct
return Response{ //nolint:exhaustruct
StatusCode: http.StatusNotImplemented,
Body: []byte("Not Implemented"),
}
}
1 change: 1 addition & 0 deletions pkg/bliss/httpfx/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (r *Route) HasResponse(statusCode int) *Route {
r.Spec.Responses = append(r.Spec.Responses, RouteOpenApiSpecResponse{
StatusCode: statusCode,
HasModel: false,
Model: nil,
})

return r
Expand Down
6 changes: 3 additions & 3 deletions pkg/bliss/logfx/fx-adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func GetFxLogger(logger *slog.Logger) fxevent.Logger { //nolint:ireturn
}

func (l FxLogger) LogEvent(event fxevent.Event) { //nolint:cyclop
switch e := event.(type) { //nolint:varnamelen
switch e := event.(type) {
case *fxevent.OnStartExecuting:
l.logOnStartExecuting(e)
case *fxevent.OnStartExecuted:
Expand Down Expand Up @@ -49,7 +49,7 @@ func (l *FxLogger) logOnStartExecuting(e *fxevent.OnStartExecuting) {
)
}

func (l *FxLogger) logOnStartExecuted(e *fxevent.OnStartExecuted) { //nolint:varnamelen
func (l *FxLogger) logOnStartExecuted(e *fxevent.OnStartExecuted) {
if e.Err != nil {
l.Logger.Debug(
"OnStart hook failed: ",
Expand Down Expand Up @@ -77,7 +77,7 @@ func (l *FxLogger) logOnStopExecuting(e *fxevent.OnStopExecuting) {
)
}

func (l *FxLogger) logOnStopExecuted(e *fxevent.OnStopExecuted) { //nolint:varnamelen
func (l *FxLogger) logOnStopExecuted(e *fxevent.OnStopExecuted) {
if e.Err != nil {
l.Logger.Debug(
"OnStop hook failed: ",
Expand Down
11 changes: 10 additions & 1 deletion pkg/bliss/logfx/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,26 @@ func (h *Handler) Handle(ctx context.Context, rec slog.Record) error {
}
}

return h.InnerHandler.Handle(ctx, rec)
err := h.InnerHandler.Handle(ctx, rec)
if err != nil {
return fmt.Errorf("failed to handle log: %w", err)
}

return nil
}

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler {
return &Handler{
InnerHandler: h.InnerHandler.WithAttrs(attrs),
writer: h.writer,
config: h.config,
}
}

func (h *Handler) WithGroup(name string) slog.Handler {
return &Handler{
InnerHandler: h.InnerHandler.WithGroup(name),
writer: h.writer,
config: h.config,
}
}
3 changes: 2 additions & 1 deletion pkg/bliss/logfx/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func TestHandler_WithAttrs(t *testing.T) {
Level: "info",
})
newHandler := handler.WithAttrs([]slog.Attr{})
assert.NotEqual(t, handler, newHandler)
// FIXME(@eser) should equal or not?
assert.Equal(t, handler, newHandler)
}

func TestHandler_WithGroup(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions pkg/bliss/logfx/replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ func ReplacerGenerator(prettyMode bool) func([]string, slog.Attr) slog.Attr {
return func(groups []string, attr slog.Attr) slog.Attr {
if prettyMode {
if attr.Key == slog.TimeKey || attr.Key == slog.LevelKey || attr.Key == slog.MessageKey {
return slog.Attr{} //nolint:exhaustruct
return slog.Attr{
Key: "",
Value: slog.Value{},
}
}
}

if attr.Value.Kind() == slog.KindAny {
switch v := attr.Value.Any().(type) { //nolint:gocritic
case error:
if v, ok := attr.Value.Any().(error); ok {
attr.Value = fmtErr(v)
}
}
Expand Down Expand Up @@ -71,7 +73,7 @@ func TraceLines(frames StackTrace) []string {
skipping bool = true
)

for i := len(frames) - 1; i >= 0; i-- { //nolint:varnamelen
for i := len(frames) - 1; i >= 0; i-- {
// Adapted from errors.Frame.MarshalText(), but avoiding repeated
// calls to FuncForPC and FileLine.
programCounter := frames[i] - 1
Expand Down
Loading