-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document using extra dicts with pre-commit #207
base: main
Are you sure you want to change the base?
Changes from all commits
0c8c6c5
5206efb
35653cb
b81a51c
0afd640
9909f3e
d4b1cf8
fcdc2a6
228514b
8720b5c
b814e43
5855852
a42b76b
d03630d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# Use an Extra Dictionary Based on the Folder or Filename | ||
<!--- cspell:ignore esac getopts shopt ---> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: it is also possible to enable a dictionary in a file if adding words becomes too long. <!--- cspell:dictionaries bash ---> |
||
|
||
For example, using Bash dictionary with Markdown or text files, by filename (the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about flipping the logic:
|
||
default is to only apply from within VSCode for files of type `shellscript`). | ||
|
||
**Note**: This adds the Bash dictionary to the list of dictionaries against | ||
which to check the files, it does not check only against the Bash dictionary. | ||
|
||
This is the same for use with `pre-commit` as with other methods of invoking | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, |
||
`cspell`, namely configuring an `overrides` section on your `cspell.json` | ||
or equivalent file. | ||
|
||
The [current overrides documentation on the | ||
website](https://cspell.org/configuration/overrides/) covers a different type of | ||
scenario, so here is an example of selecting adding a dictionary to apply to | ||
specific folders. | ||
|
||
## Using Bash dictionary with Markdown or text files by filename | ||
|
||
Given a `cspell.json` as follows: | ||
|
||
|
||
``` json | ||
{ | ||
"overrides": [ | ||
{ | ||
"filename": ["**/bash_examples/**", "**/bash_docs/**.md"], | ||
"dictionaries": [ | ||
"bash" | ||
] | ||
} | ||
], | ||
"version": "0.2" | ||
} | ||
``` | ||
|
||
Add the following code as `docs/bash_docs/a-silly-bash-code-block.md` | ||
|
||
```` markdown | ||
## Sample code block | ||
|
||
```sh | ||
if grep -r "something" .; then | ||
echo "Found" | ||
fi | ||
|
||
case "a string with 3" in | ||
with) | ||
echo "Why?" | ||
;; | ||
esac | ||
|
||
. ./.bash_aliases | ||
|
||
# We should use getopts | ||
|
||
shopt -p | ||
``` | ||
|
||
## And another topic | ||
|
||
Words, many words. | ||
```` | ||
|
||
Add the following file as `examples/bash_examples/a-silly-bash-script` | ||
|
||
``` markdown | ||
#!/bin/bash | ||
|
||
if grep -r "something" .; then | ||
echo "Found" | ||
fi | ||
|
||
case "a string with 3" in | ||
with) | ||
echo "Why?" | ||
;; | ||
esac | ||
|
||
. ./.bash_aliases | ||
|
||
# We should use getopts | ||
|
||
shopt -p | ||
``` | ||
|
||
And add the following code as `docs/about.md` | ||
|
||
```` markdown | ||
# Just a rather eccentric bash and markdown example for documentation purposes | ||
|
||
## Sample code block | ||
|
||
```sh | ||
if grep -r "something" .; then | ||
echo "Found" | ||
fi | ||
|
||
case "a string with 3" in | ||
with) | ||
echo "Why?" | ||
;; | ||
esac | ||
|
||
. ./.bash_aliases | ||
|
||
# We should use getopts | ||
|
||
shopt -p | ||
``` | ||
|
||
## And another topic | ||
|
||
Words, many words. | ||
```` | ||
|
||
When `cspell` is invoked only `docs/about.md` should show errors. | ||
|
||
## Invoking CSpell | ||
|
||
### Via [`pre-commit`](https://pre-commit.com) | ||
|
||
#### Prerequisites | ||
|
||
* Project folder initialized as a git repository via `git init` or as part of a | ||
git repository cloned via `git clone` | ||
* ['pre-commit' installed](https://pre-commit.com/#install) | ||
* A `.pre-commit-config.yaml` such as: | ||
|
||
```yaml | ||
fail_fast: true | ||
minimum_pre_commit_version: 2.18.1 | ||
|
||
repos: | ||
- repo: "https://github.com/streetsidesoftware/cspell-cli" | ||
rev: v6.7.0 | ||
hooks: | ||
- id: cspell | ||
``` | ||
|
||
#### Triggering CSpell using `pre-commit` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move the |
||
|
||
* Stage all files | ||
|
||
``` | ||
git add --all . | ||
``` | ||
|
||
* Check all files in `git` against `pre-commit` hooks | ||
|
||
``` bash | ||
pre-commit run --all-files | ||
``` | ||
|
||
* OR commit the changes | ||
|
||
``` bash | ||
git commit | ||
``` | ||
|
||
### Via Command line | ||
|
||
* Execute | ||
|
||
``` bash | ||
cspell '**' | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# Example `pre-commit` setup for French | ||
<!--- cspell:ignore Voici nous avons française reforme ---> | ||
|
||
## Common configuration | ||
|
||
### `pre-commit-config.yaml` configuration | ||
|
||
Extend the `pre-commit` hook config from the [README.md](../README.md) with | ||
`additional_dependencies`. For example: | ||
|
||
```yaml | ||
# .pre-commit-config.yaml | ||
repos: | ||
- repo: https://github.com/streetsidesoftware/cspell-cli | ||
rev: v6.7.0 | ||
hooks: | ||
- id: cspell | ||
additional_dependencies: | ||
- "@cspell/dict-fr-fr" | ||
- "@cspell/dict-fr-reforme" | ||
|
||
``` | ||
Comment on lines
+6
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
|
||
For a complete list of available dictionaries, | ||
see: <https://github.com/streetsidesoftware/cspell-dicts>. | ||
|
||
## Using French as the locale | ||
|
||
Use a `cspell.json` such as the following: | ||
|
||
```json | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", | ||
"import": [ | ||
"@cspell/dict-fr-fr/cspell-ext.json", | ||
"@cspell/dict-fr-reforme/cspell-ext.json" | ||
], | ||
"language": "fr", | ||
"version": "0.2" | ||
} | ||
``` | ||
|
||
A file such as `mots-française.md` containing: | ||
|
||
```markdown | ||
# Testing french in Markdown | ||
|
||
## Les mots | ||
|
||
Voici, nous avons les mots française. | ||
``` | ||
|
||
When `cspell` is invoked `mots-française.md` should not show errors | ||
|
||
## Applying to specific files | ||
|
||
And to apply those dictionaries to files with the `.md` extension (Markdown), | ||
use a `cspell.json` such as: | ||
|
||
```json | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", | ||
"import": [ | ||
"@cspell/dict-fr-fr/cspell-ext.json", | ||
"@cspell/dict-fr-reforme/cspell-ext.json" | ||
], | ||
"overrides": [ | ||
{ | ||
"filename": "**/*.md", | ||
"language": "fr,fr-fr,fr-90" | ||
} | ||
], | ||
"version": "0.2" | ||
} | ||
``` | ||
|
||
And the following, as `mots-française.md`: | ||
|
||
``` markdown | ||
# Testing french in Markdown | ||
|
||
## Les mots | ||
|
||
Voici, nous avons les mots française | ||
``` | ||
|
||
as again as `mots-française.err`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to repeat the example or show errors. At most, a directory tree showing which files will use French and which ones will not. |
||
|
||
``` markdown | ||
# Testing french in Markdown | ||
|
||
## Les mots | ||
|
||
Voici, nous avons les mots française | ||
``` | ||
|
||
When `cspell` is invoked `mots-française.md` should not show errors, but | ||
`mots-française.err` should. | ||
|
||
## Invoking CSpell | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a list of references to other pages. |
||
|
||
### Via [`pre-commit`](https://pre-commit.com) | ||
|
||
#### Prerequisites | ||
|
||
* Project folder initialized as a git repository via `git init` or as part of a | ||
git repository cloned via `git clone` | ||
* ['pre-commit' installed](https://pre-commit.com/#install) | ||
* A `.pre-commit-config.yaml` such as: | ||
|
||
```yaml | ||
fail_fast: true | ||
minimum_pre_commit_version: 2.18.1 | ||
|
||
repos: | ||
- repo: "https://github.com/streetsidesoftware/cspell-cli" | ||
rev: v6.7.0 | ||
hooks: | ||
- id: cspell | ||
``` | ||
|
||
#### Triggering CSpell using `pre-commit` | ||
|
||
* Stage all files | ||
|
||
``` | ||
git add --all . | ||
``` | ||
|
||
* Check all files in `git` against `pre-commit` hooks | ||
|
||
``` bash | ||
pre-commit run --all-files | ||
``` | ||
|
||
* OR commit the changes | ||
|
||
``` bash | ||
git commit | ||
``` | ||
|
||
### Via Command line | ||
|
||
* Execute | ||
|
||
``` bash | ||
cspell '**' | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Setup Custom Dictionary | ||
|
||
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. | ||
|
||
`cspell.config.yaml` | ||
|
||
```yaml | ||
dictionaryDefinitions: | ||
- name: myWords | ||
path: ./path/to/cSpell_dict.txt | ||
addWords: true | ||
dictionaries: | ||
- myWords | ||
``` | ||
|
||
`cSpell.json` | ||
|
||
```json | ||
{ | ||
"dictionaryDefinitions": [ | ||
{ | ||
"name": "myWords", | ||
"path": "./path/to/cSpell_dict.txt", | ||
"addWords": true | ||
} | ||
], | ||
"dictionaries": ["myWords"] | ||
} | ||
``` | ||
|
||
If you installed the [Code Spell Checker extension](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) for VS Code, this can be done automatically from the command palette by running "Spell: Create a CSpell configuration file". | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are a few approaches to document this. A couple come to mind:
I think either approach is fine.
Based upon how you wrote it so far, I'm guessing you are leaning towards a Walk Through Style.
My suggestion is to use a single short example file. No need to show too much. We just want
to demonstrate the issue to be solved.
Walk Though Style
A walk through is more like telling a story:
Show the problem you are trying to solve
or
Show some ways to solve it.
<!--- cspell:ignore esac --->
or<!--- cspell:words esac --->
<!--- cspell:dictionaries bash --->
overrides
languageSettings
cspell.json
:{ "words": ["esac"] }
Pick one and explain your choice.
Summarize / conclusions.
Useful things:
Reference Style
In a reference style, it is more like a list of examples.
overrides
languageSettings
Tools
cspell-cli trace word
cspell-cli check docs/file-or-folder-based-overrides.md