Skip to content

Commit 9909f3e

Browse files
Document file/folder-based overrides
Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
1 parent 0afd640 commit 9909f3e

File tree

3 files changed

+166
-82
lines changed

3 files changed

+166
-82
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
## How-To Guides and Configuration Examples
1717
1818
* [Use Dictionaries from `cspell-dicts`](docs/README-PRE-COMMIT-EXTRA-DICTS.md)
19-
* [Use a Different Dictionary Based Upon the Filename](docs/README-OVERRIDES.md)
19+
* [Use a Different Dictionary Based Upon the Filename](docs/README-FILE-FOLDER-BASED-OVERRIDE.md)
2020
* [Example `pre-commit` Setup for French](docs/README-PRE-COMMIT-EXAMPLE-FOR-FRENCH.md)
2121

2222
### Setup Custom Dictionary
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Using Different Dictionaries Based on Filename
2+
<!--- cspell:ignore esac getopts shopt --->
3+
4+
For example, using Bash dictionary with Markdown or text files, by filename (the
5+
default is to only apply from within VSCode for files of type `shellscript`).
6+
7+
This is the same for use with `pre-commit` as with other methods of invoking
8+
`cspell`, namely configuring an `overrides` section on your `cspell.json`
9+
or equivalent file.
10+
11+
The [current overrides documentation on the
12+
website](https://cspell.org/configuration/overrides/) covers a different type of
13+
scenario, so here is an example of selecting adding a dictionary to apply to
14+
specific folders.
15+
16+
## Using Bash dictionary with Markdown or text files by filename
17+
18+
Given a `cspell.json` as follows:
19+
20+
``` json
21+
{
22+
"overrides": [
23+
{
24+
"filename": ["**/bash_examples/**", "**/bash_docs/**.md"],
25+
"dictionaries": [
26+
"bash"
27+
]
28+
}
29+
],
30+
"version": "0.2"
31+
}
32+
```
33+
34+
Add the following code as `docs/bash_docs/a-silly-bash-code-block.md`
35+
36+
```` markdown
37+
## Sample code block
38+
39+
```sh
40+
if grep -r "something" .; then
41+
echo "Found"
42+
fi
43+
44+
case "a string with 3" in
45+
with)
46+
echo "Why?"
47+
;;
48+
esac
49+
50+
. ./.bash_aliases
51+
52+
# We should use getopts
53+
54+
shopt -p
55+
```
56+
57+
## And another topic
58+
59+
Words, many words.
60+
````
61+
62+
Add the following file as `examples/bash_examples/a-silly-bash-script`
63+
64+
``` markdown
65+
#!/bin/bash
66+
67+
if grep -r "something" .; then
68+
echo "Found"
69+
fi
70+
71+
case "a string with 3" in
72+
with)
73+
echo "Why?"
74+
;;
75+
esac
76+
77+
. ./.bash_aliases
78+
79+
# We should use getopts
80+
81+
shopt -p
82+
```
83+
84+
And add the following code as `docs/about.md`
85+
86+
```` markdown
87+
# Just a rather eccentric bash and markdown example for documentation purposes
88+
89+
## Sample code block
90+
91+
```sh
92+
if grep -r "something" .; then
93+
echo "Found"
94+
fi
95+
96+
case "a string with 3" in
97+
with)
98+
echo "Why?"
99+
;;
100+
esac
101+
102+
. ./.bash_aliases
103+
104+
# We should use getopts
105+
106+
shopt -p
107+
```
108+
109+
## And another topic
110+
111+
Words, many words.
112+
````
113+
114+
When `cspell` is invoked only `docs/about.md` should show errors.
115+
116+
## Invoking CSpell
117+
118+
### Via [`pre-commit`](https://pre-commit.com)
119+
120+
#### Prerequisites
121+
122+
* Project folder initialized as a git repository via `git init` or as part of a
123+
git repository cloned via `git clone`
124+
* ['pre-commit' installed](https://pre-commit.com/#install)
125+
* A `.pre-commit-config.yaml` such as:
126+
127+
```yaml
128+
fail_fast: true
129+
minimum_pre_commit_version: 2.18.1
130+
131+
repos:
132+
- repo: "https://github.com/streetsidesoftware/cspell-cli"
133+
rev: v6.5.0
134+
hooks:
135+
- id: cspell
136+
```
137+
138+
#### Triggering CSpell using `pre-commit`
139+
140+
* Stage all files
141+
142+
```
143+
git add --all .
144+
```
145+
146+
* Execute:
147+
148+
``` bash
149+
pre-commit run --all-files
150+
```
151+
152+
OR commit the changes
153+
154+
``` bash
155+
git commit
156+
```
157+
158+
### Via Command line
159+
160+
* Execute
161+
162+
``` bash
163+
cspell '**'
164+
```
165+

docs/README-OVERRIDES.md

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)