From 451cc6c0486aa67d410000e44dd155f07ae48b3c Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sat, 30 May 2026 16:15:13 -0400 Subject: [PATCH] Add codespell support with configuration and fixes (#21807) Co-authored-by: Claude Code 2.1.142 / Claude Opus 4.7 --- .codespellrc | 25 +++++++++++++++++++++++ .dockerignore | 2 +- .github/workflows/codespell.yml | 27 +++++++++++++++++++++++++ .golangci.yml | 2 +- cmd/restic/cmd_copy_integration_test.go | 2 +- cmd/restic/cmd_mount.go | 2 +- internal/fs/node.go | 2 +- internal/repository/packer_manager.go | 2 +- internal/repository/prune.go | 2 +- internal/repository/prune_test.go | 2 +- internal/restic/lock_unix.go | 2 +- internal/restorer/filerestorer.go | 2 +- internal/restorer/fileswriter.go | 2 +- 13 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 .codespellrc create mode 100644 .github/workflows/codespell.yml diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 000000000..95163923b --- /dev/null +++ b/.codespellrc @@ -0,0 +1,25 @@ +[codespell] + +# Ref: https://github.com/codespell-project/codespell#using-a-config-file +# Skip historical content (CHANGELOG, release notes archive), auto-generated +# man pages (which contain troff macros like \(bu that look like typos), and +# files we don't want to modify (go.sum, css with vendor prefixes). +skip = .git*,.gitignore,.gitattributes,go.sum,*.css,.codespellrc,CHANGELOG.md,changelog,*.1 +check-hidden = true + +# Protect URLs from corrections (URLs may contain words flagged as typos and +# must not be changed); also ignore camelCase/PascalCase identifiers like +# AtLeast which are valid Go identifiers, not typos. +ignore-regex = https?://\S+|\b[a-z]+[A-Z]\w*\b|\b[A-Z][a-z]+[A-Z]\w*\b + +ignore-words-list = + # variable name short for "serialized", also matches [uU]ser glob pattern + ser, + # German word "ist" appearing in test data string + ist, + # intentional truncated test string in format truncation tests + fo, + # CLI flag name (--iinclude, case-insensitive include) + iinclude, + # intentional in fake test path /doesnt/exist + doesnt diff --git a/.dockerignore b/.dockerignore index 30f93a461..9bd2d5970 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,6 @@ # Actual layer caching is impossible due to .git, but # that must be included for provenance reasons. These ignores -# are strictly for hygenic build. +# are strictly for hygienic build. * !/*.go !/go.* diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml new file mode 100644 index 000000000..0c70ed5b9 --- /dev/null +++ b/.github/workflows/codespell.yml @@ -0,0 +1,27 @@ +# Codespell configuration is within .codespellrc +--- +name: Codespell + +on: + # run checks on push to master, but not when other branches are pushed to + push: + branches: + - master + + # run checks for all pull requests + pull_request: + merge_group: + +permissions: + contents: read + +jobs: + codespell: + name: Check for spelling errors + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Codespell + uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2 diff --git a/.golangci.yml b/.golangci.yml index fd703473f..5f52eb8c6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,7 +55,7 @@ linters: - "-ST1021" - "-ST1022" # extra disables - - "-QF1008" # don't warn about specifing name of embedded field on access + - "-QF1008" # don't warn about specifying name of embedded field on access exclusions: rules: # revive: ignore unused parameters in tests diff --git a/cmd/restic/cmd_copy_integration_test.go b/cmd/restic/cmd_copy_integration_test.go index 6105acfe4..93f9685f6 100644 --- a/cmd/restic/cmd_copy_integration_test.go +++ b/cmd/restic/cmd_copy_integration_test.go @@ -90,7 +90,7 @@ func TestCopy(t *testing.T) { _, _, countBlobs := testPackAndBlobCounts(t, env.gopts) countTreePacksDst, countDataPacksDst, countBlobsDst := testPackAndBlobCounts(t, env2.gopts) - rtest.Equals(t, countBlobs, countBlobsDst, "expected blob count in boths repos to be equal") + rtest.Equals(t, countBlobs, countBlobsDst, "expected blob count in both repos to be equal") rtest.Equals(t, countTreePacksDst, 1, "expected 1 tree packfile") rtest.Equals(t, countDataPacksDst, 1, "expected 1 data packfile") } diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index c0f446193..cf521d643 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -145,7 +145,7 @@ func runMount(ctx context.Context, opts MountOptions, gopts global.Options, args err = unix.Access(mountpoint, unix.W_OK|unix.X_OK) if err != nil { - printer.P("Mountpoint %s is not writeable or not excutable", mountpoint) + printer.P("Mountpoint %s is not writeable or not executable", mountpoint) return errors.Fatal("inaccessible mountpoint") } diff --git a/internal/fs/node.go b/internal/fs/node.go index a66819d50..f2371e1fc 100644 --- a/internal/fs/node.go +++ b/internal/fs/node.go @@ -137,7 +137,7 @@ var ( // Cached uid lookup by user name. Returns 0 when no id can be found. // -//nolint:revive // captialization is correct as is +//nolint:revive // capitalization is correct as is func lookupUid(userName string) uint32 { userNameLookupCacheMutex.RLock() uid, ok := userNameLookupCache[userName] diff --git a/internal/repository/packer_manager.go b/internal/repository/packer_manager.go index c21d4b150..730be79b2 100644 --- a/internal/repository/packer_manager.go +++ b/internal/repository/packer_manager.go @@ -74,7 +74,7 @@ func (r *packerManager) Flush(ctx context.Context) error { // mergePackers merges small pack files before those are uploaded by Flush(). The main // purpose of this method is to reduce information leaks if a small file is backed up -// and the blobs end up in spearate pack files. If the file only consists of two blobs +// and the blobs end up in separate pack files. If the file only consists of two blobs // this would leak the size of the individual blobs. func (r *packerManager) mergePackers() ([]*packer, error) { pendingPackers := []*packer{} diff --git a/internal/repository/prune.go b/internal/repository/prune.go index 89c0a8b7a..393c2e45b 100644 --- a/internal/repository/prune.go +++ b/internal/repository/prune.go @@ -342,7 +342,7 @@ func calculateTargetPacksize(opts PruneOptions, indexPack map[restic.ID]packInfo return cmp.Compare(a.size, b.size) }) - // Using the approximatelly 3rd percentile is just a heuristic and may not always be the optimal choice. + // Using the approximately 3rd percentile is just a heuristic and may not always be the optimal choice. // However, using a low percentile ensures that only a small fraction of the repository // may end up being repacked. By using 80% of that perecentile or the minimum pack size, // we ensure that no repacking happens if the repository already has no small pack files. diff --git a/internal/repository/prune_test.go b/internal/repository/prune_test.go index 668866808..fc3c4dbbe 100644 --- a/internal/repository/prune_test.go +++ b/internal/repository/prune_test.go @@ -133,7 +133,7 @@ func TestPruneSmall(t *testing.T) { keep := restic.NewBlobSet() rtest.OK(t, repo.WithBlobUploader(context.TODO(), func(ctx context.Context, uploader restic.BlobSaverWithAsync) error { - // we need a minum of 11 packfiles, each packfile will be about 5 Mb long + // we need a minimum of 11 packfiles, each packfile will be about 5 Mb long for i := 0; i < numBlobsCreated; i++ { buf := make([]byte, blobSize) random.Read(buf) diff --git a/internal/restic/lock_unix.go b/internal/restic/lock_unix.go index ab54daf8e..ca1c74df2 100644 --- a/internal/restic/lock_unix.go +++ b/internal/restic/lock_unix.go @@ -14,7 +14,7 @@ import ( // UidGidInt returns uid, gid of the user as a number. // -//nolint:revive // captialization is correct as is +//nolint:revive // capitalization is correct as is func UidGidInt(u *user.User) (uid, gid uint32, err error) { ui, err := strconv.ParseUint(u.Uid, 10, 32) if err != nil { diff --git a/internal/restorer/filerestorer.go b/internal/restorer/filerestorer.go index d197bcf5b..01f4734b4 100644 --- a/internal/restorer/filerestorer.go +++ b/internal/restorer/filerestorer.go @@ -185,7 +185,7 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error { file.sparse = false } - // empty file or one with already uptodate content. Make sure that the file size is correct + // empty file or one with already up-to-date content. Make sure that the file size is correct if !restoredBlobs { err := r.truncateFileToSize(file.location, file.size) if errFile := r.sanitizeError(file, err); errFile != nil { diff --git a/internal/restorer/fileswriter.go b/internal/restorer/fileswriter.go index 2b60f7185..59871324c 100644 --- a/internal/restorer/fileswriter.go +++ b/internal/restorer/fileswriter.go @@ -232,7 +232,7 @@ func (w *filesWriter) writeToFile(path string, blob []byte, offset int64, create bucket.files[path].users-- if bucket.files[path].users == 0 { delete(bucket.files, path) - // Add to cache to allow re-use. Cache will close files on overflow. + // Add to cache to allow reuse. Cache will close files on overflow. w.cacheMu.Lock() w.cache.Add(path, wr) w.cacheMu.Unlock()