diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4ab3bbe..aea6a6e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,3 +18,5 @@ jobs: permissions: contents: read uses: FollowTheProcess/ci/.github/workflows/Go.yml@v3 + with: + lint-tool: staticcheck diff --git a/.gitignore b/.gitignore index bdc45d5..19a83a5 100755 --- a/.gitignore +++ b/.gitignore @@ -1,216 +1,43 @@ -# Created by https://www.toptal.com/developers/gitignore/api/macos,windows,linux,visualstudiocode,jetbrains+all,go -# Edit at https://www.toptal.com/developers/gitignore?templates=macos,windows,linux,visualstudiocode,jetbrains+all,go +# Allowlisting gitignore template for GO projects prevents us +# from adding various unwanted local files, such as generated +# files, developer configurations or IDE-specific files etc. -### Go ### -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib +# Ignore everything +* -# Test binary, built with `go test -c` -*.test +# Except these... -# Output of the go coverage tool, specifically when used with LiteIDE -*.out -coverage.html +# Git/GitHub +!/.gitignore +!/.gitattributes +!/.github/**/* -# Taskfile -.task +# Go +!*.go +!go.sum +!go.mod +!.goreleaser.yaml +!.golangci.yml +!staticcheck.conf +!**/testdata/** -# Comparative benchmarks -before.txt -after.txt +# CodeCov +!codecov.yml -# Dependency directories (remove the comment below to include it) -# vendor/ - -# Go workspace file -go.work - -### JetBrains+all ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### JetBrains+all Patch ### -# Ignore everything but code style settings and run configurations -# that are supposed to be shared within teams. - -.idea/* - -!.idea/codeStyles -!.idea/runConfigurations - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### macOS ### # General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### macOS Patch ### -# iCloud generated files -*.icloud - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets - -# Local History for Visual Studio Code -.history/ - -# Built Visual Studio Code Extensions -*.vsix - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history -.ionide - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini +!README.md +!LICENSE +!docs/**/* +!examples/**/* -# Recycle Bin used on file shares -$RECYCLE.BIN/ +# Typos +!.typos.toml -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp +# Task +!Taskfile.yml -# Windows shortcuts -*.lnk +# Copier +!.copier-answers.yml -# End of https://www.toptal.com/developers/gitignore/api/macos,windows,linux,visualstudiocode,jetbrains+all,go +# ...even if they are in subdirectories +!*/ diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 0ea78a5..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,175 +0,0 @@ -version: "2" - -formatters: - enable: - - gofumpt - - goimports - - golines - - settings: - gofumpt: - extra-rules: true - - golines: - max-len: 140 - -linters: - default: all - disable: - - decorder # Don't care about this - - dupl # Basically every table driven test ever triggers this - - dupword # Messes with test cases more often than not - - err113 # Out of date - - exhaustruct # No - - forbidigo # Nothing to forbid - - funlen # Bad metric for complexity - - ginkgolinter # I don't use whatever this is - - gochecknoglobals # Globals are fine sometimes, use common sense - - gocyclo # cyclop does this instead - - godox # "todo" and "fixme" comments are allowed - - goheader # No need - - gosmopolitan # No need - - grouper # Imports take care of themselves, rest is common sense - - ireturn # This is just not necessary or practical in a real codebase - - lll # Auto formatters do this and what they can't do I don't care about - - maintidx # This is just the inverse of complexity... which is cyclop - - nestif # cyclop does this - - nlreturn # Similar to wsl, I think best left to judgement - - nonamedreturns # Named returns are often helpful, it's naked returns that are the issue - - noinlineerr # This is more readable in some cases - - paralleltest # I've never had Go tests take longer than a few seconds, it's fine - - unparam # gopls is better and more subtle - - varnamelen # Lots of false positives of things that are fine - - wrapcheck # Not every error must be wrapped - - wsl # Very aggressive, some of this I like but tend to do anyway - - exclusions: - presets: - # See https://golangci-lint.run/usage/false-positives/#exclusion-presets - - comments # Revive in particular has lots of false positives - - std-error-handling - - common-false-positives - rules: - - path: _test\.go - linters: - - prealloc # These kinds of optimisations will make no difference to test code - - gosec # Tests don't need security stuff - - - path: examples - linters: - - mnd - - gosec - - settings: - cyclop: - max-complexity: 20 - - depguard: - rules: - main: - deny: - - pkg: io/ioutil - desc: io/ioutil is deprecated, use io instead - - - pkg: "math/rand$" - desc: use math/rand/v2 instead - - errcheck: - check-type-assertions: true - check-blank: true - - exhaustive: - check: - - switch - - map - default-signifies-exhaustive: true - - staticcheck: - checks: - - all - - gosec: - excludes: - - G104 # Errors not checked, handled by errcheck - - govet: - enable-all: true - - nakedret: - max-func-lines: 0 # Disallow any naked returns - - nolintlint: - allow-unused: false - require-explanation: true - require-specific: true - - usetesting: - context-background: true - context-todo: true - os-chdir: true - os-mkdir-temp: true - os-setenv: true - os-create-temp: true - os-temp-dir: true - - revive: - max-open-files: 256 - enable-all-rules: true - rules: - - name: add-constant - disabled: true # goconst does this - - - name: argument-limit - arguments: - - 5 - - - name: cognitive-complexity - disabled: true # gocognit does this - - - name: comment-spacings - arguments: - - "nolint:" - - - name: cyclomatic - disabled: true # cyclop does this - - - name: exported - arguments: - - checkPrivateReceivers - - checkPublicInterface - - - name: function-length - disabled: true # Bad proxy for complexity - - - name: function-result-limit - arguments: - - 3 - - - name: import-shadowing - disabled: true # predeclared does this - - - name: line-length-limit - disabled: true # gofmt/golines handles this well enough - - - name: max-public-structs - disabled: true # This is a dumb rule - - - name: redefines-builtin-id - disabled: true # predeclared does this - - - name: unhandled-error - arguments: - - fmt\.(Fp|P)rint(ln|f)? - - strings.Builder.Write(String|Byte)? - - bytes.Buffer.Write(String|Byte)? - - bytes.Buffer.WriteTo? - - os.File.Close? - - - name: flag-parameter - disabled: true # As far as I can work out this just doesn't like bools - - - name: unused-parameter - disabled: true # The gopls unused analyzer covers this better - - - name: unused-receiver - disabled: true # As above diff --git a/Taskfile.yml b/Taskfile.yml index 7d8488d..6ca440e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -8,6 +8,7 @@ vars: tasks: default: desc: List all available tasks + internal: true silent: true cmds: - task --list @@ -25,9 +26,8 @@ tasks: desc: Run go fmt on all source files sources: - "**/*.go" - - .golangci.yml cmds: - - golangci-lint fmt + - go fmt ./... demo: desc: Render the demo gifs @@ -58,18 +58,18 @@ tasks: - go test ./... -run None -benchmem -bench . {{ .CLI_ARGS }} lint: - desc: Run the linters and auto-fix if possible + desc: Run linting sources: - "**/*.go" - - .golangci.yml + - staticcheck.conf preconditions: - - sh: command -v golangci-lint - msg: golangci-lint not installed, see https://golangci-lint.run/usage/install/#local-installation + - sh: command -v staticcheck + msg: staticcheck not installed, see https://staticcheck.dev/docs/getting-started/ - sh: command -v typos msg: requires typos-cli, run `brew install typos-cli` cmds: - - golangci-lint run --fix + - staticcheck ./... - typos doc: diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 0000000..528438b --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1 @@ +checks = ["all"]