Codespell is a tool that checks for common misspellings in text files. It's designed to catch spelling errors that might be missed by traditional spell checkers, especially in code and documentation.
Codespell helps improve the quality of your codebase by:
- Finding and fixing common spelling mistakes
- Checking multiple file types (Python, Markdown, text, etc.)
- Supporting custom dictionaries for project-specific terms
- Integrating with pre-commit hooks for automated checks
Codespell is included as a development dependency:
# Install with other development dependencies
uv sync --devTo install it directly:
uv pip install codespellIn this project, Codespell is used to:
- Check for spelling errors in all project files
- Run automatically as a pre-commit hook
- Ensure consistent spelling in documentation and code comments
Codespell is configured in the pyproject.toml file:
[tool.codespell]
skip = "*.json,*.csv,*.pyc,*.min.js,node_modules/*,build/*,dist/*"
ignore-words-list = "crate,hist,ro,while"This configuration:
- Skips checking certain file types and directories
- Ignores specific words that might be flagged incorrectly
- Runs on all other files in the project
To run Codespell on the project:
# Run on the entire project
uv run codespell
# Run on specific files or directories
uv run codespell src/ docs/ README.md# Check with a custom dictionary
uv run codespell --dictionary=./custom_dictionary.txt
# Write corrections directly to files
uv run codespell --write-changes
# Show only certain types of errors
uv run codespell --quiet-level=2
# Ignore specific words
uv run codespell --ignore-words-list="crate,hist,ro"Here's an example of what codespell output might look like:
$ uv run codespell src/
src/module.py:10: definitely -> definitely
src/utils.py:25: receive -> receive
docs/README.md:15: occurred -> occurred
Example of checking and correcting:
# Check and show suggestions without making changes
$ uv run codespell src/module.py
src/module.py:10: definitely -> definitely
# Apply corrections automatically
$ uv run codespell --write-changes src/module.py
src/module.py:10: definitely -> definitely
Here are some common misspellings that Codespell catches:
| Common Typo | Correct Spelling |
|---|---|
| accommodate | accommodate |
| achieve | achieve |
| address | address |
| argument | argument |
| believe | believe |
| consensus | consensus |
| definitely | definitely |
| dependency | dependency |
| existence | existence |
| occurred | occurred |
| receive | receive |
| separate | separate |
| successful | successful |
- Run regularly: Include Codespell in your pre-commit hooks
- Customize for your project: Add project-specific terms to the ignore list
- Fix spelling errors promptly: Correct spelling errors as soon as they're detected
- Use with other tools: Combine with other linting tools for comprehensive code quality
- Update dictionaries: Keep custom dictionaries updated with domain-specific terminology
If Codespell flags words that are actually correct:
- Add them to the
ignore-words-listin your configuration - Create a custom dictionary file with words to ignore
For large codebases:
- Use the
skipoption to exclude large generated files or binary files - Run Codespell only on changed files during development