typos/README.md

188 lines
5.6 KiB
Markdown
Raw Normal View History

2019-07-03 21:22:36 -04:00
# typos
2019-01-22 17:01:33 -05:00
2019-07-03 21:22:36 -04:00
> **Source code spell checker**
2019-01-22 17:01:33 -05:00
Finds and corrects spelling mistakes among source code:
- Fast enough to run on monorepos
- Low false positives so you can run on PRs
2021-05-19 20:48:33 -04:00
![Screenshot](./docs/screenshot.png)
2019-10-25 09:49:41 -04:00
[![codecov](https://codecov.io/gh/crate-ci/typos/branch/master/graph/badge.svg)](https://codecov.io/gh/crate-ci/typos)
2019-01-22 17:01:33 -05:00
[![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation]
2019-07-03 21:22:36 -04:00
![License](https://img.shields.io/crates/l/typos.svg)
2023-10-06 16:04:55 -04:00
[![Crates Status](https://img.shields.io/crates/v/typos.svg)][Crates.io]
2019-01-22 17:01:33 -05:00
Dual-licensed under [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE)
2019-01-22 17:01:33 -05:00
## Documentation
2019-01-22 17:01:33 -05:00
- [Installation](#install)
2021-05-28 09:33:44 -04:00
- [Getting Started](#getting-started)
- [False Positives](#false-positives)
- [Integrations](#integrations)
- [GitHub Action](docs/github-action.md)
2021-06-08 15:54:38 -04:00
- [pre-commit](docs/pre-commit.md)
2021-05-31 20:51:03 -04:00
- [Custom](#custom)
- [Debugging](#debugging)
- [Reference](docs/reference.md)
2021-07-27 16:22:17 -04:00
- [FAQ](#faq)
- [Comparison with other spell checkers](docs/comparison.md)
- [Projects using typos](https://github.com/crate-ci/typos/wiki)
- [Benchmarks](benchsuite/runs)
- [Design](docs/design.md)
- [Contribute](CONTRIBUTING.md)
- [CHANGELOG](CHANGELOG.md)
2019-01-22 17:01:33 -05:00
## Install
2019-01-22 17:01:33 -05:00
[Download](https://github.com/crate-ci/typos/releases) a pre-built binary
2021-05-19 20:54:51 -04:00
(installable via [gh-install](https://github.com/crate-ci/gh-install)).
2019-01-22 17:01:33 -05:00
Or use rust to install:
```bash
cargo install typos-cli
```
Or use [Homebrew](https://brew.sh/) to install:
```bash
brew install typos-cli
```
Or use [Conda](https://conda.io/) to install:
```bash
conda install typos
```
2024-02-17 03:42:28 -05:00
Or use [Pacman](https://wiki.archlinux.org/title/pacman) to install:
```
sudo pacman -S typos
```
2021-05-28 09:33:44 -04:00
## Getting Started
Most commonly, you'll either want to see what typos are available with
```bash
typos
```
Or have them fixed
```bash
typos --write-changes
typos -w
```
If there is any ambiguity (multiple possible corrections), `typos` will just report it to the user and move on.
### False-positives
Sometimes, what looks like a typo is intentional, like with people's names, acronyms, or localized content.
2023-02-01 07:43:38 -05:00
To mark a word or an identifier (grouping of words) as valid, add it your [`_typos.toml`](docs/reference.md) by declaring itself as the valid spelling:
2021-05-28 09:33:44 -04:00
```toml
[default]
extend-ignore-identifiers-re = [
# *sigh* this just isn't worth the cost of fixing
2023-08-14 16:55:39 -04:00
"AttributeID.*Supress.*",
]
2021-05-28 09:33:44 -04:00
[default.extend-identifiers]
# *sigh* this just isn't worth the cost of fixing
2023-08-14 16:55:39 -04:00
AttributeIDSupressMenu = "AttributeIDSupressMenu"
2021-05-28 09:33:44 -04:00
[default.extend-words]
2023-08-14 16:55:39 -04:00
# Don't correct the surname "Teh"
teh = "teh"
2021-05-28 09:33:44 -04:00
```
2021-05-28 20:07:20 -04:00
For cases like localized content, you can disable spell checking of file contents while still checking the file name:
2021-05-28 19:42:09 -04:00
```toml
[type.po]
extend-glob = ["*.po"]
2021-05-28 19:42:09 -04:00
check-file = false
```
(run `typos --type-list` to see configured file types)
2021-05-28 20:07:20 -04:00
If you need some more flexibility, you can completely exclude some files from consideration:
2021-05-28 09:33:44 -04:00
```toml
[files]
extend-exclude = ["localized/*.po"]
```
### Integrations
- [GitHub Actions](docs/github-action.md)
2021-06-08 15:54:38 -04:00
- [pre-commit](docs/pre-commit.md)
- [🐊Putout Processor](https://github.com/putoutjs/putout-processor-typos)
- [Visual Studio Code](https://github.com/tekumara/typos-vscode)
2023-09-22 21:03:46 -04:00
- [typos-lsp (Language Server Protocol server)](https://github.com/tekumara/typos-vscode)
2021-05-31 20:51:03 -04:00
#### Custom
`typos` provides several building blocks for custom native integrations
2021-05-28 09:33:44 -04:00
- `-` reads from `stdin`, `--write-changes` will be written to `stdout`
- `--diff` to provide a diff
- `--format json` to get jsonlines with exit code 0 on no errors, code 2 on typos, anything else is an error.
Examples:
```bash
# Read file from stdin, write corrected version to stdout
typos - --write-changes
# Creates a diff of what would change
typos dir/file --diff
# Fully programmatic control
typos dir/file --format json
```
2021-05-28 19:37:01 -04:00
### Debugging
You can see what the effective config looks like by running
```bash
typos --dump-config -
```
You can then see how typos is processing your project with
```bash
typos --files
typos --identifiers
2021-05-28 20:08:24 -04:00
typos --words
2021-05-28 19:37:01 -04:00
```
If you need to dig in more, you can enable debug logging with `-v`
2021-07-27 16:22:17 -04:00
## FAQ
### Why was ... not corrected?
**Does the file show up in `typos --files`?**
If not, check your config with `typos --dump-config -`.
The `[files]` table controls how we walk files.
If you are using `files.extend-exclude`,
are you running into [#593](https://github.com/crate-ci/typos/issues/593)?
If you are using `files.ignore-vcs = true`,
is the file in your `.gitignore` but git tracks it anyways?
Prefer allowing the file explicitly (see [#909](https://github.com/crate-ci/typos/issues/909)).
**Does the identifier show up in `typos --identifers` or the word show up in `typos --words`?**
If not, it might be subject to one of typos' heuristics for
detecting non-words (like hashes) or
unambiguous words (like words after a `\` escape).
If it is showing up, likely `typos` doesn't know about it yet.
2021-07-27 16:22:17 -04:00
`typos` maintains a list of known typo corrections to keep the false positive
count low so it can safely run unassisted.
This is in contrast to most spell checking UIs people use where there is a
known list of valid words. In this case, the spell checker tries to guess your
intent by finding the closest-looking word. It then has a gauge for when a
word isn't close enough and assumes you know best. The user has the
opportunity to verify these corrections and explicitly allow or reject them.
For more on the trade offs of these approaches, see [Design](docs/design.md).
- To correct it locally, see also our [False Positives documentation](#false-positives).
- To contribute your correction, see [Contribute](CONTRIBUTING.md)
[Crates.io]: https://crates.io/crates/typos-cli
2019-07-03 21:22:36 -04:00
[Documentation]: https://docs.rs/typos