-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support local configuration files (#966)
## Supported Configuration Files The spell checker will look for the following configuration files. - `.cspell.json` - `cspell.json` - `.cSpell.json` - `cSpell.json` - `.vscode/cspell.json` - `.vscode/cSpell.json` - `.vscode/.cspell.json` - `cspell.config.js` - `cspell.config.cjs` - `cspell.config.json` - `cspell.config.yaml` - `cspell.config.yml` - `cspell.yaml` - `cspell.yml` ## Configuration Search While spell checking files, the spell checker will look for the nearest configuration file in the directory hierarchy. This allows for folder level configurations to be honored. It is possible to stop this behavior by adding adding `"noConfigSearch": true` to the top level configuration. A Monorepo Example: ``` repo-root ├── cspell.config.json ├─┬ packages │ ├─┬ package-A │ │ ├── cspell.json │ │ ├── README.md │ │ └── CHANGELOG.md │ ├─┬ package-B │ │ ├── README.md │ │ └── CHANGELOG.md │ ├─┬ package-C │ │ ├── cspell.yaml │ │ ├── README.md │ │ └── CHANGELOG.md ``` The following command will search the repo start at `repo-root` looking for `.md` files. ``` repo-root % cspell "**/*.md" ``` The root configuration is used to determine which files to check. Files matching the globs in `ignorePaths` will not be checked. When a file is found, the directory hierarchy is searched looking for the nearest configuration file. For example: | File | Config Used | | ------------------------------ | -------------------------------- | | `packages/package-A/README.md` | `packages/package-A/cspell.json` | | `packages/package-A/CONFIG.md` | `packages/package-A/cspell.json` | | `packages/package-B/README.md` | `cspell.config.json` | | `packages/package-C/README.md` | `packages/package-C/cspell.yaml` | * dev: Add `noConfigSearch` to configuration Support reading local config files when spell checking a file. This makes having supporting workspaces with multiple folders easier. ## Commits * dev: improve sample config * dev: document how the configuration works. * dev: Support spell checking documents * dev: Update spellCheckFile.test.ts to fix tests on Windows * dev: add ability to specify the languageId in the Document * dev: refactor Document type. * dev: export spellCheckDocument * refactor: cspell app options into their own files.
- Loading branch information
Showing
18 changed files
with
611 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# cspell Configuration | ||
|
||
## Supported Configuration Files | ||
|
||
The spell checker will look for the following configuration files. | ||
|
||
- `.cspell.json` | ||
- `cspell.json` | ||
- `.cSpell.json` | ||
- `cSpell.json` | ||
- `.vscode/cspell.json` | ||
- `.vscode/cSpell.json` | ||
- `.vscode/.cspell.json` | ||
- `cspell.config.js` | ||
- `cspell.config.cjs` | ||
- `cspell.config.json` | ||
- `cspell.config.yaml` | ||
- `cspell.config.yml` | ||
- `cspell.yaml` | ||
- `cspell.yml` | ||
|
||
## Configuration Search | ||
|
||
While spell checking files, the spell checker will look for the nearest configuration file in the directory hierarchy. | ||
This allows for folder level configurations to be honored. | ||
It is possible to stop this behavior by adding adding `"noConfigSearch": true` to the top level configuration. | ||
|
||
A Monorepo Example: | ||
|
||
``` | ||
repo-root | ||
├── cspell.config.json | ||
├─┬ packages | ||
│ ├─┬ package-A | ||
│ │ ├── cspell.json | ||
│ │ ├── README.md | ||
│ │ └── CHANGELOG.md | ||
│ ├─┬ package-B | ||
│ │ ├── README.md | ||
│ │ └── CHANGELOG.md | ||
│ ├─┬ package-C | ||
│ │ ├── cspell.yaml | ||
│ │ ├── README.md | ||
│ │ └── CHANGELOG.md | ||
``` | ||
|
||
The following command will search the repo start at `repo-root` looking for `.md` files. | ||
|
||
``` | ||
repo-root % cspell "**/*.md" | ||
``` | ||
|
||
The root configuration is used to determine which files to check. Files matching the globs in `ignorePaths` will not be checked. When a file is found, the directory hierarchy is searched looking for the nearest configuration file. | ||
|
||
For example: | ||
|
||
| File | Config Used | | ||
| ------------------------------ | -------------------------------- | | ||
| `packages/package-A/README.md` | `packages/package-A/cspell.json` | | ||
| `packages/package-A/CONFIG.md` | `packages/package-A/cspell.json` | | ||
| `packages/package-B/README.md` | `cspell.config.json` | | ||
| `packages/package-C/README.md` | `packages/package-C/cspell.yaml` | | ||
|
||
## Example Configurations: | ||
|
||
### Example `cspell.config.js` | ||
|
||
```javascript | ||
'use strict'; | ||
|
||
/** @type { import("@cspell/cspell-types").CSpellUserSettings } */ | ||
const cspell = { | ||
description: 'Company cspell settings', | ||
languageSettings: [ | ||
{ | ||
languageId: 'cpp', | ||
allowCompoundWords: false, | ||
patterns: [ | ||
{ | ||
// define a pattern to ignore #includes | ||
name: 'pound-includes', | ||
pattern: /^\s*#include.*/g, | ||
}, | ||
], | ||
ignoreRegExpList: ['pound-includes'], | ||
}, | ||
], | ||
dictionaryDefinitions: [ | ||
{ | ||
name: 'custom-words', | ||
path: './custom-words.txt', | ||
}, | ||
], | ||
dictionaries: ['custom-words'], | ||
}; | ||
|
||
module.exports = cspell; | ||
``` | ||
|
||
### Example import from `cspell.json` | ||
|
||
Import a `cspell.config.js` file from a `cspell.json` file. | ||
|
||
```javascript | ||
{ | ||
"import": ["../cspell.config.js"] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
here | ||
are | ||
some | ||
words |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class ImportError extends Error { | ||
constructor(msg: string, readonly cause?: Error) { | ||
super(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.