Fix common misspellings in text files. It's designed primarily for checking misspelled words in source code (backslash escapes are skipped), but it can be used with other files as well. It does not check for word membership in a complete dictionary, but instead looks for a set of common misspellings. Therefore it should catch errors like "adn", but it will not catch "adnasdfasdf". This also means it shouldn't generate false-positives when you use a niche term it doesn't know about.
Python 3.8 or above.
You can use pip to install codespell with e.g.:
pip install codespell
Below are some simple usage examples to demonstrate how the tool works.
For exhaustive usage information, please check the output of codespell -h.
Run codespell in all files of the current directory:
codespell
Run codespell in specific files or directories (specified via their names or glob patterns):
codespell some_file some_dir/ *.ext
Some noteworthy flags:
codespell -w, --write-changes
The -w flag will actually implement the changes recommended by codespell. Running without the -w flag is the same as doing a dry run. It is recommended to run this with the -i or --interactive flag.
codespell -I FILE, --ignore-words=FILE
The -I flag can be used for a list of certain words to allow that are in the codespell dictionaries. The format of the file is one word per line. Invoke using: codespell -I path/to/file.txt to execute codespell referencing said list of allowed words. See Ignoring Words for more details.
codespell -L word1,word2,word3,word4
The -L flag can be used to allow certain words that are comma-separated placed immediately after it. See Ignoring Words for more details.
codespell -x FILE, --exclude-file=FILE
Ignore whole lines that match those in FILE. The lines in FILE should match the to-be-excluded lines exactly.
codespell -S, --skip=
Comma-separated list of files to skip. It accepts globs as well. Examples:
codespell --skip="*.eps,*.txt"
codespell --skip="./src/3rd-Party,./src/Test"
Useful commands:
codespell -d -q 3 --skip="*.po,*.ts,./src/3rdParty,./src/Test"
List all typos found except translation files and some directories. Display them without terminal colors and with a quiet level of 3.
codespell -i 3 -w
Run interactive mode level 3 and write changes to file.
We ship a collection of dictionaries that are an improved version of the one available
echo "word" | codespell -
echo "1stword,2ndword" | codespell -
You can select the optional dictionaries with the When ignoring false positives, note that spelling errors are case-insensitive but words to ignore are case-sensitive. For example, the dictionary entry The words to ignore can be passed in two ways: Some situation might require ignoring a specific word in a specific location. This can be achieved by adding a comment in the source code.
You can either ignore a single word or a list of words. The comment should be in the format of ignore specific word: ignore multiple words: Command line options can also be specified in a config file. When running Python's
tomli package. For example, here is the TOML equivalent of the
previous config file: The above INI and TOML files are equivalent to running: If several config files are present, they are read in the following order: If a codespell configuration is supplied in several of these files,
the configuration from the most recently read file overwrites previously
specified configurations. Any options specified in the command line will
override options from the config files. Values in a config file entry cannot start with a instead of these invalid entries: codespell also works with
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
If one configures codespell using the pyproject.toml file instead use: The format of the dictionaries was influenced by the one they originally came from,
i.e. from Wikipedia. The difference is how multiple options are treated and
that the last argument is an optional reason why a certain entry could not be
applied directly, but should instead be manually inspected. E.g.: Simple entry: one wrong word / one suggestion: Entry with more than one suggested fix: Note the last comma! You need to use it, otherwise the last suggestion
will be discarded (see below for why). When there is more than one
suggestion, an automatic fix is not possible and the best we can do is
to give the user the file and line where the error occurred as well as
the suggestions. Entry with one word, but with automatic fix disabled: Note that there isn't a comma at the end of the line. The last argument is
treated as the reason why a suggestion cannot be automatically applied. There can also be multiple suggestions but any automatic fix will again be
disabled: As suggested in the
pip install --upgrade pip setuptools setuptools_scm wheel
You can install required dependencies for development by running the following within a checkout of the codespell source: To run tests against the codebase run: If you have a suggested typo that you'd like to see merged please follow these steps: Make sure you read the instructions mentioned in the Choose the correct dictionary file to add your typo to. See codespell --help for explanations of the different dictionaries. Sort the dictionaries. This is done by invoking (in the top level directory of If the make script finds that you need to sort a dictionary, please then run: Only after this process is complete do we recommend you submit the PR. Important Notes: To stay current with codespell developments it is possible to build codespell from GitHub via: Important Notes: Sometimes installing via It has been reported that after installing from If you decide to install via In the scenario where the user prefers not to follow the development version of codespell yet still opts to benefit from the frequently updated dictionary files, we recommend running a simple set of commands to achieve this: The above simply downloads the latest The Python script Copyright (C) 2011 ProFUSION embedded systems This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. You should have received a copy of the GNU General Public License
along with this program; if not, see
<Creative Commons Attribution-Share-Alike License 3.0.--builtin option.
Ignoring words
wrod will also match the typo Wrod, but to ignore it you must pass wrod (to match the case of the dictionary entry).
-I: A file with a word per line to ignore:
codespell -I FILE, --ignore-words=FILE
-L: A comma separated list of words to ignore on the command line:
codespell -L word1,word2,word3,word4
Inline ignore
codespell:ignore <words>.
Words should be separated by a comma.
def wrod() # codespell:ignore wrod
pass
def wrod(wrods) # codespell:ignore
pass
Using a config file
codespell, it will check in the current directory for an
[codespell]
skip = *.po,*.ts,./src/3rdParty,./src/Test
count =
quiet-level = 3
[tool.codespell]
skip = '*.po,*.ts,./src/3rdParty,./src/Test'
count = true
quiet-level = 3
codespell --skip "*.po,*.ts,./src/3rdParty,./src/Test" --count --quiet-level 3
pyproject.toml (only if the tomli library is available for Python < 3.11)setup.cfg.codespellrc--config
- character, so if
you need to do this, structure your entries like this:
[codespell]
dictionary = mydict,-
ignore-words-list = bar,-foo
[codespell]
dictionary = -,mydict
ignore-words-list = -foo,bar
pre-commit hook
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
- tomli
Dictionary format
calulated->calculated
fiel->feel, field, file, phial,
clas->class, disabled because of name clash in c++
clas->class, clash, disabled because of name clash in c++
Development setup
pip install -e ".[dev]"
make check
Sending pull requests
Dictionary format section above to submit correctly formatted entries.codespell/):
make check-dictionaries
make sort-dictionaries
Updating
pip install --upgrade git+https://github.com/codespell-project/codespell.git
pip will complain about permissions. If this is the case then run with:
pip install --user --upgrade git+https://github.com/codespell-project/codespell.git
pip, codespell can't be located. Please check the $PATH variable to see if ~/.local/bin is present. If it isn't then add it to your path.pip then be sure to remove any previously installed versions of codespell (via your platform's preferred app manager).
Updating the dictionaries
wget https://raw.githubusercontent.com/codespell-project/codespell/main/codespell_lib/data/dictionary.txt
codespell -D dictionary.txt
dictionary.txt file and then by utilizing the -D flag allows the user to specify the freshly downloaded dictionary.txt as the custom dictionary instead of the default one.
codespell with its library codespell_lib is available
with the following terms:
(tl;dr: lucas.de.marchi@gmail.com>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。