Repository navigation
Features
feat: Specify multiple config files in the `check`, `trace`, `suggest`, and `dictionaries` commands (#9761)
feat: Specify multiple config files in the check, trace, suggest, and dictionaries commands (#9761)
Summary
cspell check, cspell trace, cspell suggest, and cspell dictionaries now accept --config more than once, as cspell lint does. The files merge in the order given.
Feature
-c, --configcan be repeated oncheck,trace,suggest, anddictionaries. Later files override earlier ones.- The matching API functions in
cspellaccept a list of config files forconfig.
cspell trace colour --config cspell.base.json --config ci/cspell.ci.json
cspell check --config cspell.base.json --config ci/cspell.ci.json README.mdTechnical Details
- The named files load and merge the same way as for
cspell lint. - For
check, the named files still replace the search for a config near the document, as a single--configdoes today.
feat: Specify multiple config files in the lint API (#9759)
feat: Specify multiple config files in the lint API (#9759)
Summary
The lint API in cspell now takes a list of config files. Integrations that call the API, such as the GitHub Action, can get the same result as cspell lint --config a.json --config b.json. cspell-lib resolves and merges the list.
Feature
- The
configoption of thelintAPI accepts a list.- Each entry is a file name or a config file object.
- The files merge in the order given. Later files override earlier ones.
cspell-libaddsresolveConfigFiles, which resolves the imports of each config file and merges the results in order.- The
cspell-libconfig loader has a matchingmergeConfigFilesWithImportsmethod.
import { lint } from 'cspell';
await lint(['**/*.md'], { config: ['cspell.base.json', 'ci/cspell.ci.json'] });import { readConfigFile, resolveConfigFiles } from 'cspell-lib';
const configFiles = await Promise.all(['cspell.base.json', 'ci/cspell.ci.json'].map((file) => readConfigFile(file)));
const settings = await resolveConfigFiles(configFiles);Other changes
- An empty config name, such as
--config '', now reports a configuration error instead of searching for a config. This applies tolint,trace,suggest, anddictionaries.
Technical Details
- Each file in the list loads the same way a single config file does, including its imports and Yarn PnP setup. The results then merge in order.
cspell lintwith more than one--configuses the same path.
feat: Specify multiple config files in the `cspell lint` CLI (#9757)
feat: Specify multiple config files in the cspell lint CLI (#9757)
Summary
The cspell lint CLI now takes multiple config files. Before, using more than one config meant writing a config that imports them.
Feature
cspell lint --config cspell.json --config cspell.ci.json "**"- The named configs merge exactly as if one config imported them, in the order given.
- The import rules cover every setting, including
files,ignorePaths,reporters, andcache. Paths resolve against each config's own folder. - The config found for each file still merges on top. If
cspell.ci.jsonsetslanguage: enandi18n/de/cspell.jsonsetslanguage: de, files ini18n/de/are checked as German. - A named config can also be the closer config for some files. It then merges on top again, as an imported config does today.
- With one
--config, nothing changes.
Before, a repeated --config kept only the last file:
cspell lint --config cspell.json --config cspell.ci.json "**"
# only cspell.ci.json applies
After, both apply, with cspell.ci.json on top of cspell.json.
cspell lint -v -v lists every named file under "Config Files Found".
Technical Details
- Each named file is found and read exactly as a single
--configis. An in-memory config then imports the files by their full paths, in the order given. - As with one named config, the search for each file's config stops at the root without looking in it.
--stop-config-search-atworks as before. - A missing or broken named file is a configuration error, like a failed import.
- The cache key holds the named files in order, so changing the order checks the files again. Caches made with a single
--configare rebuilt once. CSPELL_CONFIG_PATH,CSPELL_DEFAULT_CONFIG_PATH, and the other commands still take one config file.
Fixes
fix: Keep `--exclude` globs relative to the current folder (#9776)
fix: Keep --exclude globs relative to the current folder (#9776)
Summary
--exclude globs now match the same files as ignorePaths: they are relative to the current folder. Before, running from inside an installed package, --exclude node_modules/ skipped every file, because the node_modules folder above the current folder counted.
node_modules/,node_modules,/**/node_modules/**, and${cwd}/**/node_modules/**match onlynode_modulesfolders below the current folder.- A leading
/ties a glob to the current folder:--exclude /fixturesskipsfixtures/sample.md, but notpackages/app/fixtures/broken.md. - A glob that starts with
**/, such as**/node_modules/**, still matches folders above the current folder, as it does inignorePaths.
Before:
$ cd node_modules/my-package
$ cspell --exclude node_modules/ "**"
No files found to check.
After:
$ cd node_modules/my-package
$ cspell --exclude node_modules/ "**"
README.md:1:1 - Unknown word (helllo)
Technical Details
- Each
--excludeglob is first resolved against the current folder. A glob such asnode_modules/becomes**/node_modules/**, tied to the current folder. - That result was then written out as text and read again. Read as text, a glob that starts with
**/matches folders above the current folder too, so thenode_modulesfolder that holds the package counted. - The resolved globs are now used as they are, so they stay tied to the current folder.
fix: cspell-tools: Split dashed camelCase words the same way every time (#9773)
fix: cspell-tools: Split dashed camelCase words the same way every time (#9773)
With split enabled and allowedSplitWords set, a camelCase entry that also contains a dash, such as fooBar-Baz, was sometimes kept whole instead of being split into its parts. Whether it was split depended on the entry before it in the word list. Such entries are now split the same way every time.
fix: Use `--show-context` for cached results (#9770)
fix: Use --show-context for cached results (#9770)
Summary
With --cache, a file whose result came from the cache ignored --show-context: it showed the context the stored result happened to have. Cached results now show the context the current run asks for, the same as a file that is checked again.
For a file first checked without --show-context, then again with it:
cspell lint --cache --show-context 10 "*.md"Before:
a.md:2:5 - Unknown word (Helllo) -- The Helllo wrold line is a long line with words.
After:
a.md:2:5 - Unknown word (Helllo) -- The Helllo wrold line is a long
The cache file also gets smaller.
Technical Details
- The cache no longer stores what it can calculate when a result is loaded: an issue's column, its list of suggested words, and its context.
- The cache stores a line's text only when it differs from the file. Otherwise the unchanged file still holds it, and a cache hit reads the file to get it. A cache hit reads a file again only when it has issues.
fix: `cspell check` uses the same config files as `cspell lint` (#9767)
fix: cspell check uses the same config files as cspell lint (#9767)
Summary
cspell check now uses the same config files as cspell lint, so it shows what cspell lint reports for a file. It only differs in how it shows the result.
Changes to cspell check:
- It uses the config file named by
CSPELL_CONFIG_PATH. When no config file is found, it usesCSPELL_DEFAULT_CONFIG_PATH. - Without
--config, the config file found from the current folder applies, along with any config file closer to the file being checked. - With
--config, config files near the file being checked, below the current folder, apply too.
Before and after
A project allows extra words in cspell.ci.json:
CSPELL_CONFIG_PATH=cspell.ci.json cspell check README.mdBefore: cspell check ignored cspell.ci.json and flagged the words it allows, while cspell lint accepted them.
After: cspell check uses cspell.ci.json and flags the same words as cspell lint.
fix: Use `cacheStrategy` from the config file when `--cache-strategy` isn't given (#9762)
fix: Use cacheStrategy from the config file when --cache-strategy isn't given (#9762)
cspell lint ignored the cache.cacheStrategy setting in a config file. It always used content unless --cache-strategy was given. Now the setting is used when the flag isn't given.
The help for cspell lint --root, cspell lint --report and cspell init --format now shows the default the same way as other options:
-r, --root <root folder> Root directory. (default: current directory)
--report <level> Set how unknown words are reported (choices: "all", "simple", "typos", "flagged", default: "all")
--format <format> Define the format of a new file. (choices: "yaml", "yml", "json", "jsonc", default: "yaml")
fix: Don't reuse cached results between runs with different dictionary and file-skipping flags (#9741)
fix: Don't reuse cached results between runs with different dictionary and file-skipping flags (#9741)
Summary
With --cache, cspell lint now checks a file again when one of these flags differs from the run that cached the file's result:
--dictionaryand--disable-dictionary--no-default-configuration--force-check--max-file-size
Before this fix, a run could reuse the result of a run with different flags. For example:
- Adding
--dictionaryshowed the same issues as before, from the cache, as if the dictionary had no effect. - Dropping
--dictionaryshowed the earlier run's result, so issues were missed and the run could pass. - A run without
--force-checkreported issues in a file it should skip. - A run with
--max-file-sizereported issues in a file larger than the limit.
The first run after one of these flags changes checks the files again.
fix: Show broken symbolic links in verbose glob searches (#9700)
fix: Show broken symbolic links in verbose glob searches (#9700)
Summary
When you run cspell lint --glob-symlinks --verbose, CSpell reports broken symbolic links that match a glob or block a path named in one. This helps explain why an expected file or directory was skipped.
CSpell reports each link as an informational message and uses the normal lint result for its exit status.
Fixes #9441.