Skip to content

Commit 5206efb

Browse files
Document using extra dictionaries with pre-commit
This closes #206 and stems from streetsidesoftware/cspell#3426 where I had to dig around rather a lot to pull the pieces together. Hopefully the docs make life easier for the next person who wants to do this kind of thing. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
1 parent 0c8c6c5 commit 5206efb

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ default is to only apply from within VSCode for files of type `shellscript`).
2222

2323
[Using CSpell overrides](docs/README-OVERRIDES.md)
2424

25+
### Using dictionaries from `cspell-dicts`
26+
27+
For example, using the fr_FR and fr_FR_90 dictionaries when local is `fr`
28+
29+
[Using extra CSpell dictionaries with
30+
`pre-commit`](docs/README-PRE-COMMIT-EXTRA-DICTS.md)
31+
32+
You can of course combine using override with using dictionaries from
33+
`cspell-dicts`.
34+
2535
### Setup Custom Dictionary
2636

2737
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.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Using extra CSpell dictionaries with `pre-commit`
2+
3+
## Common configuration
4+
5+
### `pre-commit-config.yaml` configuration
6+
7+
Extend the `pre-commit` hook config from the [README.md](../README.md) with
8+
`additional_dependencies`. For example:
9+
10+
```yaml
11+
# .pre-commit-config.yaml
12+
repos:
13+
- repo: https://github.com/streetsidesoftware/cspell-cli
14+
rev: v6.2.0
15+
hooks:
16+
- id: cspell
17+
additional_dependencies:
18+
- "@cspell/dict-fr-fr"
19+
- "@cspell/dict-fr-reforme"
20+
21+
```
22+
23+
For a complete list of available dictionaries,
24+
see: <https://github.com/streetsidesoftware/cspell-dicts>.
25+
26+
## Using French as the locale
27+
28+
Use a `cspell.json` such as the following:
29+
30+
```json
31+
{
32+
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
33+
"import": [
34+
"@cspell/dict-fr-fr/cspell-ext.json",
35+
"@cspell/dict-fr-reforme/cspell-ext.json"
36+
],
37+
"language": "fr",
38+
"version": "0.2"
39+
}
40+
```
41+
42+
A file such as `test2.md` containing:
43+
44+
```markdown
45+
# Testing french in Markdown
46+
47+
## Les mots
48+
49+
Voici, nous avons les mots française.
50+
```
51+
52+
When `cspell` is invoked `test2.md` should not show errors
53+
54+
## Applying to specific files
55+
56+
And to apply those dictionaries to files with the `.md` extension (Markdown),
57+
use a `cspell.json` such as:
58+
59+
```json
60+
{
61+
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
62+
"import": [
63+
"@cspell/dict-fr-fr/cspell-ext.json",
64+
"@cspell/dict-fr-reforme/cspell-ext.json"
65+
],
66+
"overrides": [
67+
{
68+
"filename": "**/{*.md,*.txt}",
69+
"language": "fr,fr-fr,fr-90"
70+
}
71+
],
72+
"version": "0.2"
73+
}
74+
```
75+
76+
And the following, as `test2.md` and as `test2.err`:
77+
78+
``` markdown
79+
# Testing french in Markdown
80+
81+
## Les mots
82+
83+
Voici, nous avons les mots française
84+
```
85+
86+
When `cspell` is invoked `test2.md` should not show errors, but `test2.err`
87+
should.
88+
89+
## Invoking CSpell
90+
91+
### `pre-commit`
92+
93+
With [pre-commit](https://pre-commit.com) installed:
94+
95+
1. Use a config such as the one above
96+
2. Stage all files (e.g. `git add --all .`)
97+
3. Execute:
98+
99+
``` bash
100+
pre-commit run --all-files
101+
```
102+
103+
OR commit the changes
104+
105+
``` bash
106+
git commit
107+
```
108+
109+
### Command line
110+
111+
`cspell ./test2.*`

0 commit comments

Comments
 (0)