Skip to content

Commit ab1c742

Browse files
Deprecate misspell and replace it with typos
1 parent 750f044 commit ab1c742

File tree

16 files changed

+146
-64
lines changed

16 files changed

+146
-64
lines changed

.github/workflows/checks.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ name: Checks
1818
permissions:
1919
checks: write
2020
contents: read
21-
pull-requests: read
2221
jobs:
2322
checks:
2423
name: Checks
@@ -42,13 +41,9 @@ jobs:
4241
- name: Dependency Licenses Review
4342
run: make check-dependency-licenses
4443
- name: Check for spelling errors
45-
uses: reviewdog/action-misspell@v1
46-
with:
47-
exclude: ./vendor/*
48-
fail_on_error: true
49-
github_token: ${{ secrets.GITHUB_TOKEN }}
50-
ignore: importas
51-
reporter: github-check
44+
uses: crate-ci/typos@v1
45+
env:
46+
CLICOLOR: "1"
5247
- name: Check if source code files have license header
5348
run: make check-addlicense
5449
- name: REUSE Compliance Check

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ linters:
5656
- ineffassign
5757
- intrange
5858
- iotamixing
59-
- misspell
6059
- modernize
6160
- nilerr
6261
- nolintlint

.typos.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: 2025 SAP SE
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
[default.extend-words]
6+
7+
[files]
8+
extend-exclude = [
9+
"go.mod",
10+
"vendor/",
11+
]

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ run-shellcheck: FORCE install-shellcheck
110110
@printf "\e[1;36m>> shellcheck\e[0m\n"
111111
@find . \( -path './vendor/*' -prune \) -o -type f \( -name '*.bash' -o -name '*.ksh' -o -name '*.zsh' -o -name '*.sh' -o -name '*.shlib' \) -exec shellcheck {} +
112112

113+
run-typos: FORCE
114+
@printf "\e[1;36m>> typos\e[0m\n"
115+
@printf "\e[1;36m>> Typos install instructions can be found here https://github.com/crate-ci/typos#install e[0m\n"
116+
@typos
117+
113118
build/cover.out: FORCE | build
114119
@printf "\e[1;36m>> Running tests\e[0m\n"
115120
@env $(GO_TESTENV) go test -shuffle=on -coverprofile=build/coverprofile.out $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=go-makefile-maker -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTFLAGS) $(GO_TESTPKGS)
@@ -212,6 +217,7 @@ help: FORCE
212217
@printf " \e[36mcheck\e[0m Run the test suite (unit tests and golangci-lint).\n"
213218
@printf " \e[36mrun-golangci-lint\e[0m Install and run golangci-lint. Installing is used in CI, but you should probably install golangci-lint using your package manager.\n"
214219
@printf " \e[36mrun-shellcheck\e[0m Install and run shellcheck. Installing is used in CI, but you should probably install shellcheck using your package manager.\n"
220+
@printf " \e[36mrun-typos\e[0m Check for spelling errors using typos.\n"
215221
@printf " \e[36mbuild/cover.out\e[0m Run tests and generate coverage report.\n"
216222
@printf " \e[36mbuild/cover.html\e[0m Generate an HTML file with source code annotations from the coverage report.\n"
217223
@printf " \e[36mcheck-addlicense\e[0m Check license headers in all non-vendored .go files with addlicense.\n"

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ The config file has the following sections:
8282
* [renovate](#renovate)
8383
* [reuse](#reuse)
8484
* [shellCheck](#shellCheck)
85-
* [spellCheck](#spellcheck)
8685
* [testPackages](#testpackages)
86+
* [typos](#typos)
8787
* [variables](#variables)
8888
* [verbatim](#verbatim)
8989
* [githubWorkflow](#githubworkflow)
@@ -473,18 +473,23 @@ Whether to run [`ShellCheck`](https://www.shellcheck.net/) on all shell scripts
473473

474474
`opts` specifies additional options to pass to `shellcheck`. The `-e` option can be used to ignore specific shellcheck warnings.
475475

476-
### `spellCheck`
476+
### `typos`
477477

478478
```yaml
479-
spellCheck:
480-
ignoreWords:
481-
- example
482-
- exampleTwo
479+
typos:
480+
enabled: true
481+
extendExcludes:
482+
- internal/compress/constants.go
483+
- internal/compress/testdata/
484+
extendWords:
485+
- reenforced: reenforced # do not correct to the semantically different word "reinforced"
483486
```
484487

485-
`golangci-lint` (if `golangciLint.createConfig` is `true`) and the spell check GitHub workflow (`githubWorkflow.spellCheck`) use [`misspell`][misspell] to check for spelling errors.
488+
Whether to run [`typos`](https://github.com/crate-ci/typos) to check for spelling mistakes.
489+
490+
`typos.extendExcludes` maps to typos `files.extend-excludes` and allows to exclude some files or paths from spell checking.
486491

487-
If `spellCheck.ignoreWords` is defined then both `golangci-lint` and spell check workflow will give this word list to `misspell` so that they can be ignored during its checks.
492+
`typos.extendWords` maps to typos `default.extend-words` and allows to add custom word mappings to the dictionary. The key is hereby the wrong spelling and the value the correct spelling.
488493

489494

490495
### `testPackages`
@@ -714,7 +719,6 @@ githubWorkflow:
714719
[doublestar-pattern]: https://github.com/bmatcuk/doublestar#patterns
715720
[go-licence-detector]: https://github.com/elastic/go-licence-detector
716721
[govulncheck]: https://github.com/golang/vuln
717-
[misspell]: https://github.com/client9/misspell
718722
[ref-onpushpull]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths
719723
[ref-pattern-cheat-sheet]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
720724
[ref-runs-on]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

internal/core/config.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ type Configuration struct {
3838
Nix NixConfig `yaml:"nix"`
3939
Renovate RenovateConfig `yaml:"renovate"`
4040
ShellCheck ShellCheckConfiguration `yaml:"shellCheck"`
41-
SpellCheck SpellCheckConfiguration `yaml:"spellCheck"`
42-
Test TestConfiguration `yaml:"testPackages"`
43-
Reuse ReuseConfiguration `yaml:"reuse"`
44-
Verbatim string `yaml:"verbatim"`
45-
VariableValues map[string]string `yaml:"variables"`
41+
// Deprecated: use `typos` instead.
42+
SpellCheck SpellCheckConfiguration `yaml:"spellCheck"`
43+
Test TestConfiguration `yaml:"testPackages"`
44+
Typos TyposConfiguration `yaml:"typos"`
45+
Reuse ReuseConfiguration `yaml:"reuse"`
46+
Verbatim string `yaml:"verbatim"`
47+
VariableValues map[string]string `yaml:"variables"`
4648
}
4749

4850
// Variable returns the value of this variable if it's overridden in the config,
@@ -139,6 +141,18 @@ type SpellCheckConfiguration struct {
139141
IgnoreWords []string `yaml:"ignoreWords"`
140142
}
141143

144+
// TyposConfiguration appears in type Configuration.
145+
type TyposConfiguration struct {
146+
Enabled Option[bool] `yaml:"enabled"`
147+
ExtendExcludes []string `yaml:"extendExcludes"`
148+
ExtendWords map[string]string `yaml:"extendWords"`
149+
}
150+
151+
// IsEnabled encodes that the default state for the Enabled field is `true`.
152+
func (c TyposConfiguration) IsEnabled() bool {
153+
return c.Enabled.UnwrapOr(true)
154+
}
155+
142156
///////////////////////////////////////////////////////////////////////////////
143157
// GitHub workflow configuration
144158

@@ -214,6 +228,11 @@ func (s ShellCheckConfiguration) AllIgnorePaths(g GolangConfiguration) []string
214228
return s.IgnorePaths
215229
}
216230

231+
// IsEnabled encodes that the default state for the Enabled field is `true`.
232+
func (s ShellCheckConfiguration) IsEnabled() bool {
233+
return s.Enabled.UnwrapOr(true)
234+
}
235+
217236
type PackageRule struct {
218237
MatchPackageNames []string `yaml:"matchPackageNames" json:"matchPackageNames,omitempty"`
219238
MatchUpdateTypes []string `yaml:"matchUpdateTypes" json:"matchUpdateTypes,omitempty"`
@@ -298,6 +317,10 @@ type NixConfig struct {
298317
// Helper functions
299318

300319
func (c *Configuration) Validate() {
320+
if len(c.SpellCheck.IgnoreWords) > 0 {
321+
logg.Fatal("SpellCheck/misspell is deprecated, please migrate to typos")
322+
}
323+
301324
if c.Dockerfile.Enabled {
302325
if c.Metadata.URL == "" {
303326
logg.Fatal("metadata.url must be set when docker.enabled is true")

internal/core/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ const (
6565
GoCoverageReportAction = "fgrosse/[email protected]"
6666
GolangciLintAction = "golangci/golangci-lint-action@v9"
6767
GoreleaserAction = "goreleaser/goreleaser-action@v6"
68-
MisspellAction = "reviewdog/action-misspell@v1"
6968
ReuseAction = "fsfe/reuse-action@v6"
69+
TyposAction = "crate-ci/typos@v1"
7070
)

internal/ghworkflow/workflow_checks.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
package ghworkflow
55

66
import (
7-
"fmt"
8-
"strings"
9-
107
"github.com/sapcc/go-makefile-maker/internal/core"
118
)
129

@@ -27,7 +24,7 @@ func checksWorkflow(cfg core.Configuration) {
2724
},
2825
})
2926

30-
if cfg.ShellCheck.Enabled.UnwrapOr(true) {
27+
if cfg.ShellCheck.IsEnabled() {
3128
// delete the pretty out of date installed version of shellcheck so that make install-shellcheck installs the current version
3229
if !ghwCfg.IsSelfHostedRunner {
3330
j.addStep(jobStep{
@@ -49,24 +46,12 @@ func checksWorkflow(cfg core.Configuration) {
4946
}
5047

5148
if !ghwCfg.IsSelfHostedRunner {
52-
with := map[string]any{
53-
"exclude": "./vendor/*",
54-
"reporter": "github-check",
55-
"fail_on_error": true,
56-
"github_token": "${{ secrets.GITHUB_TOKEN }}",
57-
"ignore": "importas", //nolint:misspell //importas is a valid linter name, so we always ignore it
58-
}
59-
ignoreWords := cfg.SpellCheck.IgnoreWords
60-
if len(ignoreWords) > 0 {
61-
with["ignore"] = fmt.Sprintf("%s,%s", with["ignore"], strings.Join(ignoreWords, ","))
62-
}
63-
64-
w.Permissions.Checks = tokenScopeWrite // for nicer output in pull request diffs
65-
w.Permissions.PullRequests = tokenScopeRead // for private repos
6649
j.addStep(jobStep{
6750
Name: "Check for spelling errors",
68-
Uses: core.MisspellAction,
69-
With: with,
51+
Uses: core.TyposAction,
52+
Env: map[string]string{
53+
"CLICOLOR": "1",
54+
},
7055
})
7156
}
7257

internal/golangcilint/golangci.yaml.tmpl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ linters:
5656
- ineffassign
5757
- intrange
5858
- iotamixing
59-
- misspell
6059
- modernize
6160
- nilerr
6261
- nolintlint
@@ -160,13 +159,6 @@ linters:
160159
# omitzero requires removing omitempty tags in kubernetes api struct types which are nested, which is intepreted by controller-gen and breaks the CRDs.
161160
- omitzero
162161
{{- end }}
163-
{{- if .MisspellIgnoreWords }}
164-
misspell:
165-
ignore-rules:
166-
{{- range .MisspellIgnoreWords }}
167-
- {{ . }}
168-
{{- end }}
169-
{{- end }}
170162
perfsprint:
171163
# modernize generates nicer fix code
172164
concat-loop: false

internal/golangcilint/golangci_lint.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ func RenderConfig(cfg core.Configuration, sr golang.ScanResult) {
2828
}
2929

3030
must.Succeed(util.WriteFileFromTemplate(".golangci.yaml", configTemplate, map[string]any{
31-
"EnableVendoring": cfg.Golang.EnableVendoring,
32-
"GoMinorVersion": must.Return(strconv.Atoi(strings.Split(sr.GoVersion, ".")[1])),
33-
"ModulePath": sr.ModulePath,
34-
"MisspellIgnoreWords": cfg.SpellCheck.IgnoreWords,
35-
"ErrcheckExcludes": cfg.GolangciLint.ErrcheckExcludes,
36-
"SkipDirs": cfg.GolangciLint.SkipDirs,
37-
"Timeout": timeout,
38-
"ReviveRules": cfg.GolangciLint.ReviveRules,
39-
"WithControllerGen": cfg.ControllerGen.Enabled.UnwrapOr(sr.KubernetesController),
31+
"EnableVendoring": cfg.Golang.EnableVendoring,
32+
"GoMinorVersion": must.Return(strconv.Atoi(strings.Split(sr.GoVersion, ".")[1])),
33+
"ModulePath": sr.ModulePath,
34+
"ErrcheckExcludes": cfg.GolangciLint.ErrcheckExcludes,
35+
"SkipDirs": cfg.GolangciLint.SkipDirs,
36+
"Timeout": timeout,
37+
"ReviveRules": cfg.GolangciLint.ReviveRules,
38+
"WithControllerGen": cfg.ControllerGen.Enabled.UnwrapOr(sr.KubernetesController),
4039
}))
4140
}

0 commit comments

Comments
 (0)