aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-linter/testdata
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-02 18:38:27 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-04 15:05:30 +0200
commitc992206a1d8b6e537fe1782d025c25ea77bce06d (patch)
tree724ed6ceb179555b56bf63afb4a82eca7c948f25 /tools/syz-linter/testdata
parentfcb219b67eb296b6781f81074e9cb5b09163f734 (diff)
tools/syz-linter: add custom linter
For now we have 2 simple checks: 1. for multiline comments: /* */ -> // 2. for string len comparison with 0: len(str) != 0 -> str != "" Update #1876
Diffstat (limited to 'tools/syz-linter/testdata')
-rw-r--r--tools/syz-linter/testdata/src/lintertest/lintertest.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/syz-linter/testdata/src/lintertest/lintertest.go b/tools/syz-linter/testdata/src/lintertest/lintertest.go
new file mode 100644
index 000000000..b507bc1ee
--- /dev/null
+++ b/tools/syz-linter/testdata/src/lintertest/lintertest.go
@@ -0,0 +1,19 @@
+// Copyright 2020 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package lintertest
+
+/* some comment */ // want "Use C-style comments // instead of /* */"
+var comment = 1 /* some comment */ // want "Use C-style comments // instead of /* */"
+
+func stringComparison() {
+ str := ""
+ if len(str) == 0 { // want "Compare string with \"\", don't compare len with 0"
+ }
+ if 0 != len(str) { // want "Compare string with \"\", don't compare len with 0"
+ }
+ if len(returnString()+"foo") > 0 { // want "Compare string with \"\", don't compare len with 0"
+ }
+}
+
+func returnString() string { return "foo" }