question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

repl mode for stdin, or fail fast

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Jason3Scommented, Jan 21, 2022

@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

{
  "import": ["cspell.json"],
  "reporters": [["./<relative path from cspell.json>/reporter.js"]]
}

Example logic:

export function getReporter(): CSpellReporter {
    const issues: Issue[] = [];
    const errors: string[] = [];
    const files: string[] = [];

    const reporter: CSpellReporter = {
        issue: (issue) => {
            issues.push(issue);
        },
        info: () => {},
        debug: () => {},
        error: (message, _error) => {
            errors.push(message);
        },
        progress: (p) => {
            // Progress is called when a file has completed.
            if (issues.length || errors.length) {
                // Output any errors and then fail.
                console.log('errors...');
                throw new Error('Fail');
            }
            files.push(p.filename);
        },
        result:() => {},
    };

  return reporter;
}

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 with cacheLocation.

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

{
  "import": ["cspell.json"],
  "cache": {
    "useCache": true,
    "cacheLocation": ".ci-cspell-cache",
    "cacheStrategy": "content"
  }
}

Supporting new Feature Development

Please consider supporting the cost of development:

0reactions
github-actions[bot]commented, Feb 26, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading all of stdin at program start prevents ... - Stack Overflow
I have a golang program that makes a simple repl for jq. I'd like to be able to read input from stdin at...
Read more >
Part Seven: A REPL · Make A Language
In case you aren't familiar with the concept, a read-eval-print-loop, or REPL, is a program that lets you interactively use a programming ...
Read more >
Chapter 12 The toplevel system or REPL (ocaml)
This chapter describes the toplevel system for OCaml, that permits interactive use of the OCaml system through a read-eval-print loop (REPL). In this...
Read more >
Chapter 4. Interactive Node with REPL and More on the Console
Another useful REPL feature is that it enables us to create a custom REPL so that we can eliminate the unhelpful undefined responses,...
Read more >
Repl.it DB - Replit
Some quick docs Setting data getting data you can leave out the part, but if you set to false, you will either get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found