cargo-spellcheck: hunspell and nlprule checks for Rust doc comments
Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
At a glance
- What is it?
- cargo-spellcheck is a cargo subcommand that runs hunspell and an nlprule-based grammar checker over your doc comments, README and markdown, and can apply replacements interactively. It is aimed at Rust maintainers who want typo checks in review and CI, and its setup cost is real.
- Who is it for?
- Adopt cargo-spellcheck if you maintain a Rust crate whose public documentation is part of its interface and you are willing to maintain a dictionary of project lingo. Do not adopt it if you need a grammar checker that works out of the box on non-English prose, or if you cannot install libclang on your build machines: the README's Linux path is apt-get install libclang-dev plus LIBCLANG_PATH, and macOS needs DYLD_FALLBACK_LIBRARY_PATH pointed at the Xcode toolchain.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 5 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- drahnr/cargo-spellcheck361 ★ · -2
| Repository | 2026-09-17 | 2026-11-24 |
|---|---|---|
| drahnr/cargo-spellcheck | 363 | 361 |
-2 Stars in the last 68 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The problem: typos in doc comments survive review
Rust puts documentation in the same file as the code, which is convenient for writers and bad for typos. A misspelled word inside a doc comment compiles fine, passes cargo check, and reaches docs.rs. Human review catches some of it; reviewers skim prose when the diff is mostly logic. cargo-spellcheck exists to move that class of mistake into an automated check, and the README frames the audience directly: it is "meant as a helper simplifying review as well as improving CI checks after a learning phase for custom/topic specific lingo." That last clause matters. This is not a tool you drop in and forget. It expects you to teach it your vocabulary first.
The scope is documentation, not identifiers. The README's examples point at src/main.rs and src/literalset.rs, and the check output is rendered in rustc's error format, with a file, a line number, a caret under the offending token, and a suggestion. The repository also carries a doc-chunks workspace member and depends on pulldown-cmark, so markdown is part of what it parses, not only Rust source.
How the hunspell and nlprule checkers fit together
The README's one-line description is the whole architecture: "Check your spelling with `hunspell` and/or `nlprule`." Two distinct engines sit behind one command. hunspell is the classic dictionary and affix engine, and the repository ships hunspell-data/ so the tool has dictionaries to work from without a system-wide install. nlprule is the grammar side, and the repository ships nlprule-data/ as compressed .bin.xz artifacts; the build script depends on nlprule-build and xz2, and a comment in Cargo.toml explains why the compression exists: "compress the nlprule artifacts to be under the 10 MB limit that cargo enforces." That is a packaging constraint shaping the design, not a stylistic choice.
The dependency list shows how a run is assembled. syn with span-locations parses Rust source and gives byte spans back to the checker, which is how the tool can print a line and column the way rustc does. proc-macro2 with span-locations supports the same. rayon and num_cpus appear in the dependency set, so checking is parallelised across files. glob and ignore handle file selection, and the ignore crate means .gitignore semantics apply to what gets walked. cargo_toml and toml are there because the tool reads Cargo.toml, which is how it finds the crate and its layout. fancy-regex, regex and memchr support the filtering machinery that decides what is worth checking.
One consequence of the two-engine design is that a single run can produce two different kinds of finding. The README's fix example labels its output spellcheck(Hunspell), which tells you the checker that raised it. If you configure only hunspell, you get dictionary lookups and no grammar analysis; if you configure only nlprule, you get grammar and no dictionary coverage. The configuration surface lives in docs/configuration.md, which the README links but does not reproduce.
Installing cargo-spellcheck and running a first check
The README gives one install command and recommends the locked variant: "The `--locked` flag is the preferred way of installing to get the tested set of dependencies."
cargo install --locked cargo-spellcheckThe published crate declares rust-version = "1.85.0" in Cargo.toml, so an older toolchain will refuse the build. The tool links against clang, and the README treats this as the main installation friction. On Linux the README gives apt-get install libclang-dev, then asks you to point the linker at the library:
export LIBCLANG_PATH=/usr/lib/llvm-14/lib/On macOS the README says to make libclang.dylib findable and shows this export, note the spelling in the README, which writes DYLB_FALLBACK_LIBRARY_PATH in the prose but exports DYLD_FALLBACK_LIBRARY_PATH in the code block:
export DYLD_FALLBACK_LIBRARY_PATH= \
"$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/lib/"With the binary installed, the first real use is a check across the crate. Run it from the crate root:
cargo spellcheck checkExpect rustc-style output: an error line, an arrow to file and line, and the offending token underlined with a suggested replacement. The README's example flags "Fun facets shalld cause some erroris." at src/main.rs:44 and offers shall or shall d. To act on findings one at a time, use the interactive mode:
cargo spellcheck fixThis walks findings and prompts with (13/14) Apply this suggestion [y,n,q,a,d,j,e,?]?, listing candidates and allowing a custom replacement. Shell completion is available too, either autodetected from $SHELL or explicit:
cargo spellcheck completions --shell zshWhere cargo-spellcheck gets in the way
The README's own example is the best argument for caution. For shalld it suggests "shall or shall d". A reviewer who accepts suggestions without reading them will introduce new errors, which is why the default mode is check and the fix mode is interactive rather than batch. If you want this in CI, plan for the check subcommand and a non-zero exit, not the fixer.
Dictionaries are the second problem. hunspell dictionaries are per-language, and the README's learning-phase remark acknowledges that domain vocabulary needs to be added before the tool stops complaining. Crate names, type names, protocol names and product spellings all read as errors to a general dictionary. The repository ships hunspell-data/ and nlprule-data/, but the README does not document how to extend or replace those dictionaries; that detail is deferred to docs/configuration.md and docs/remedy.md, both linked and neither reproduced in the README.
The clang dependency is the third. A tool that checks prose should not require a C toolchain to build, and this one does. That is a packaging decision inherited from the nlprule build path, and it is the reason the README spends more space on linker environment variables than on the checker itself. On a minimal CI image you will be installing libclang before you can spell-check anything.
Finally, the tool checks documentation. It will not validate that your doc examples compile, and it will not check identifiers, so a misspelled function name is outside its remit. If your actual problem is broken doctests, this is the wrong tool.
cargo spellcheck versus typos and LanguageTool
The closest alternative in the Rust ecosystem is typos, a single-binary spell checker that works on source trees without a C toolchain and without a dictionary service. The difference in approach is the checker model. typos maintains its own curated dictionary of common misspellings and corrections, which makes it fast and dependency-free but narrow: it corrects known errors rather than validating words against a full language dictionary. cargo-spellcheck does the opposite. It delegates to hunspell for full dictionary coverage and to nlprule for grammar, which is broader and slower and brings the clang build requirement with it. If you want a check that runs anywhere with no setup, typos wins on logistics. If you want grammar findings and a real dictionary, cargo-spellcheck is the one that does that.
LanguageTool is the other reference point, and the project's own topic list includes languagetool alongside hunspell and nlprule. LanguageTool is a general-purpose grammar checker with a large rule set and a server mode; cargo-spellcheck embeds nlprule instead, which keeps the check local and offline but with a smaller rule set. The trade-off is coverage against self-containment. Note that the README does not describe a LanguageTool integration, only nlprule; the topic tag is not documentation.
One more distinction worth naming: cargo spellcheck is a cargo subcommand, so it understands crate layout and can be invoked as cargo spellcheck from the crate root. A generic spell checker has to be told which files to look at.
Maintenance, releases and licence
The repository is not archived. The last push was on 2026-05-18, and the most recent release v0.15.7 was tagged on 2026-05-01. The gap between that release and its predecessor is notable: v0.15.5 is dated 2025-03-18, roughly a year earlier, with v0.15.4 shortly before it on 2025-03-10. So the release cadence is not uniform, and a patch-level bump from 0.15.5 to 0.15.7 over a year is the kind of signal you check yourself against CHANGELOG.md before pinning a version in CI.
The Cargo.toml declares license = "MIT OR Apache-2.0", while the repository root carries LICENSE-APACHE, LICENSE-MIT and LICENSE-LGPL. The LGPL file is not reflected in the package metadata. That mismatch is worth resolving with the project before you vendor or redistribute the crate, and it is a question for the maintainer rather than something to infer. The package metadata is also what crates.io and downstream tooling will read, so the effective terms for a normal cargo install are the dual MIT OR Apache-2.0 grant named in Cargo.toml. This is not legal advice; if your organisation has a licence review process, the three licence files at the root are what it will want to look at.
Upgrade cost is mostly dictionary and data churn. The nlprule data is pinned through nlprule-build = "=0.6.4" in the build dependencies, an exact pin, so an upgrade of the data path is deliberate rather than incidental. The MSRV is declared as 1.85.0; moving it forward is a breaking change for anyone on an older toolchain, and the README does not describe a policy for MSRV bumps.
Editorial conclusion
Adopt cargo-spellcheck if you maintain a Rust crate whose public documentation is part of its interface and you are willing to maintain a dictionary of project lingo. Do not adopt it if you need a grammar checker that works out of the box on non-English prose, or if you cannot install libclang on your build machines: the README's Linux path is apt-get install libclang-dev plus LIBCLANG_PATH, and macOS needs DYLD_FALLBACK_LIBRARY_PATH pointed at the Xcode toolchain. Before rolling it into CI, run cargo spellcheck fix on one module and read the prompt carefully, because the README's own example shows the checker suggesting shall d for shalld, and that is the class of suggestion you have to reject by hand.
Frequently asked questions
What has happened to spell check?
In this project it is a cargo subcommand rather than an editor feature. cargo spellcheck check runs hunspell and/or nlprule over your documentation and prints rustc-style errors with a file, line and suggested replacement.
How do I turn on automatic spell check for a Rust crate?
Install with cargo install --locked cargo-spellcheck, then run cargo spellcheck check from the crate root. The README also describes running it from git commit hooks or CI/CD systems, and cargo spellcheck fix applies suggestions interactively.
What is the best free spell checker for Rust documentation?
The README does not rank spell checkers, so there is no supported answer here. What can be said is that cargo-spellcheck is Apache-2.0 or MIT licensed per its Cargo.toml, uses hunspell and nlprule, and is installable from crates.io.
Why is my spell check suddenly in a different language?
The README does not document language selection or how the active hunspell dictionary is chosen. Dictionaries ship in the repository's hunspell-data directory, and the linked docs/configuration.md is where configuration is described.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/drahnr-cargo-spellcheck)Star history chart for your README
[](https://hysenlabs.com/projects/drahnr-cargo-spellcheck)Was this useful?