Overrides
The configuration used for a file is calculated by applying the configuration in two phases.
The first phase is to gather all the relevant configuration files and merge the settings.
The second phase is to finalize the configuration based upon the resulting overrides and languageSettings
that match the path name, languageId, and locale.
Configuration Gathering
The spell checker gathers all the relevant configuration files and merges the settings from each file.
Settings Gathering Order
- Default Configuration - the settings included in
cspell. - Command line settings - the settings given on the command line.
- Imports found in the configuration file. - any imports found in the configuration file loaded.
- Configuration file - the settings found in the configuration file.
Merge Rules
Most individual settings will overwrite the settings from the previous step / file. There are a few important exceptions.
Array Settings are Unions
Most Array like settings are joined as a union. In most cases order is preserved.
Examples:
- Word lists like:
words,flagWords,ignoreWordsare the union of all the settings. The order is not preserved. overridesandlanguageSettingsare accumulated in the order they were loaded to be applied later.patterns,includeRegExpList, andignoreRegExpListare collected in order so that patterns of the same name can be replaced.dictionaryDefinitionsanddictionariesare collected in order so that dictionaries can be replaced by other dictionaries with the same name.
Configuration Finalization
Order
overrides- the settings from the matchingfilenameglobs are applied.languageSettings- the settings from the matchinglanguageIdorlocaleare applied.
Override Configuration Field: overrides
The overrides configuration is a useful way to force configuration on a per file basis.
The filename field is used to set the glob selection criteria.
When the path of the file being checked matches the glob/globs specified in filename, the override settings will be applied.
Example Overrides
filename can be a single glob or an array of globs.
Example:
"overrides": [
{
// Force `*.hrr` and `*.crr` files to be treated as `cpp` files:
"filename": "**/{*.hrr,*.crr}",
"languageId": ["cpp", "hpp"] // Set the languageId `cpp` and `hpp` overriding the defaults.
},
{
// Force `*.txt` to use the Dutch dictionary (Dutch dictionary needs to be installed separately):
"filename": "**/dutch/**/*.txt",
"language": "nl",
},
{
// Enable the `lorem-ipsum` dictionary for all test files.
"filename": ["**/*.test.ts", "**/test/**"],
"dictionaries": ["lorem-ipsum"]
},
{
"filename": "**/images/**",
"enabled": false // Disable spellchecking.
}
]