golangci/golangci-lint · error

typo (%q) and correction (%q) fields should not be empty

Error message

typo (%q) and correction (%q) fields should not be empty

What it means

misspell's extra-words setting lets users add custom typo→correction pairs. appendExtraWords validates each pair and rejects any entry whose typo or correction field is an empty string, because an empty rule is meaningless and would corrupt the replacer dictionary.

Source

Thrown at pkg/golinters/misspell/misspell.go:136

					NewText: []byte(diff.Corrected),
				}},
			}},
		})
	}

	return nil
}

func appendExtraWords(replacer *misspell.Replacer, extraWords []config.MisspellExtraWords) error {
	if len(extraWords) == 0 {
		return nil
	}

	extra := make([]string, 0, len(extraWords)*2)

	for _, word := range extraWords {
		if word.Typo == "" || word.Correction == "" {
			return fmt.Errorf("typo (%q) and correction (%q) fields should not be empty", word.Typo, word.Correction)
		}

		if strings.ContainsFunc(word.Typo, func(r rune) bool { return !unicode.IsLetter(r) }) {
			return fmt.Errorf("the word %q in the 'typo' field should only contain letters", word.Typo)
		}
		if strings.ContainsFunc(word.Correction, func(r rune) bool { return !unicode.IsLetter(r) }) {
			return fmt.Errorf("the word %q in the 'correction' field should only contain letters", word.Correction)
		}

		extra = append(extra, strings.ToLower(word.Typo), strings.ToLower(word.Correction))
	}

	replacer.AddRuleList(extra)

	return nil
}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Fill in both typo and correction with non-empty single-word values for every extra-words entry.
  2. Delete entries that have an empty side instead of leaving blank keys.
  3. Run `golangci-lint config verify` to catch malformed settings early.
  4. If you want to ignore a word, use ignore-rules instead of an empty correction.

Example fix

# before
extra-words:
  - typo: "langauge"
    correction: ""
# after
extra-words:
  - typo: "langauge"
    correction: "language"
Defensive patterns

Strategy: validation

Validate before calling

for i, w := range extraWords {
    if w.Typo == "" || w.Correction == "" {
        return fmt.Errorf("extra-words[%d]: typo and correction must be non-empty", i)
    }
}

Prevention

When it happens

Trigger: Any entry in linters-settings.misspell.extra-words with typo: "" or correction: "" (missing key, blank YAML value, or null) while golangci-lint builds the misspell replacer.

Common situations: YAML entries where one side was left blank after editing; templated config generation that dropped a value; entries copied where the correction was intentionally empty to 'delete' a word.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/c3a5b5cf70aedad0. Report an issue: GitHub.