Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tools/golangci-lint/gitaly/testdata')
-rw-r--r--tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_alias_test.go32
-rw-r--r--tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_test.go37
-rw-r--r--tools/golangci-lint/gitaly/testdata/src/quote/quote_test.go27
3 files changed, 96 insertions, 0 deletions
diff --git a/tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_alias_test.go b/tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_alias_test.go
new file mode 100644
index 000000000..d3e0aba27
--- /dev/null
+++ b/tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_alias_test.go
@@ -0,0 +1,32 @@
+package errorwrap
+
+import (
+ f "fmt"
+)
+
+// This file is the test fixture for Gitaly linters
+
+func errorWrapAliasOkay() {
+ err := f.Errorf("test error")
+
+ _ = f.Errorf("error: %s", "something else")
+ _ = f.Errorf("error: %v", "something else")
+ _ = f.Errorf("error: %q", "something else")
+ _ = f.Errorf("error: %s %d", "something else", 5)
+ _ = f.Errorf("error: %w", err)
+ _ = f.Errorf("error: %w", f.Errorf("error: %s", "hello"))
+}
+
+func errorWrapAliasNotOkay() {
+ err := f.Errorf("test error")
+
+ _ = f.Errorf("error: %s", err) // want "please use %w to wrap errors"
+ _ = f.Errorf("error: %s", f.Errorf("test error")) // want "please use %w to wrap errors"
+ _ = f.Errorf("error: %v", err) // want "please use %w to wrap errors"
+ _ = f.Errorf("error: %v", f.Errorf("test error")) // want "please use %w to wrap errors"
+ _ = f.Errorf("error: %q", err) // want "please use %w to wrap errors"
+ _ = f.Errorf("error: %q", f.Errorf("test error")) // want "please use %w to wrap errors"
+ _ = f.Errorf("error number %d: %s", 5, err) // want "please use %w to wrap errors"
+ _ = f.Errorf("error: %w", err)
+ _ = f.Errorf("error: %w", f.Errorf("error: %s", err)) // want "please use %w to wrap errors"
+}
diff --git a/tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_test.go b/tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_test.go
new file mode 100644
index 000000000..5f6764e63
--- /dev/null
+++ b/tools/golangci-lint/gitaly/testdata/src/errorwrap/errorwrap_test.go
@@ -0,0 +1,37 @@
+package errorwrap
+
+import (
+ "fmt"
+)
+
+// This file is the test fixture for Gitaly linters
+
+func call(format string, err error) {}
+
+func errorWrapOkay() {
+ err := fmt.Errorf("test error")
+
+ _ = fmt.Errorf("error: %s", "something else")
+ _ = fmt.Errorf("error: %v", "something else")
+ _ = fmt.Errorf("error: %q", "something else")
+ _ = fmt.Errorf("error: %s %d", "something else", 5)
+ _ = fmt.Errorf("error: %w", err)
+ _ = fmt.Errorf("error: %w", fmt.Errorf("error: %s", "hello"))
+
+ call("error: %w", fmt.Errorf("error: %s", "hello"))
+ _ = fmt.Sprintf("error: %s", err)
+}
+
+func errorWrapNotOkay() {
+ err := fmt.Errorf("test error")
+
+ _ = fmt.Errorf("error: %s", err) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error: %s", fmt.Errorf("test error")) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error: %v", err) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error: %v", fmt.Errorf("test error")) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error: %q", err) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error: %q", fmt.Errorf("test error")) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error number %d: %s", 5, err) // want "please use %w to wrap errors"
+ _ = fmt.Errorf("error: %w", err)
+ _ = fmt.Errorf("error: %w", fmt.Errorf("error: %s", err)) // want "please use %w to wrap errors"
+}
diff --git a/tools/golangci-lint/gitaly/testdata/src/quote/quote_test.go b/tools/golangci-lint/gitaly/testdata/src/quote/quote_test.go
new file mode 100644
index 000000000..d0e832c59
--- /dev/null
+++ b/tools/golangci-lint/gitaly/testdata/src/quote/quote_test.go
@@ -0,0 +1,27 @@
+package quote
+
+import "fmt"
+
+// This file is the test fixture for Gitaly linters
+
+func quoteOkay() {
+ fmt.Printf("hello world: %q", "today is a good day")
+ fmt.Printf("hello world: %d", 123)
+ fmt.Printf("%s something", "hello")
+ fmt.Printf("hello world: %s", "this is good")
+ fmt.Printf("hello world: %s something", "this is good")
+}
+
+func quoteNotOkay() {
+ fmt.Printf("hello world: '%s'", "today is a good day") // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+ fmt.Printf(`hello world: "%s"`, "today is a good day") // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+ fmt.Printf(`hello world: "%s"`, "today is a good day") // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+ str := `so is
+tomorrow`
+ fmt.Printf("hello world: '%s'", str) // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+ fmt.Printf(`hello world: "%s"`, str) // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+ fmt.Printf(`hello world: "%s"`, str) // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+
+ fmt.Printf("hello world:%s %s '%s'", "today", "is a", "good day") // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+ fmt.Printf("hello world: %d '%s'", 123, "today is a good day") // want "wrapping %s verb with quotes is not encouraged, please use %q instead"
+}