Convert Figma logo to code with AI

client9 logomisspell

Correct commonly misspelled English words in source files

1,344
113
1,344
76

Top Related Projects

check code for common misspellings

2,472

Source code spell checker

4,388

:pencil: A markup-aware linter for prose built with speed and extensibility in mind.

4,798

Catch insensitive, inconsiderate writing

1,209

A Spell Checker for Code!

Quick Overview

Misspell is a spell-checker and corrector designed to fix commonly misspelled words in source code. It's particularly useful for catching and correcting typos in comments, strings, and documentation within codebases. The tool can be used as a standalone command-line utility or integrated into various development workflows.

Pros

  • Fast and efficient, capable of processing large codebases quickly
  • Supports multiple file formats and programming languages
  • Can be easily integrated into CI/CD pipelines for automated spell-checking
  • Offers both spell-checking and automatic correction modes

Cons

  • May occasionally produce false positives or miss context-specific misspellings
  • Limited to a predefined list of common misspellings
  • Does not perform grammar checks or more advanced language analysis
  • May require manual review of changes in automatic correction mode

Getting Started

To install and use misspell:

# Install misspell
go install github.com/client9/misspell/cmd/misspell@latest

# Check for misspellings in a file or directory
misspell your_file_or_directory

# Automatically correct misspellings
misspell -w your_file_or_directory

# Ignore specific files or directories
misspell -i vendor/* .

# Use a custom dictionary
misspell -locale UK your_file_or_directory

For more advanced usage and integration options, refer to the project's GitHub repository and documentation.

Competitor Comparisons

check code for common misspellings

Pros of codespell

  • More extensive dictionary with over 10,000 common misspellings
  • Supports multiple programming languages and file formats
  • Actively maintained with regular updates and contributions

Cons of codespell

  • Slower performance on large codebases compared to misspell
  • May produce more false positives due to its larger dictionary
  • Requires Python installation, which may not be ideal for all environments

Code Comparison

misspell:

func main() {
    m := misspell.New()
    m.AddRuleList(misspell.DictMain)
    err := m.ReplaceGlob([]string{"*.txt"})
    if err != nil {
        log.Fatal(err)
    }
}

codespell:

import codespell_lib

if __name__ == "__main__":
    misspelled_words = codespell_lib.check(["*.txt"])
    for word in misspelled_words:
        print(f"Misspelled word: {word}")

Both tools offer similar functionality for detecting and correcting misspellings in text files. misspell is written in Go and focuses on simplicity and speed, while codespell is written in Python and provides more extensive language support and a larger dictionary. The choice between the two depends on specific project requirements, performance needs, and the desired level of customization.

2,472

Source code spell checker

Pros of typos

  • Written in Rust, offering better performance and memory safety
  • Supports custom dictionaries and configuration files
  • Provides more granular control over ignored files and directories

Cons of typos

  • Less mature project with potentially fewer contributors
  • May have a steeper learning curve for users unfamiliar with Rust

Code Comparison

misspell:

func main() {
    m := misspell.New()
    m.AddRuleList(misspell.DictMain)
    err := m.ReplaceGlob([]string{"*.txt"}, true)
    if err != nil {
        log.Fatal(err)
    }
}

typos:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut typos = typos::Typos::new();
    typos.load_default_dictionaries()?;
    typos.walk_files(&["*.txt"])?;
    Ok(())
}

Both tools aim to detect and correct spelling mistakes in text files. misspell is written in Go and has been around longer, potentially offering more stability and a larger user base. It's simpler to use out of the box but may lack some advanced features.

typos, being newer and written in Rust, offers potential performance benefits and more customization options. It allows users to define custom dictionaries and provides finer control over which files to check or ignore. However, it might require more setup and configuration to achieve the desired results.

The code examples demonstrate the basic usage of each tool, highlighting the different approaches in Go and Rust. While misspell's API appears more straightforward, typos offers more flexibility in its configuration.

4,388

:pencil: A markup-aware linter for prose built with speed and extensibility in mind.

Pros of Vale

  • More comprehensive linting capabilities, including style, consistency, and grammar checks
  • Highly customizable with support for custom rules and styles
  • Integrates with various text editors and CI/CD pipelines

Cons of Vale

  • Steeper learning curve due to more complex configuration
  • Slower performance compared to Misspell's focused approach
  • Requires more setup and maintenance for optimal use

Code Comparison

Vale configuration example:

StylesPath = styles
MinAlertLevel = suggestion

[*.md]
BasedOnStyles = Vale, proselint

Misspell usage example:

misspell -w file.txt

Vale offers more extensive configuration options, while Misspell provides a simpler, out-of-the-box solution for quick spell-checking. Vale's flexibility allows for more comprehensive text analysis, but Misspell excels in its straightforward approach to identifying and correcting spelling errors.

4,798

Catch insensitive, inconsiderate writing

Pros of alex

  • Focuses on inclusive and respectful language, not just spelling
  • Supports multiple human languages beyond English
  • Integrates with various text editors and CI/CD pipelines

Cons of alex

  • May produce more false positives due to context-sensitive analysis
  • Requires more configuration to customize rules and exceptions
  • Has a larger package size due to its comprehensive language analysis

Code comparison

alex:

const alex = require('alex');

alex('He\'s pretty set in his ways.').messages;
// [ { message: '`He` may be insensitive, use `They`, `It` instead',
//     name: 'he-she',
//     reason: '`He` may be insensitive, use `They`, `It` instead',
//     line: 1,
//     column: 1,
//     source: 'retext-equality' } ]

misspell:

package main

import "github.com/client9/misspell"

func main() {
    r := misspell.New()
    r.Replace("He's pritty set in his ways.")
    // Output: "He's pretty set in his ways."
}

Both tools aim to improve text quality, but they serve different purposes. misspell focuses solely on correcting spelling errors, while alex addresses a broader range of language issues, including inclusive and respectful communication. misspell is generally faster and more straightforward, while alex offers more comprehensive language analysis at the cost of increased complexity and potential false positives.

1,209

A Spell Checker for Code!

Pros of cspell

  • More comprehensive dictionary with support for multiple languages and specialized vocabularies
  • Customizable configuration options for different file types and project-specific needs
  • Integration with popular IDEs and text editors for real-time spell checking

Cons of cspell

  • Slower performance due to larger dictionary and more complex configuration
  • Higher memory usage, which may impact system resources
  • Steeper learning curve for advanced configuration and customization

Code Comparison

misspell:

func main() {
    m := misspell.New()
    m.AddRuleList(misspell.DictMain)
    err := m.CheckFiles(os.Args[1:])
    if err != nil {
        log.Fatal(err)
    }
}

cspell:

const cspell = require('cspell');

const results = cspell.spellFile('path/to/file.txt', {
    languageId: 'en',
    dictionaries: ['customDictionary'],
    ignoreWords: ['specificword'],
});

console.log(results);

Both tools offer spell checking functionality, but cspell provides more advanced features and customization options. misspell is simpler and faster, making it suitable for quick checks or CI/CD pipelines. cspell is better for comprehensive spell checking across multiple languages and file types, especially in development environments with IDE integration.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status Go Report Card GoDoc Coverage license

Correct commonly misspelled English words... quickly.

Install

If you just want a binary and to start using misspell:

curl -L -o ./install-misspell.sh https://git.io/misspell
sh ./install-misspell.sh

Both will install as ./bin/misspell. You can adjust the download location using the -b flag. File a ticket if you want another platform supported.

If you use Go, the best way to run misspell is by using gometalinter. Otherwise, install misspell the old-fashioned way:

go get -u github.com/client9/misspell/cmd/misspell

and misspell will be in your GOPATH

Also if you like to live dangerously, one could do

curl -L https://git.io/misspell | bash

Usage

$ misspell all.html your.txt important.md files.go
your.txt:42:10 found "langauge" a misspelling of "language"

# ^ file, line, column
$ misspell -help
Usage of misspell:
  -debug
    	Debug matching, very slow
  -error
    	Exit with 2 if misspelling found
  -f string
    	'csv', 'sqlite3' or custom Golang template for output
  -i string
    	ignore the following corrections, comma separated
  -j int
    	Number of workers, 0 = number of CPUs
  -legal
    	Show legal information and exit
  -locale string
    	Correct spellings using locale perferances for US or UK.  Default is to use a neutral variety of English.  Setting locale to US will correct the British spelling of 'colour' to 'color'
  -o string
    	output file or [stderr|stdout|] (default "stdout")
  -q	Do not emit misspelling output
  -source string
    	Source mode: auto=guess, go=golang source, text=plain or markdown-like text (default "auto")
  -w	Overwrite file with corrections (default is just to display)

FAQ

How can I make the corrections automatically?

Just add the -w flag!

$ misspell -w all.html your.txt important.md files.go
your.txt:9:21:corrected "langauge" to "language"

# ^ File is rewritten only if a misspelling is found

How do I convert British spellings to American (or vice-versa)?

Add the -locale US flag!

$ misspell -locale US important.txt
important.txt:10:20 found "colour" a misspelling of "color"

Add the -locale UK flag!

$ echo "My favorite color is blue" | misspell -locale UK
stdin:1:3:found "favorite color" a misspelling of "favourite colour"

Help is appreciated as I'm neither British nor an expert in the English language.

How do you check an entire folder recursively?

Just list a directory you'd like to check

misspell .
misspell aDirectory anotherDirectory aFile

You can also run misspell recursively using the following shell tricks:

misspell directory/**/*

or

find . -type f | xargs misspell

You can select a type of file as well. The following examples selects all .txt files that are not in the vendor directory:

find . -type f -name '*.txt' | grep -v vendor/ | xargs misspell -error

Can I use pipes or stdin for input?

Yes!

Print messages to stderr only:

$ echo "zeebra" | misspell
stdin:1:0:found "zeebra" a misspelling of "zebra"

Print messages to stderr, and corrected text to stdout:

$ echo "zeebra" | misspell -w
stdin:1:0:corrected "zeebra" to "zebra"
zebra

Only print the corrected text to stdout:

$ echo "zeebra" | misspell -w -q
zebra

Are there special rules for golang source files?

Yes! If the file ends in .go, then misspell will only check spelling in comments.

If you want to force a file to be checked as a golang source, use -source=go on the command line. Conversely, you can check a golang source as if it were pure text by using -source=text. You might want to do this since many variable names have misspellings in them!

Can I check only-comments in other other programming languages?

I'm told the using -source=go works well for ruby, javascript, java, c and c++.

It doesn't work well for python and bash.

Does this work with gometalinter?

gometalinter runs multiple golang linters. Starting on 2016-06-12 gometalinter supports misspell natively but it is disabled by default.

# update your copy of gometalinter
go get -u github.com/alecthomas/gometalinter

# install updates and misspell
gometalinter --install --update

To use, just enable misspell

gometalinter --enable misspell ./...

Note that gometalinter only checks golang files, and uses the default options of misspell

You may wish to run this on your plaintext (.txt) and/or markdown files too.

How Can I Get CSV Output?

Using -f csv, the output is standard comma-seprated values with headers in the first row.

misspell -f csv *
file,line,column,typo,corrected
"README.md",9,22,langauge,language
"README.md",47,25,langauge,language

How can I export to SQLite3?

Using -f sqlite, the output is a sqlite3 dump-file.

$ misspell -f sqlite * > /tmp/misspell.sql
$ cat /tmp/misspell.sql

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE misspell(
  "file" TEXT,
  "line" INTEGER,i
  "column" INTEGER,i
  "typo" TEXT,
  "corrected" TEXT
);
INSERT INTO misspell VALUES("install.txt",202,31,"immediatly","immediately");
# etc...
COMMIT;
$ sqlite3 -init /tmp/misspell.sql :memory: 'select count(*) from misspell'
1

With some tricks you can directly pipe output to sqlite3 by using -init /dev/stdin:

misspell -f sqlite * | sqlite3 -init /dev/stdin -column -cmd '.width 60 15' ':memory' \
    'select substr(file,35),typo,count(*) as count from misspell group by file, typo order by count desc;'

How can I ignore rules?

Using the -i "comma,separated,rules" flag you can specify corrections to ignore.

For example, if you were to run misspell -w -error -source=text against document that contains the string Guy Finkelshteyn Braswell, misspell would change the text to Guy Finkelstheyn Bras well. You can then determine the rules to ignore by reverting the change and running the with the -debug flag. You can then see that the corrections were htey -> they and aswell -> as well. To ignore these two rules, you add -i "htey,aswell" to your command. With debug mode on, you can see it print the corrections, but it will no longer make them.

How can I change the output format?

Using the -f template flag you can pass in a golang text template to format the output.

One can use printf "%q" VALUE to safely quote a value.

The default template is compatible with gometalinter

{{ .Filename }}:{{ .Line }}:{{ .Column }}:corrected {{ printf "%q" .Original }} to "{{ printf "%q" .Corrected }}"

To just print probable misspellings:

-f '{{ .Original }}'

What problem does this solve?

This corrects commonly misspelled English words in computer source code, and other text-based formats (.txt, .md, etc).

It is designed to run quickly so it can be used as a pre-commit hook with minimal burden on the developer.

It does not work with binary formats (e.g. Word, etc).

It is not a complete spell-checking program nor a grammar checker.

What are other misspelling correctors and what's wrong with them?

Some other misspelling correctors:

They all work but had problems that prevented me from using them at scale:

  • slow, all of the above check one misspelling at a time (i.e. linear) using regexps
  • not MIT/Apache2 licensed (or equivalent)
  • have dependencies that don't work for me (python3, bash, linux sed, etc)
  • don't understand American vs. British English and sometimes makes unwelcome "corrections"

That said, they might be perfect for you and many have more features than this project!

How fast is it?

Misspell is easily 100x to 1000x faster than other spelling correctors. You should be able to check and correct 1000 files in under 250ms.

This uses the mighty power of golang's strings.Replacer which is a implementation or variation of the Aho–Corasick algorithm. This makes multiple substring matches simultaneously.

In addition this uses multiple CPU cores to work on multiple files.

What problems does it have?

Unlike the other projects, this doesn't know what a "word" is. There may be more false positives and false negatives due to this. On the other hand, it sometimes catches things others don't.

Either way, please file bugs and we'll fix them!

Since it operates in parallel to make corrections, it can be non-obvious to determine exactly what word was corrected.

It's making mistakes. How can I debug?

Run using -debug flag on the file you want. It should then print what word it is trying to correct. Then file a bug describing the problem. Thanks!

Why is it making mistakes or missing items in golang files?

The matching function is case-sensitive, so variable names that are multiple worlds either in all-upper or all-lower case sometimes can cause false positives. For instance a variable named bodyreader could trigger a false positive since yrea is in the middle that could be corrected to year. Other problems happen if the variable name uses a English contraction that should use an apostrophe. The best way of fixing this is to use the Effective Go naming conventions and use camelCase for variable names. You can check your code using golint

What license is this?

The main code is MIT.

Misspell also makes uses of the Golang standard library and contains a modified version of Golang's strings.Replacer which are covered under a BSD License. Type misspell -legal for more details or see legal.go

Where do the word lists come from?

It started with a word list from Wikipedia. Unfortunately, this list had to be highly edited as many of the words are obsolete or based from mistakes on mechanical typewriters (I'm guessing).

Additional words were added based on actually mistakes seen in the wild (meaning self-generated).

Variations of UK and US spellings are based on many sources including:

American English is more accepting of spelling variations than is British English, so "what is American or not" is subject to opinion. Corrections and help welcome.

What are some other enhancements that could be done?

Here's some ideas for enhancements:

Capitalization of proper nouns could be done (e.g. weekday and month names, country names, language names)

Opinionated US spellings US English has a number of words with alternate spellings. Think adviser vs. advisor. While "advisor" is not wrong, the opinionated US locale would correct "advisor" to "adviser".

Versioning Some type of versioning is needed so reporting mistakes and errors is easier.

Feedback Mistakes would be sent to some server for agregation and feedback review.

Contractions and Apostrophes This would optionally correct "isnt" to "isn't", etc.