From e5a014e8c0169298087d70af07a8e91da1cb8dab Mon Sep 17 00:00:00 2001 From: Tom <73077675+tmzane@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:06:17 +0500 Subject: [PATCH 1/4] build(deps): bump go-simpler.org/sloglint from 0.5.1 to 0.6.0 --- .golangci.next.reference.yml | 8 ++++++++ .golangci.reference.yml | 8 ++++++++ go.mod | 2 +- go.sum | 2 ++ jsonschema/golangci.jsonschema.json | 6 ++++++ jsonschema/golangci.next.jsonschema.json | 6 ++++++ pkg/config/linters_settings.go | 7 +++++-- pkg/golinters/sloglint/sloglint.go | 7 +++++-- pkg/golinters/sloglint/testdata/sloglint_context_only.go | 2 +- pkg/golinters/sloglint/testdata/sloglint_context_only.yml | 2 +- 10 files changed, 43 insertions(+), 7 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 546270df4507..1005c6270329 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -2014,6 +2014,14 @@ linters-settings: # Default: "" no-global: "all" # Enforce using methods that accept a context. + # Values: + # - "": disabled + # - "all": report all contextless calls + # - "scope": report only if a context exists in the scope of the outermost function + # Default: "" + context: "all" + # Deprecated: use `context` instead. + # Enforce using methods that accept a context. # Default: false context-only: true # Enforce using static values for log messages. diff --git a/.golangci.reference.yml b/.golangci.reference.yml index c4e23bb0cbd6..dc48446c4d17 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -2013,6 +2013,14 @@ linters-settings: # Default: "" no-global: "all" # Enforce using methods that accept a context. + # Values: + # - "": disabled + # - "all": report all contextless calls + # - "scope": report only if a context exists in the scope of the outermost function + # Default: "" + context: "all" + # Deprecated: use `context` instead. + # Enforce using methods that accept a context. # Default: false context-only: true # Enforce using static values for log messages. diff --git a/go.mod b/go.mod index cc9f1863c6ca..a64d54dc6ec3 100644 --- a/go.mod +++ b/go.mod @@ -121,7 +121,7 @@ require ( github.com/ykadowak/zerologlint v0.1.5 gitlab.com/bosi/decorder v0.4.1 go-simpler.org/musttag v0.12.1 - go-simpler.org/sloglint v0.5.1 + go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89 go.uber.org/automaxprocs v1.5.3 golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc golang.org/x/tools v0.20.0 diff --git a/go.sum b/go.sum index fcce20d0ef88..561b44d081f2 100644 --- a/go.sum +++ b/go.sum @@ -594,6 +594,8 @@ go-simpler.org/musttag v0.12.1 h1:yaMcjl/uyVnd1z6GqIhBiFH/PoqNN9f2IgtU7bp7W/0= go-simpler.org/musttag v0.12.1/go.mod h1:46HKu04A3Am9Lne5kKP0ssgwY3AeIlqsDzz3UxKROpY= go-simpler.org/sloglint v0.5.1 h1:v4b9ave8MidsW28AkkRnF6Syg109zDgsYLiTlB5Ldew= go-simpler.org/sloglint v0.5.1/go.mod h1:+kJJtebtPePWyG5boFwY46COydAggADDOHM22zOvzBk= +go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89 h1:uk/IpjeYW+hRfTgBZIhTwS2a/HbswhCjkVcsDktEkPk= +go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89/go.mod h1:+kJJtebtPePWyG5boFwY46COydAggADDOHM22zOvzBk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/jsonschema/golangci.jsonschema.json b/jsonschema/golangci.jsonschema.json index 6e72616e8367..5d22917e657f 100644 --- a/jsonschema/golangci.jsonschema.json +++ b/jsonschema/golangci.jsonschema.json @@ -2275,10 +2275,16 @@ "default": true }, "context-only": { + "deprecated": true, "description": "Enforce using methods that accept a context.", "type": "boolean", "default": false }, + "context": { + "description": "Enforce using methods that accept a context.", + "enum": ["", "all", "scope"], + "default": "" + }, "static-msg": { "description": "Enforce using static values for log messages.", "type": "boolean", diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index ed1c51cf9a81..851ffbc238bb 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -2290,10 +2290,16 @@ "default": true }, "context-only": { + "deprecated": true, "description": "Enforce using methods that accept a context.", "type": "boolean", "default": false }, + "context": { + "description": "Enforce using methods that accept a context.", + "enum": ["", "all", "scope"], + "default": "" + }, "static-msg": { "description": "Enforce using static values for log messages.", "type": "boolean", diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index b368f4f281c0..eccf368b0c2f 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -144,6 +144,8 @@ var defaultLintersSettings = LintersSettings{ NoMixedArgs: true, KVOnly: false, AttrOnly: false, + NoGlobal: "", + Context: "", ContextOnly: false, StaticMsg: false, NoRawKeys: false, @@ -810,9 +812,10 @@ type RowsErrCheckSettings struct { type SlogLintSettings struct { NoMixedArgs bool `mapstructure:"no-mixed-args"` KVOnly bool `mapstructure:"kv-only"` - NoGlobal string `mapstructure:"no-global"` AttrOnly bool `mapstructure:"attr-only"` - ContextOnly bool `mapstructure:"context-only"` + NoGlobal string `mapstructure:"no-global"` + Context string `mapstructure:"context"` + ContextOnly bool `mapstructure:"context-only"` // Deprecated: use Context instead. StaticMsg bool `mapstructure:"static-msg"` NoRawKeys bool `mapstructure:"no-raw-keys"` KeyNamingCase string `mapstructure:"key-naming-case"` diff --git a/pkg/golinters/sloglint/sloglint.go b/pkg/golinters/sloglint/sloglint.go index be7d45180611..c4ae9ee4367d 100644 --- a/pkg/golinters/sloglint/sloglint.go +++ b/pkg/golinters/sloglint/sloglint.go @@ -14,14 +14,17 @@ func New(settings *config.SlogLintSettings) *goanalysis.Linter { opts = &sloglint.Options{ NoMixedArgs: settings.NoMixedArgs, KVOnly: settings.KVOnly, - NoGlobal: settings.NoGlobal, AttrOnly: settings.AttrOnly, - ContextOnly: settings.ContextOnly, + NoGlobal: settings.NoGlobal, + ContextOnly: settings.Context, StaticMsg: settings.StaticMsg, NoRawKeys: settings.NoRawKeys, KeyNamingCase: settings.KeyNamingCase, ArgsOnSepLines: settings.ArgsOnSepLines, } + if settings.ContextOnly && settings.Context == "" { + opts.ContextOnly = "all" + } } a := sloglint.New(opts) diff --git a/pkg/golinters/sloglint/testdata/sloglint_context_only.go b/pkg/golinters/sloglint/testdata/sloglint_context_only.go index a257a5168c1f..4eca68e151fb 100644 --- a/pkg/golinters/sloglint/testdata/sloglint_context_only.go +++ b/pkg/golinters/sloglint/testdata/sloglint_context_only.go @@ -12,5 +12,5 @@ import ( func test() { slog.InfoContext(context.Background(), "msg") - slog.Info("msg") // want `methods without a context should not be used` + slog.Info("msg") // want `InfoContext should be used instead` } diff --git a/pkg/golinters/sloglint/testdata/sloglint_context_only.yml b/pkg/golinters/sloglint/testdata/sloglint_context_only.yml index a15bbe49680a..2b0703cef2ab 100644 --- a/pkg/golinters/sloglint/testdata/sloglint_context_only.yml +++ b/pkg/golinters/sloglint/testdata/sloglint_context_only.yml @@ -1,3 +1,3 @@ linters-settings: sloglint: - context-only: true + context: "all" From 1b8e25fd567c1d2e9f88351015e9a2e728c44071 Mon Sep 17 00:00:00 2001 From: Tom <73077675+tmzane@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:14:53 +0500 Subject: [PATCH 2/4] chore: update go.sum --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 561b44d081f2..348295b0a458 100644 --- a/go.sum +++ b/go.sum @@ -592,8 +592,6 @@ go-simpler.org/assert v0.7.0 h1:OzWWZqfNxt8cLS+MlUp6Tgk1HjPkmgdKBq9qvy8lZsA= go-simpler.org/assert v0.7.0/go.mod h1:74Eqh5eI6vCK6Y5l3PI8ZYFXG4Sa+tkr70OIPJAUr28= go-simpler.org/musttag v0.12.1 h1:yaMcjl/uyVnd1z6GqIhBiFH/PoqNN9f2IgtU7bp7W/0= go-simpler.org/musttag v0.12.1/go.mod h1:46HKu04A3Am9Lne5kKP0ssgwY3AeIlqsDzz3UxKROpY= -go-simpler.org/sloglint v0.5.1 h1:v4b9ave8MidsW28AkkRnF6Syg109zDgsYLiTlB5Ldew= -go-simpler.org/sloglint v0.5.1/go.mod h1:+kJJtebtPePWyG5boFwY46COydAggADDOHM22zOvzBk= go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89 h1:uk/IpjeYW+hRfTgBZIhTwS2a/HbswhCjkVcsDktEkPk= go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89/go.mod h1:+kJJtebtPePWyG5boFwY46COydAggADDOHM22zOvzBk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= From b57fbd96ed6a755e0c15a5651471f5c9661b0ab5 Mon Sep 17 00:00:00 2001 From: Tom <73077675+tmzane@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:58:22 +0500 Subject: [PATCH 3/4] address review comments --- .golangci.next.reference.yml | 4 ---- .golangci.reference.yml | 8 -------- jsonschema/golangci.jsonschema.json | 6 ------ jsonschema/golangci.next.jsonschema.json | 6 ------ pkg/config/loader.go | 8 ++++++++ pkg/golinters/sloglint/sloglint.go | 3 --- 6 files changed, 8 insertions(+), 27 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 1005c6270329..860e4fc28779 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -2020,10 +2020,6 @@ linters-settings: # - "scope": report only if a context exists in the scope of the outermost function # Default: "" context: "all" - # Deprecated: use `context` instead. - # Enforce using methods that accept a context. - # Default: false - context-only: true # Enforce using static values for log messages. # Default: false static-msg: true diff --git a/.golangci.reference.yml b/.golangci.reference.yml index dc48446c4d17..c4e23bb0cbd6 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -2013,14 +2013,6 @@ linters-settings: # Default: "" no-global: "all" # Enforce using methods that accept a context. - # Values: - # - "": disabled - # - "all": report all contextless calls - # - "scope": report only if a context exists in the scope of the outermost function - # Default: "" - context: "all" - # Deprecated: use `context` instead. - # Enforce using methods that accept a context. # Default: false context-only: true # Enforce using static values for log messages. diff --git a/jsonschema/golangci.jsonschema.json b/jsonschema/golangci.jsonschema.json index 5d22917e657f..6e72616e8367 100644 --- a/jsonschema/golangci.jsonschema.json +++ b/jsonschema/golangci.jsonschema.json @@ -2275,16 +2275,10 @@ "default": true }, "context-only": { - "deprecated": true, "description": "Enforce using methods that accept a context.", "type": "boolean", "default": false }, - "context": { - "description": "Enforce using methods that accept a context.", - "enum": ["", "all", "scope"], - "default": "" - }, "static-msg": { "description": "Enforce using static values for log messages.", "type": "boolean", diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 851ffbc238bb..2d2673b8bded 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -2289,12 +2289,6 @@ "type": "boolean", "default": true }, - "context-only": { - "deprecated": true, - "description": "Enforce using methods that accept a context.", - "type": "boolean", - "default": false - }, "context": { "description": "Enforce using methods that accept a context.", "enum": ["", "all", "scope"], diff --git a/pkg/config/loader.go b/pkg/config/loader.go index eb5044a70b3e..57ec4d4ee811 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -408,6 +408,14 @@ func (l *Loader) handleLinterOptionDeprecations() { if l.cfg.LintersSettings.Stylecheck.GoVersion != "" { l.log.Warnf("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`.") } + + // Deprecated since v1.58.0 + if l.cfg.LintersSettings.SlogLint.ContextOnly { + l.log.Warnf("The configuration option `linters.sloglint.context-only` is deprecated, please use `linters.sloglint.context`") + if l.cfg.LintersSettings.SlogLint.Context == "" { + l.cfg.LintersSettings.SlogLint.Context = "all" + } + } } func (l *Loader) handleEnableOnlyOption() error { diff --git a/pkg/golinters/sloglint/sloglint.go b/pkg/golinters/sloglint/sloglint.go index c4ae9ee4367d..d3f567e9c7f7 100644 --- a/pkg/golinters/sloglint/sloglint.go +++ b/pkg/golinters/sloglint/sloglint.go @@ -22,9 +22,6 @@ func New(settings *config.SlogLintSettings) *goanalysis.Linter { KeyNamingCase: settings.KeyNamingCase, ArgsOnSepLines: settings.ArgsOnSepLines, } - if settings.ContextOnly && settings.Context == "" { - opts.ContextOnly = "all" - } } a := sloglint.New(opts) From 0a8aaadbdca3c486caeb35950dad4558445d18b1 Mon Sep 17 00:00:00 2001 From: Tom <73077675+tmzane@users.noreply.github.com> Date: Sat, 20 Apr 2024 21:53:22 +0500 Subject: [PATCH 4/4] bump version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a64d54dc6ec3..72ed95cb2c2c 100644 --- a/go.mod +++ b/go.mod @@ -121,7 +121,7 @@ require ( github.com/ykadowak/zerologlint v0.1.5 gitlab.com/bosi/decorder v0.4.1 go-simpler.org/musttag v0.12.1 - go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89 + go-simpler.org/sloglint v0.6.0 go.uber.org/automaxprocs v1.5.3 golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc golang.org/x/tools v0.20.0 diff --git a/go.sum b/go.sum index 348295b0a458..2242a7d0cfcd 100644 --- a/go.sum +++ b/go.sum @@ -592,8 +592,8 @@ go-simpler.org/assert v0.7.0 h1:OzWWZqfNxt8cLS+MlUp6Tgk1HjPkmgdKBq9qvy8lZsA= go-simpler.org/assert v0.7.0/go.mod h1:74Eqh5eI6vCK6Y5l3PI8ZYFXG4Sa+tkr70OIPJAUr28= go-simpler.org/musttag v0.12.1 h1:yaMcjl/uyVnd1z6GqIhBiFH/PoqNN9f2IgtU7bp7W/0= go-simpler.org/musttag v0.12.1/go.mod h1:46HKu04A3Am9Lne5kKP0ssgwY3AeIlqsDzz3UxKROpY= -go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89 h1:uk/IpjeYW+hRfTgBZIhTwS2a/HbswhCjkVcsDktEkPk= -go-simpler.org/sloglint v0.5.2-0.20240415120200-0f71de074b89/go.mod h1:+kJJtebtPePWyG5boFwY46COydAggADDOHM22zOvzBk= +go-simpler.org/sloglint v0.6.0 h1:0YcqSVG7LI9EVBfRPhgPec79BH6X6mwjFuUR5Mr7j1M= +go-simpler.org/sloglint v0.6.0/go.mod h1:+kJJtebtPePWyG5boFwY46COydAggADDOHM22zOvzBk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=