Repository: fsnotify/fsnotify
Pull request #687 (2025-04-01 08:06:36)

Fix staticcheck in CI
Looks like it wasn't really being run? Guess I didn't use that -matrix correctly? Just use a simple shell script.

Also run go vet.


Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
deleted file mode 100644
index bc2ca95..0000000
--- a/.github/workflows/build.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-name: 'build'
-on:
-  pull_request:
-    paths: ['**.go', 'go.mod', '.github/workflows/*']
-  push:
-    branches: ['main', 'aix']
-
-jobs:
-  cross-compile:
-    strategy:
-      fail-fast: false
-      matrix:
-        go: ['1.17', '1.24']
-    runs-on: 'ubuntu-latest'
-    steps:
-      - uses: 'actions/checkout@v4'
-
-      - uses: 'actions/setup-go@v5'
-        with:
-          go-version: ${{ matrix.go }}
-
-      - name: build
-        run: |
-          for a in $(go tool dist list); do
-            export GOOS=${a%%/*}
-            export GOARCH=${a#*/}
-
-            case "$GOOS" in
-              (android|ios)  exit 0 ;; # Requires cgo to link.
-              (js)           exit 0 ;; # No build tags in internal/ TODO: should maybe fix?
-              (openbsd)
-                case "$GOARCH" in
-                  # Fails with:
-                  #   golang.org/x/sys/unix.syscall_syscall9: relocation target syscall.syscall10 not defined
-                  #   golang.org/x/sys/unix.kevent: relocation target syscall.syscall6 not defined
-                  #   golang.org/x/sys/unix.pipe2: relocation target syscall.rawSyscall not defined
-                  #   ...
-                  # Works for me locally though, hmm...
-                  (386) exit 0 ;;
-                esac
-            esac
-
-            go test -c
-            go build ./cmd/fsnotify
-          done
diff --git a/.github/workflows/staticcheck.yml b/.github/workflows/staticcheck.yml
index 5a998ba..55126cd 100644
--- a/.github/workflows/staticcheck.yml
+++ b/.github/workflows/staticcheck.yml
@@ -3,17 +3,28 @@ on:
   pull_request:
     paths: ['**.go', 'go.mod', '.github/workflows/*']
   push:
-    branches: ['main', 'aix']
+    branches: ['main']
 
 jobs:
   staticcheck:
     name:    'staticcheck'
     runs-on: 'ubuntu-latest'
+    env:     {cache: 'staticcheck-${{ github.ref }}'}
     steps:
-      - uses: 'actions/setup-go@v5'
+      # Setup
+      - uses: 'actions/checkout@v4'
+      - id:   'cache-restore'
+        uses: 'actions/cache/restore@v4'
         with:
-          go-version: '1.24'
-
+          key: '${{ env.cache }}'
+          path: |
+            ${{ runner.temp }}/staticcheck
+            /home/runner/.cache/go-build
+          restore-keys: |
+            staticcheck-${{ github.ref }}
+            staticcheck-refs/heads/main
+      - uses: 'actions/setup-go@v5'
+        with: {go-version: '1.24'}
       - uses: 'actions/cache@v4'
         with:
           key: '${{ runner.os }}-staticcheck'
@@ -21,16 +32,39 @@ jobs:
             ${{ runner.temp }}/staticcheck
             ${{ steps.install_go.outputs.GOCACHE || '' }}
 
+      # Run
       - run: |
           export STATICCHECK_CACHE="${{ runner.temp }}/staticcheck"
           go install honnef.co/go/tools/cmd/staticcheck@latest
 
-          $(go env GOPATH)/bin/staticcheck -matrix <<EOF
-          windows: GOOS=windows
-          linux: GOOS=linux
-          freebsd: GOOS=freebsd
-          openbsd: GOOS=openbsd
-          netbsd: GOOS=netbsd
-          darwin: GOOS=darwin
-          illumos: GOOS=illumos
-          EOF
+          fail=0
+          for a in $(go tool dist list); do
+            export GOOS=${a%%/*}
+            export GOARCH=${a#*/}
+
+            case "$GOOS" in
+              (android|ios)  continue ;; # Requires cgo to link.
+              (js|wasip1)    continue ;; # No build tags in internal/ TODO: should maybe fix?
+              (plan9)        continue ;; # Errors out on some missing definitions like syscall.Errno.
+            esac
+
+            echo $a
+            go vet ./... || fail=1
+            staticcheck ./... || fail=1
+          done
+          exit $fail
+
+      # Store cache
+      - name: 'delete existing cache'
+        if:   '${{ steps.cache-restore.outputs.cache-hit }}'
+        env:  {GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'}
+        continue-on-error: true
+        run: |
+          gh extension install actions/gh-actions-cache
+          gh actions-cache delete "${{ env.cache }}" --confirm
+      - uses: 'actions/cache/save@v4'
+        with:
+          key: '${{ env.cache }}'
+          path: |
+            ${{ runner.temp }}/staticcheck
+            /home/runner/.cache/go-build
diff --git a/backend_inotify.go b/backend_inotify.go
index e36d2d5..a36cb89 100644
--- a/backend_inotify.go
+++ b/backend_inotify.go
@@ -100,7 +100,7 @@ func (w *watches) removePath(path string) ([]uint32, error) {
 	wds := make([]uint32, 0, 8)
 	wds = append(wds, wd)
 	for p, rwd := range w.path {
-		if filepath.HasPrefix(p, path) {
+		if strings.HasPrefix(p, path) {
 			delete(w.path, p)
 			delete(w.wd, rwd)
 			wds = append(wds, rwd)
diff --git a/backend_kqueue.go b/backend_kqueue.go
index 2d48be9..340aeec 100644
--- a/backend_kqueue.go
+++ b/backend_kqueue.go
@@ -694,9 +694,9 @@ func (w *kqueue) read(events []unix.Kevent_t) ([]unix.Kevent_t, error) {
 }
 
 func (w *kqueue) xSupports(op Op) bool {
-	if runtime.GOOS == "freebsd" {
-		//return true // Supports everything.
-	}
+	//if runtime.GOOS == "freebsd" {
+	//	return true // Supports everything.
+	//}
 	if op.Has(xUnportableOpen) || op.Has(xUnportableRead) ||
 		op.Has(xUnportableCloseWrite) || op.Has(xUnportableCloseRead) {
 		return false
diff --git a/fsnotify.go b/fsnotify.go
index bc80032..d53eaa9 100644
--- a/fsnotify.go
+++ b/fsnotify.go
@@ -244,6 +244,7 @@ var (
 
 	// ErrUnsupported is returned by AddWith() when WithOps() specified an
 	// Unportable event that's not supported on this platform.
+	//lint:ignore ST1012 not relevant
 	xErrUnsupported = errors.New("fsnotify: not supported with this backend")
 )
 
diff --git a/internal/darwin.go b/internal/darwin.go
index b0eab10..0b01bc1 100644
--- a/internal/darwin.go
+++ b/internal/darwin.go
@@ -9,14 +9,14 @@ import (
 )
 
 var (
-	SyscallEACCES = syscall.EACCES
-	UnixEACCES    = unix.EACCES
+	ErrSyscallEACCES = syscall.EACCES
+	ErrUnixEACCES    = unix.EACCES
 )
 
 var maxfiles uint64
 
-// Go 1.19 will do this automatically: https://go-review.googlesource.com/c/go/+/393354/
 func SetRlimit() {
+	// Go 1.19 will do this automatically: https://go-review.googlesource.com/c/go/+/393354/
 	var l syscall.Rlimit
 	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &l)
 	if err == nil && l.Cur != l.Max {
diff --git a/internal/freebsd.go b/internal/freebsd.go
index 547df1d..5ac8b50 100644
--- a/internal/freebsd.go
+++ b/internal/freebsd.go
@@ -9,8 +9,8 @@ import (
 )
 
 var (
-	SyscallEACCES = syscall.EACCES
-	UnixEACCES    = unix.EACCES
+	ErrSyscallEACCES = syscall.EACCES
+	ErrUnixEACCES    = unix.EACCES
 )
 
 var maxfiles uint64
diff --git a/internal/unix.go b/internal/unix.go
index 30976ce..b251fb8 100644
--- a/internal/unix.go
+++ b/internal/unix.go
@@ -1,4 +1,4 @@
-//go:build !windows && !darwin && !freebsd
+//go:build !windows && !darwin && !freebsd && !plan9
 
 package internal
 
@@ -9,8 +9,8 @@ import (
 )
 
 var (
-	SyscallEACCES = syscall.EACCES
-	UnixEACCES    = unix.EACCES
+	ErrSyscallEACCES = syscall.EACCES
+	ErrUnixEACCES    = unix.EACCES
 )
 
 var maxfiles uint64
diff --git a/internal/windows.go b/internal/windows.go
index a72c649..896bc2e 100644
--- a/internal/windows.go
+++ b/internal/windows.go
@@ -10,8 +10,8 @@ import (
 
 // Just a dummy.
 var (
-	SyscallEACCES = errors.New("dummy")
-	UnixEACCES    = errors.New("dummy")
+	ErrSyscallEACCES = errors.New("dummy")
+	ErrUnixEACCES    = errors.New("dummy")
 )
 
 func SetRlimit()                                    {}
diff --git a/staticcheck.conf b/staticcheck.conf
new file mode 100644
index 0000000..8fa7351
--- /dev/null
+++ b/staticcheck.conf
@@ -0,0 +1,3 @@
+checks = ['all',
+	'-U1000',  # Don't complain about unused functions.
+]


Test patch:
diff --git a/backend_windows_test.go b/backend_windows_test.go
index 850f40c..6364f43 100644
--- a/backend_windows_test.go
+++ b/backend_windows_test.go
@@ -10,7 +10,7 @@ import (
 
 func TestRemoveState(t *testing.T) {
 	// TODO: the Windows backend is too confusing; needs some serious attention.
-	return
+	t.Skip("broken test")
 
 	var (
 		tmp  = t.TempDir()
diff --git a/fsnotify_test.go b/fsnotify_test.go
index b5d0bb0..9f4599a 100644
--- a/fsnotify_test.go
+++ b/fsnotify_test.go
@@ -442,10 +442,10 @@ func TestAdd(t *testing.T) {
 		if err == nil {
 			t.Fatal("error is nil")
 		}
-		if !errors.Is(err, internal.UnixEACCES) {
+		if !errors.Is(err, internal.ErrUnixEACCES) {
 			t.Errorf("not unix.EACCESS: %T %#[1]v", err)
 		}
-		if !errors.Is(err, internal.SyscallEACCES) {
+		if !errors.Is(err, internal.ErrSyscallEACCES) {
 			t.Errorf("not syscall.EACCESS: %T %#[1]v", err)
 		}
 	})
diff --git a/internal/ztest/diff.go b/internal/ztest/diff.go
index ab7bfa7..f635d6a 100644
--- a/internal/ztest/diff.go
+++ b/internal/ztest/diff.go
@@ -1,7 +1,3 @@
-// Copy of https://github.com/arp242/zstd/tree/master/ztest – vendored here so
-// we don't add a dependency for just one file used in tests. DiffXML was
-// removed as it depends on zgo.at/zstd/zxml.
-
 // This code is based on https://github.com/pmezard/go-difflib
 //
 // Copyright (c) 2013, Patrick Mezard
@@ -32,6 +28,10 @@
 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+// Package ztest is a copy of https://github.com/arp242/zstd/tree/master/ztest –
+// vendored here so we don't add a dependency for just one file used in tests.
+//
+// DiffXML was removed as it depends on zgo.at/zstd/zxml.
 package ztest
 
 import (