Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
hunspelland/or
languagetool.
Run
cargo spellcheck --fixor
cargo spellcheck fixto fix all your documentation comments in order to avoid narsty typos all over your source tree. Meant as a helper simplifying review as well as improving CI checks after a learning phase for custom/topic specifc lingo.
cargo spellcheck check
error: spellcheck --> src/main.rs:44 | 44 | Fun facets shalld cause some erroris. | ^^^^^^ | - shall or shall d |
cargo spellcheck fix
error: spellcheck(Hunspell) --> /media/supersonic1t/projects/cargo-spellcheck/src/literalset.rs:291 | 291 | Returns literl within the Err variant if not adjacent | ^^^^^^(13/14) Apply this suggestion [y,n,q,a,d,j,e,?]?
lite litter litterer liter l liters literal liter » a custom replacement literal
cargo spellcheckcan be configured with
-m
to return a non-zero
return code if mistakes are found instead of 0.
#!/usr/bin/shRedirect output to stderr.
exec 1>&2
exec cargo spellcheck -m 99 $(git diff-index --cached --name-only --diff-filter=AM HEAD)
cargo-spellcheck check
hunspell
languagetoolhttp API
commonmark/
markdownaware
README.mdfiles #37
crossterm
...#42
hunspelland
languagetoolare currently the two supported featuresets.
# Project settings where a Cargo.toml exists and is passed # ${CARGO_MANIFEST_DIR}/.config/spellcheck.tomlAlso take into account developer comments
dev_comments = false
Skip the README.md file as defined in the cargo manifest
skip_readme = false
Fallback to per use configuration files:
Linux: /home/alice/.config/cargo_spellcheck/config.toml
Windows: C:\Users\Alice\AppData\Roaming\cargo_spellcheck\config.toml
macOS: /Users/Alice/Library/Preferences/cargo_spellcheck/config.toml
[LanguageTool] url = "127.0.0.1:8010"
[Hunspell]
lang and name of
.dic
filelang = "en_US"
OS specific additives
Linux: [ /usr/share/myspell ]
Windows: []
macOS [ /home/alice/Libraries/hunspell, /Libraries/hunspell ]
Additional search paths, which take presedence over the default
os specific search dirs, searched in order, defaults last
search_dirs = []
Adds additional dictionaries, can be specified as
absolute paths or relative in the search dirs (in this order).
Relative paths are resolved relative to the configuration file
which is used.
Refer to
man 5 hunspell
or https://www.systutorials.com/docs/linux/man/4-hunspell/#lbAE
on how to define a custom dictionary file.
extra_dictionaries = []
[Hunspell.quirks]
Transforms words that are provided by the tokenizer
into word fragments based on the capture groups which are to
be checked.
If no capture groups are present, the matched word is whitelisted.
transform_regex = ["^'([^\s])'$", "^[0-9]+x$"]
Accepts
alphabeta
variants if the checker provides a replacement suggestionof
alpha-beta
.allow_concatenation = true
And the counterpart, which accepts words with dashes, when the suggestion has
recommendations without the dashes. This is less common.
allow_dashed = false
[NlpRules]
Allows the user to override the default included
exports of LanguageTool, with other custom
languages
override_rules = "/path/to/rules_binencoded.bin"
override_tokenizer = "/path/to/tokenizer_binencoded.bin"
[Reflow]
Reflows doc comments to adhere to adhere to a given maximum line width limit.
max_line_length = 80
To increase verbosity add
-v(multiple) to increase verbosity.
cargo install cargo-spellcheck
Available checker support
Requires a C++ compiler to compile the hunspell CXX source files which are part of
hunspell-sys
dnf install -y clang
apt install -y clang
brew install llvm
The environment variable
LLVM_CONFIG_PATHneeds to point to
llvm-config, to do so:
export LLVM_CONFIG_PATH=/usr/local/opt/llvm/bin/llvm-config
When compiled with the default featureset which includes
nlprules, the resulting binary can only be distributed under the
LGPLv2.1since the
rulesand
tokenizerdefinitions are extracted from
LanguageTool(which is itself licensed under
LGPLv2.1) as described by the library that is used for pulling and integrating - details are to be found under crate
nlprule's README.md.
Deprecated!
You must run an instance of the LanguageTool server i.e. as container.