Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codespell support (config, workflow to detect/not fix) and make it fix few typos #12731

Closed
wants to merge 8 commits into from
8 changes: 8 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[codespell]
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
skip = .git*,*.pdf,*.svg,go.sum,package-lock.json,*.css,*.min.*,.codespellrc,.cspell.json,time_test.go,_vendor,*.csv,commands_errors.txt,*.cn.*,*.bundle.js
check-hidden = true
# Lines with regex (duplicated all around and include "TE?MP"), mixed in case words, some German, etc
ignore-regex = .*TE\?MP.*|.*codespell-ignore.*|[A-Z]?[a-z]*[A-Z][a-zA-Z]*|/extras/crossreferences/|Januar 2023|\\ndoes|.*ä.*
# Some common short variable names
ignore-words-list = bu,edn,ot,fromt,varn,trys,classess,wil,te,ue,womens
25 changes: 25 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Codespell configuration is within .codespellrc
---
name: Codespell

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Annotate locations with typos
uses: codespell-project/codespell-problem-matcher@v1
- name: Codespell
uses: codespell-project/actions-codespell@v2
2 changes: 1 addition & 1 deletion cache/httpcache/httpcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Config struct {
}

type Cache struct {
// Enable HTTP cache behaviour (RFC 9111) for these rsources.
// Enable HTTP cache behaviour (RFC 9111) for these resources.
For GlobMatcher
}

Expand Down
2 changes: 1 addition & 1 deletion common/hexec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (e *Exec) new(name string, fullyQualifiedName string, arg ...any) (Runner,
}

// Npx will in order:
// 1. Try fo find the binary in the WORKINGDIR/node_modules/.bin directory.
// 1. Try to find the binary in the WORKINGDIR/node_modules/.bin directory.
// 2. If not found, and npx is available, run npx --no-install <name> <args>.
// 3. Fall back to the PATH.
func (e *Exec) Npx(name string, arg ...any) (Runner, error) {
Expand Down
2 changes: 1 addition & 1 deletion common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func DeprecateLevel(item, alternative, version string, level logg.Level) {
loggers.Log().Logger().WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf(msg)
}

// We ususally do about one minor version a month.
// We usually do about one minor version a month.
// We want people to run at least the current and previous version without any warnings.
// We want people who don't update Hugo that often to see the warnings and errors before we remove the feature.
func deprecationLogLevelFromVersion(ver string) logg.Level {
Expand Down
2 changes: 1 addition & 1 deletion config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ func (c *Configs) Init() error {
}

if len(c.Modules) == 0 {
return errors.New("no modules loaded (ned at least the main module)")
return errors.New("no modules loaded (need at least the main module)")
}

// Apply default project mounts.
Expand Down
2 changes: 1 addition & 1 deletion config/allconfig/alldecoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ var allDecoderSetups = map[string]decodeWeight{
var err error
m := p.p.GetStringMap(d.key)
if len(m) == 1 {
// In v0.112.4 we moved this to the language config, but it's very commmon for mono language sites to have this at the top level.
// In v0.112.4 we moved this to the language config, but it's very common for mono language sites to have this at the top level.
var first maps.Params
var ok bool
for _, v := range m {
Expand Down
2 changes: 1 addition & 1 deletion create/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (b *contentBuilder) mapArcheTypeDir() error {
// In the regular build, we will filter out the duplicates, but
// for archetype folders these are ambiguous and we need to
// fail.
return fmt.Errorf("duplicate content file found in archetype folder: %q; having both e.g. %s.md and %s.html is ambigous", path, pi.BaseNameNoIdentifier(), pi.BaseNameNoIdentifier())
return fmt.Errorf("duplicate content file found in archetype folder: %q; having both e.g. %s.md and %s.html is ambiguous", path, pi.BaseNameNoIdentifier(), pi.BaseNameNoIdentifier())
}
seen[pathLang] = true
m.contentFiles = append(m.contentFiles, fim)
Expand Down
2 changes: 1 addition & 1 deletion hugolib/content_map_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type pageTrees struct {
treeTaxonomyEntries *doctree.TreeShiftTree[*weightedContentNode]

// Stores the state for _content.gotmpl files.
// Mostly releveant for rebuilds.
// Mostly relevant for rebuilds.
treePagesFromTemplateAdapters *doctree.TreeShiftTree[*pagesfromdata.PagesFromTemplate]

// A slice of the resource trees.
Expand Down
2 changes: 1 addition & 1 deletion hugolib/datafiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ d: {{ site.Data.d.v1 }}|
`
b := Test(t, files)

b.AssertFileContent("public/index.html", "a: a_v1|\nb: b_v1|\ncd: c_d_v1|\nd: d_v1_theme|")
b.AssertFileContent("public/index.html", "a: a_v1|\nb: b_v1|\ncd: c_d_v1|\nd: d_v1_theme|") // pragma: codespell-ignore
})
}

Expand Down
2 changes: 1 addition & 1 deletion hugolib/dates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Date: {{ .Date | time.Format ":date_long" }}
b.Build(BuildCfg{})

b.AssertFileContent("public/en/index.html", `Date: July 18, 2021`)
b.AssertFileContent("public/nn/index.html", `Date: 18. juli 2021`)
b.AssertFileContent("public/nn/index.html", `Date: 18. juli 2021`) // pragma: codespell-ignore
}

func TestTimeZones(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/doctree/nodeshifttree.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type (
)

// NodeShiftTree is the root of a tree that can be shaped using the Shape method.
// Note that multipled shapes of the same tree is meant to be used concurrently,
// Note that multiplied shapes of the same tree is meant to be used concurrently,
// so use the applicable locking when needed.
type NodeShiftTree[T any] struct {
tree *radix.Tree
Expand Down
2 changes: 1 addition & 1 deletion hugolib/filesystems/basefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (d *SourceFilesystem) mounts() []hugofs.FileMetaInfo {
})

// Filter out any mounts not belonging to this filesystem.
// TODO(bep) I think this is superflous.
// TODO(bep) I think this is superfluous.
n := 0
for _, mm := range m {
if mm.Meta().Component == d.Name {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/hugo_sites_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func checkContent(s *sitesBuilder, filename string, matches ...string) {
content := readWorkingDir(s.T, s.Fs, filename)
for _, match := range matches {
if !strings.Contains(content, match) {
s.Fatalf("No match for\n%q\nin content for %s\n%q\nDiff:\n%s", match, filename, content, htesting.DiffStrings(content, match))
s.Fatalf("No match for\n%q\nin content for %s\n%q\nDiff:\n%s", match, filename, content, htesting.DiffStrings(content, match)) // pragma: codespell-ignore
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/integrationtest_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestOptWithNFDOnDarwin() TestOpt {
}
}

// TestOptWithWorkingDir allows setting any config optiona as a function al option.
// TestOptWithWorkingDir allows setting any config option as a function al option.
func TestOptWithConfig(fn func(c *IntegrationTestConfig)) TestOpt {
return func(c *IntegrationTestConfig) {
fn(c)
Expand Down
2 changes: 1 addition & 1 deletion hugolib/segments/segments.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (e excludeInclude) ShouldExcludeCoarse(fields SegmentMatcherFields) bool {
}

// ShouldExcludeFine returns whether the given fields should be excluded.
// This is used for the finer grained checks, e.g. on invididual pages.
// This is used for the finer grained checks, e.g. on individual pages.
func (e excludeInclude) ShouldExcludeFine(fields SegmentMatcherFields) bool {
if e.exclude != nil && e.exclude(fields) {
return true
Expand Down
2 changes: 1 addition & 1 deletion internal/warpc/warpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ type CompiledModule struct {
RuntimeName string

// The main module to instantiate.
// This will be insantiated multiple times in a pool,
// This will be instantiated multiple times in a pool,
// so it does not need a name.
Module wazero.CompiledModule
}
Expand Down
6 changes: 3 additions & 3 deletions livereload/livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ if (PATCH) {
}
if (NPCG_INCLUDED && match && match.length > 1) {
// Fix browsers whose `exec` methods don't consistently return `undefined`
// for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/
// for NPCG, like IE8. NOTE: This doesn't work for /(.?)?/
// eslint-disable-next-line no-loop-func
nativeReplace.call(match[0], reCopy, function () {
for (i = 1; i < arguments.length - 2; i++) {
Expand Down Expand Up @@ -1465,7 +1465,7 @@ if (!$Number(' 0o1') || !$Number('0b1') || $Number('+0x1')) {
for (var keys = require('./_descriptors') ? gOPN(Base) : (
// ES3:
'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' +
// ES6 (in case, if modules with ES6 Number statics required before):
// ES6 (in case, if modules with ES6 Number statistics required before):
'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' +
'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger'
).split(','), j = 0, key; keys.length > j; j++) {
Expand Down Expand Up @@ -2761,7 +2761,7 @@ var LiveReload = /*#__PURE__*/function () {
// -- required, plugin constructor
//
// bool plugin.reload(string path, { bool liveCSS, bool liveImg })
// -- optional, attemp to reload the given path, return true if handled
// -- optional, attempt to reload the given path, return true if handled
//
// object plugin.analyze()
// -- optional, returns plugin-specific information about the current document (to send to the connected server)
Expand Down
2 changes: 1 addition & 1 deletion markup/blackfriday/anchors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package blackfriday holds some compability functions for the old Blackfriday v1 Markdown engine.
// Package blackfriday holds some compatibility functions for the old Blackfriday v1 Markdown engine.
package blackfriday

import "unicode"
Expand Down
2 changes: 1 addition & 1 deletion markup/goldmark/goldmark_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ FENCE
runBenchmark(filesTemplate, b)
})

b.Run("Hook no higlight", func(b *testing.B) {
b.Run("Hook no highlight", func(b *testing.B) {
files := filesTemplate + `
-- layouts/_default/_markup/render-codeblock.html --
{{ .Inner }}
Expand Down
2 changes: 1 addition & 1 deletion markup/tableofcontents/tableofcontents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestTocMisc(t *testing.T) {
toc := newTestToc()
m := toc.HeadingsMap
c.Assert(m["h1-1"].Title, qt.Equals, "Heading 1")
c.Assert(m["doesnot exist"], qt.IsNil)
c.Assert(m["doesn't exist"], qt.IsNil)
})
}

Expand Down
2 changes: 1 addition & 1 deletion parser/pageparser/pagelexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (l *pageLexer) emit(t ItemType) {
}()

if t == tText {
// Identify any trailing whitespace/intendation.
// Identify any trailing whitespace/indentation.
// We currently only care about the last one.
for i := l.pos - 1; i >= l.start; i-- {
b := l.input[i]
Expand Down
2 changes: 1 addition & 1 deletion resources/page/pages_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var (
if o1 != o2 && o1 != -1 && o2 != -1 {
return o1 < o2
}
// Weight0, as by the weight of the taxonomy entrie in the front matter.
// Weight0, as by the weight of the taxonomy entry in the front matter.
w01, w02 := getWeight0s(p1, p2)
if w01 != w02 && w01 != -1 && w02 != -1 {
return w01 < w02
Expand Down
2 changes: 1 addition & 1 deletion tpl/collections/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ func TestUniq(t *testing.T) {

// should fail
{1, 1, true},
{"foo", "fo", true},
{"foo", "fo", true}, // pragma: codespell-ignore
} {
errMsg := qt.Commentf("[%d] %v", i, test)

Expand Down
2 changes: 1 addition & 1 deletion tpl/debug/debug_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tags: ["a", "b"]
-- layouts/_default/list.html --
Dump: {{ debug.Dump . | safeHTML }}
Dump Site: {{ debug.Dump site }}
Dum site.Taxonomies: {{ debug.Dump site.Taxonomies | safeHTML }}
Dump site.Taxonomies: {{ debug.Dump site.Taxonomies | safeHTML }}
-- layouts/_default/single.html --
Dump: {{ debug.Dump . | safeHTML }}

Expand Down
14 changes: 7 additions & 7 deletions tpl/partials/partials.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type partialCacheKey struct {
Variants []any
}
type includeResult struct {
name string
result any
mangager identity.Manager
err error
name string
result any
manager identity.Manager
err error
}

func (k partialCacheKey) Key() string {
Expand Down Expand Up @@ -239,7 +239,7 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any
}
r := ns.includWithTimeout(ctx, key.Name, context)
if ns.deps.Conf.Watching() {
r.mangager = depsManagerShared
r.manager = depsManagerShared
}
return r, r.err
})
Expand All @@ -257,8 +257,8 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any
ns.deps.Metrics.TrackValue(key.templateName(), r.result, found)
}

if r.mangager != nil && depsManagerIn != nil {
depsManagerIn.AddIdentity(r.mangager)
if r.manager != nil && depsManagerIn != nil {
depsManagerIn.AddIdentity(r.manager)
}

return r.result, nil
Expand Down