Skip to content

Repository files navigation

spell-checkr

Grammar and spell checker for English prose in pure Go with zero dependencies. Ships as a native CLI, an LSP server, an HTTP lint API, a WebAssembly module built with TinyGo, and a browser extension for Chrome and Firefox.

Install

make build

Usage

spell-checkr file.txt
echo "Their is a error" | spell-checkr
spell-checkr -json file.txt
spell-checkr --fix file.txt        # print corrected text
spell-checkr -w file.txt           # fix in place
spell-checkr -dialect american -disable style,spacing file.txt
spell-checkr -dict mywords.txt file.txt
spell-checkr -rules                # list lint kinds
spell-checkr --version
spell-checkr lsp                   # language server on stdio
spell-checkr serve :8080           # HTTP API and web demo
spell-checkr serve -maxinflight 64 -pprof :8080
spell-checkr -cpuprofile cpu.out -memprofile mem.out big.txt

The serve subcommand exposes POST /lint (plain text or a JSON body with text, dialect, disable, extraWords), GET /rules, GET /healthz, and GET /version. POST /lint?stream=1 returns NDJSON with one lint array per paragraph as analysis completes. Requests are capped at 4 MB and concurrent analyses are bounded by -maxinflight.

Code spans, fenced blocks, URLs, emails, HTML tags, markdown link targets, and YAML front matter are skipped automatically. Add "spell-checkr-ignore" on a line to suppress its lints, or "spell-checkr-ignore-next" for the following line.

Source code comments

Passing a source file (main.go, app.py, lib.rs, ...) lints only its comments. String literals and code are skipped. Override detection with -lang:

spell-checkr main.go          # only // and /* */ comments checked
spell-checkr -lang python s.py
spell-checkr -lang text s.py  # treat as plain prose

Lint kinds and rules

Kinds: spelling, grammar, capitalization, repetition, spacing, punctuation, style, dialect, confusable.

Named rules (disable with -disable name): spelling, repeated-word, articles, confusables, their-there, through-threw, phrases, double-negative, capitalization, proper-nouns, pronoun-i, spacing, long-sentence, terminal-punctuation, unclosed-pairs, ellipsis, emphatic-punctuation, number-suffix, spelled-numbers, hedging, intensifiers, sequential-pronouns, oxford-comma, everyday, anaphora, dialect, subject-aux-agreement, det-noun-agreement, numeral-noun, more-er, good-well, absolute-adjectives, modal-verb, subject-verb-agreement, be-participle, adj-as-adverb, mass-noun, det-subject-agreement, prep-collocation, plural-after-of, formally-formerly, discourse-comma, concessive-comma, word-form, contractions, of-or-pronoun, perfect-base, past-frame.

Coverage includes confusable contexts, phrase fixes for eggcorns and redundancies, double negatives, missing auxiliaries, POS agreement ("you is", "she run", "could went", "these dog", "5 cat"), comparatives ("more easy"), ordinals, and US/UK spellings.

The POS tagger is a trigram HMM trained on the UD English EWT corpus with deterministic corrections and a suffix model for unknown words. Regenerate its tables with make pos.

Markdown structure is understood. Headings, list items, table rows, and quotes get relaxed rules, and emphasis markers are stripped before analysis.

Repeated analysis is incremental. The LSP server and HTTP API cache paragraph-level results, so re-linting after an edit only recomputes changed paragraphs.

WASM

make wasm   # requires tinygo 0.42+

Exports spellCheckrLint(text, optsJSON) returning a JSON array of lints with UTF-16 offsets, plus spellCheckrDictSize and spellCheckrKinds. optsJSON accepts dialect, disable, extraWords, and lang.

Browser extension

make ext

Produces dist/spell-checkr-chrome.zip, dist/spell-checkr-chrome.crx (when chromium is installed), and dist/spell-checkr-firefox.xpi. The extension underlines issues in textareas and contenteditable fields. Click a flagged word to apply a fix. All analysis runs locally in the service worker.

Editor integrations

VS Code: editors/vscode/build.sh produces dist/spell-checkr-vscode.vsix. Install with code --install-extension dist/spell-checkr-vscode.vsix.

Neovim:

vim.lsp.start({ cmd = { "spell-checkr", "lsp" },
                root_dir = vim.fn.getcwd() })

Helix (languages.toml):

[language-server.spell-checkr]
command = "spell-checkr"
args = ["lsp"]

Development

make test    # unit and golden corpus tests
make bench   # benchmarks with allocation counts
make fuzz    # tokenizer and analyzer fuzz targets
make dict    # regenerate the word list
make pos     # regenerate the POS tables from UD English EWT
make misspell  # regenerate synthesized misspelling data

License

Code: Apache-2.0. Bundled data files are licensed as described in NOTICE, internal/dict/LICENSE.txt, and internal/pos/LICENSE.txt.

About

fast and accurate spell checker and grammar corrector.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages