Skip to content

Commit 0c8c6c5

Browse files
Add doc of using overrides with pre-commit
Document using included dictionaries on files for which they are not normally used (for example, Bash words on Markdown or text files), when using `pre-commit`. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
1 parent ee88dec commit 0c8c6c5

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ repos:
1313
- id: cspell
1414
```
1515
16-
## Setup Custom Dictionary
16+
## Using additional dictionaries
17+
18+
### Using included dictionaries on non-standard files
19+
20+
For example, using Bash dictionary with Markdown or text files, by filename (the
21+
default is to only apply from within VSCode for files of type `shellscript`).
22+
23+
[Using CSpell overrides](docs/README-OVERRIDES.md)
24+
25+
### Setup Custom Dictionary
1726

1827
To use a custom dictionary with the `pre-commit` hook, create either a `cspell.config.yaml` or `cspell.json` file in your project's root directory.
1928

docs/README-OVERRIDES.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Using CSpell overrides
2+
3+
This is the same for use with `pre-commit` as with other methods of invoking
4+
`cspell`, namely configuring an `overrides` section on your `cspell.json`
5+
or equivalent file.
6+
7+
The [current overrides documentation on the
8+
website](https://cspell.org/configuration/overrides/) is rather sparse, so here
9+
is another example.
10+
11+
## Using Bash dictionary with Markdown or text files by filename
12+
13+
Given a `cspell.json` as follows:
14+
15+
``` json
16+
{
17+
"language": "en",
18+
"overrides": [
19+
{
20+
"dictionaries": [
21+
"bash"
22+
],
23+
"filename": "**/{*.md,*.txt}"
24+
}
25+
],
26+
"version": "0.2"
27+
}
28+
```
29+
30+
And the following, as `test1.md` and as `test1.err`:
31+
32+
``` markdown
33+
## Sample code block
34+
35+
if grep -r "something" .; then
36+
echo "Found"
37+
fi
38+
39+
case "a string with 3" in
40+
with)
41+
echo "Why?"
42+
;;
43+
esac
44+
45+
. ./.bash_aliases
46+
47+
# We should use getopts
48+
49+
shopt -p
50+
51+
## And another topic
52+
53+
Words, many words.
54+
```
55+
56+
When `cspell` is invoked `test1.md` should not show errors, but `test1.err`
57+
should.
58+
59+
## Invoking CSpell
60+
61+
### `pre-commit`
62+
63+
Use a config such as the one in the [README.md](../README.md), stage all files
64+
(e.g. `git add --all .`), and execute:
65+
66+
``` bash
67+
pre-commit run --all-files
68+
```
69+
70+
or commit the changes
71+
72+
``` bash
73+
git commit
74+
```
75+
76+
### Command line
77+
78+
`cspell ./test1.*`

0 commit comments

Comments
 (0)