repl mode for stdin, or fail fast
See original GitHub issueIs your feature request related to a problem? Please describe. We’re lining all files in the CI, and we want cspell to fail as soon as it found the first issue, so that we don’t have to wait for it to check all hundreds of files. One might argue that we only should check changed files, but unfortunately, our CI system isn’t advanced enough to allow for that, so we have to check all the files every time.
Describe the solution you’d like
I’d like to have something similar to REPL mode, so that when used with --file-list stdin
, I can write one file to stdin, let cspell check it and give me result, then write another file to stdin, and so on. I would also be checking stderr to see if errors were found and terminate the process in that case. Buffering may be an issue here.
So probably a better approach would be to provide a flag --fail-fast
to make cspell exit with an error code as soon as an error is encountered. Perhaps, there’s already such a feature that I’ve missed?..
Describe alternatives you’ve considered
I’ve tried using it in REPL mode, but unless I do cspellProcess.stdin.end();
it doesn’t start producing any output.
Additional context The current approach:
const cspellProcess = spawn('cspell --dot --file-list stdin', [], {
shell: true,
});
const notIgnoredFiles = await getNotIgnoredFiles();
notIgnoredFiles.forEach((file) => {
cspellProcess.stdin.write(file.toString() + '\n');
});
cspellProcess.stdin.end();
cspellProcess.stdout.on('data', (data) => {
console.log(`${data}`);
});
cspellProcess.stderr.on('data', (data) => {
console.log(`${data}`);
});
cspellProcess.on('error', (error) => {
console.log(`cspellProcess error:\n${error}`);
});
cspellProcess.on('exit', (code, signal) => {
if (code) {
console.log(`Process exit with code: ${code}`);
}
if (signal) {
console.log(`Process killed with signal: ${signal}`);
}
console.log(`Done`);
});
(unrelated, but for some reason, it doesn’t write to stdout, only to stderr, even when there are no errors to report…)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@Maxim-Mazurok,
I think a
--fail-fast
option is a good feature.In the meantime, you can use a custom reporter or caching.
Using a Custom Reporter
Example reporter: cspell-json-reporter
To add a reporter to your configuration, just add
reporters
field.Using a custom CSpell config for your CI pipeline:
cspell -c ci-cspell.json ...
ci-cspell.json
Example logic:
A full example can be found here: Integration Test Reporter
Using a Cache
If your CI supports caching of files, then you can use the
--cache
option. This is generally very fast. Just cache the file you have defined withcacheLocation
.For this to work, the run location must always be the same. For example on GitHub using workflows, it is
/home/runner/work/
.ci-cspell.json
Supporting new Feature Development
Please consider supporting the cost of development:
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.