Skip to content

Add --min-word-length option to ignore short words#3971

Open
ekanshul wants to merge 1 commit into
codespell-project:mainfrom
ekanshul:min-word-length-2211
Open

Add --min-word-length option to ignore short words#3971
ekanshul wants to merge 1 commit into
codespell-project:mainfrom
ekanshul:min-word-length-2211

Conversation

@ekanshul

Copy link
Copy Markdown

Closes #2211

Adds a --min-word-length LENGTH option 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:

$ codespell file.txt
file.txt:1: nwe ==> new
file.txt:1: abandonned ==> abandoned
$ codespell --min-word-length 4 file.txt
file.txt:1: abandonned ==> abandoned

Tests included (test_min_word_length) covering the length boundaries, case-insensitivity and --check-filenames.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Whishlist: Optionally ignore short words

1 participant