Skip to content

Commit b472b7a

Browse files
committed
add golangci-lint errcheck warning
we were getting this warning: ``` WARN [config_reader] The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`. ``` so removing .errcheck.txt and adding the functions to the .golangci.yml add a comment to the go code to explain what the function does and launch golangci-lint to make sure it's all good. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent fca09b0 commit b472b7a

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

.errcheck.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

.golangci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ linters-settings:
1515
disabled-checks:
1616
- unlambda
1717
errcheck:
18-
exclude: .errcheck.txt
18+
exclude-functions:
19+
- (*github.com/tektoncd/pipeline/vendor/go.uber.org/zap.SugaredLogger).Sync
20+
- flag.Set
21+
- logger.Sync
22+
- fmt.Fprintf
23+
- fmt.Fprintln
24+
- (io.Closer).Close
25+
- updateConfigMap
1926
gofumpt:
2027
extra-rules: true
2128
linters:

pkg/templates/templating.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,33 @@ var (
2121
mapType = reflect.TypeOf(&structpb.Struct{})
2222
)
2323

24-
// ReplacePlaceHoldersVariables Replace those {{var}} placeholders to the runinfo variable.
24+
// ReplacePlaceHoldersVariables is a function that replaces placeholders in a
25+
// given string template with their corresponding values. The placeholders are
26+
// expected to be in the format `{{key}}`, where `key` is the identifier for a
27+
// value.
28+
//
29+
// The function first checks if the key in the placeholder has a prefix of
30+
// "body", "headers", or "files". If it does and both `rawEvent` and `headers`
31+
// are not nil, it attempts to retrieve the value for the key using the
32+
// `customparams.CelValue` function and returns the corresponding string
33+
// representation. If the key does not have any of the mentioned prefixes, the
34+
// function checks if the key exists in the `dico` map. If it does, the
35+
// function replaces the placeholder with the corresponding value from the
36+
// `dico` map.
37+
//
38+
// Parameters:
39+
// - template (string): The input string that may contain placeholders in the
40+
// format `{{key}}`.
41+
// - dico (map[string]string): A dictionary mapping keys to their corresponding
42+
// string values. If a placeholder's key is found in this dictionary, it will
43+
// be replaced with the corresponding value.
44+
// - rawEvent (any): The raw event data that may be used to retrieve values for
45+
// placeholders with keys that have a prefix of "body", "headers", or "files".
46+
// - headers (http.Header): The HTTP headers that may be used to retrieve
47+
// values for placeholders with keys that have a prefix of "headers".
48+
// - changedFiles (map[string]interface{}): A map of changed files that may be
49+
// used to retrieve values for placeholders with keys that have a prefix of
50+
// "files".
2551
func ReplacePlaceHoldersVariables(template string, dico map[string]string, rawEvent any, headers http.Header, changedFiles map[string]interface{}) string {
2652
return keys.ParamsRe.ReplaceAllStringFunc(template, func(s string) string {
2753
parts := keys.ParamsRe.FindStringSubmatch(s)

0 commit comments

Comments
 (0)