misspell-fixer() | misspell-fixer | misspell-fixer() |
misspell-fixer - misspell-fixer
Utility to fix common misspellings, typos in source code. There are lots of typical misspellings in program code. Typically they are more eye-catching in the living code but they can easily hide in comments, examples, samples, notes and documentation. With this utility you can fix a large number of them very quickly.
Be aware that the utility does not check or fix file names. It could easily happen that a misspelled word is fixed in a file name in a program's code, but the file itself will not be renamed by this utility.
It is also important to be very careful when fixing public APIs!
A manual review is always needed to verify that nothing has been broken.
misspell-fixer [OPTION] target[s]
target[s] can be any file[s] or directory/ies.
Main options:
Performance note: -s, -v or the lack of -n or -r use a slower processing internal loop. So usually -frn without -s and -v are the highest performing combination.
Output control options:
By default only a subset of rules is enabled (around 100). You can enable more rules with the following options:
The processing speed decreases as you activate more rules. But with newer greps this is much less significant.
File filtering options:
Whitelisting files/entries:
Misspell-fixer automatically ignores the issues matching to the patterns listed in .misspell-fixer.ignore or .github/.misspell-fixer.ignore. The format of this file follows the prefiltering's temporary result format:
^filename:line number:matched word
The ignore file is interpreted as a grep exclusion list. It is applied after the prefiltering step as a set of grep expressions. So it is possible to exclude any prefixes or more specifically whole files with keeping only their file names:
^filename
Or a directory:
^directory
The entries are listed/matched with the paths based on the current invocation. Reaching the same target with a different path from the same working directory will not apply the whitelisted entries generated from the other invocation. In directory x the whitelist entries generated with target . will not be applied for target ../x, although they are the same. There is a workaround for this with manually editing the whitelist to your needs. (Patches are welcome...)
Generally, the script tries to return with 0 if there were no typos or errors found/fixed.
Without arguments, the script will not change anything and its output is minimal. Its return value can be used to detect whether it found any typos or not.
$ misspell-fixer target
Fixing the files with displaying each fixed file:
$ misspell-fixer -rv target
Showing only the diffs without modifying the originals:
$ misspell-fixer -sv target
Showing the diffs with progress and fixing the found typos:
$ misspell-fixer -rsv target
Fast mode example, no backups: (highest performance)
$ misspell-fixer -frn target
The previous with all rules enabled:
$ misspell-fixer -frunRVD target
It is based on the following sources for common misspellings:
In some environments the dependencies may cause some trouble. (Mac, Windows, older linux versions.) In this case, you can use misspell-fixer as a docker container image.
Pull the latest version:
$ docker pull vlajos/misspell-fixer
And fix targetdir's content:
$ docker run -ti --rm -v targetdir:/work vlajos/misspell-fixer -frunRVD .
General execution directly with docker:
$ docker run -ti --rm -v targetdir:/work vlajos/misspell-fixer [arguments]
targetdir becomes the current working directory in the container, so you can reference it as . in the arguments list.
You can also use the dockered-fixer wrapper from the source repository:
$ dockered-fixer [arguments]
In case your shell supports functions, you can define a function to make the command a little shorter:
$ function misspell-fixer { docker run -ti --rm -v $(pwd):/work vlajos/misspell-fixer "$@"; }
And fixing with the function:
$ misspell-fixer [arguments]
Through the wrapper and the function, it can access only the folders below the current working directory as it is the only one passed to the container as a volume.
You can build the container locally, although this should not be really needed:
$ docker build . -t misspell-fixer
There's a GitHub Action https://github.com/sobolevn/misspell-fixer-action to run misspell-fixer as well. It can even send PRs automatically with the fixes.
The script itself is just a misspelling database and some glue in bash between grep and sed. grep's -F combined with sed's line targeting makes the script quite efficient. -F enables parallel pattern matching with the Aho–Corasick algorithm https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm . Unfortunately only the newer (2.28+) versions of grep supports -w properly.
A little more comprehensive list:
https://github.com/vlajos/misspell-fixer
Feel free to use it!
January 2023 |