Add --min-word-length option to ignore short words#3971
Conversation
Words shorter than the given length are dropped from the misspelling dictionary up front, so they are ignored both in file contents and with --check-filenames. This avoids having to list every short variable name in --ignore-words-list. Closing: codespell-project#2211
|
Applied this branch and exercised it rather than just reading it — it works, and filtering at the dictionary level is the right layer. Sharing the checks in case they're useful to a maintainer: The one thing I went looking for was whether Filtering the dictionary once after For context on the size of what it buys: 162 of the default dictionary's keys are ≤3 characters, so (Not a maintainer, just a contributor who was recently in this file.) |
Closes #2211
Adds a
--min-word-length LENGTHoption so that words shorter than LENGTH are not checked. This helps with codebases full of 2-3 letter variable names that would otherwise each need an entry in--ignore-words-list.Implementation: entries shorter than LENGTH are dropped from the misspelling dictionary right after it is built, so short words are ignored consistently everywhere (file contents, stdin and
--check-filenames) with no per-word cost during scanning. The default (0) keeps current behavior.Example:
Tests included (
test_min_word_length) covering the length boundaries, case-insensitivity and--check-filenames.