Skip to content

Add --show-dictionary option to report the origin of each typo#3973

Open
ekanshul wants to merge 1 commit into
codespell-project:mainfrom
ekanshul:show-dictionary-1470
Open

Add --show-dictionary option to report the origin of each typo#3973
ekanshul wants to merge 1 commit into
codespell-project:mainfrom
ekanshul:show-dictionary-1470

Conversation

@ekanshul

Copy link
Copy Markdown

Closes #1470

Each dictionary entry now records which dictionary it was loaded from, and a new --show-dictionary option annotates every reported typo with it — the name of the builtin dictionary (clear, rare, …) or the path of a custom -D dictionary file:

$ codespell --show-dictionary file.txt
file.txt:1: abandonned ==> abandoned  (from clear)
file.txt:1: acapella ==> a cappella  (from rare)

This makes it easy to see which builtin dictionaries are worth enabling/disabling for a project, and to locate the right dictionary file when an entry needs fixing.

Implementation notes:

  • Misspelling gains a source attribute (a shared string per dictionary, so the memory overhead is one reference per entry).
  • When several dictionaries define the same entry, the last one loaded wins — matching the existing override behavior of the entry itself.
  • _select_builtin_dictionary now returns (filename, name) tuples so builtins can be reported by their friendly name.
  • Tests included (test_show_dictionary) covering builtins, custom dictionaries, override order and --check-filenames.

Each dictionary entry now records the dictionary it was loaded from.
With --show-dictionary, every reported typo is annotated with the name
of the builtin dictionary (e.g. 'clear', 'rare') or the path of the
custom dictionary file it came from, which helps decide which builtin
dictionaries to enable and makes dictionary entries easier to fix.

Closing: codespell-project#1470
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.

Track and report the dictionary a typo came from

1 participant