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.

Change Request: Make processors (pre/post) async or pass config to them

See original GitHub issue

ESLint version

8.6.0

What problem do you want to solve?

ESLint currently calls the preprocessor and postprocessor functions synchronously. This is a problem since the ESLint class is asynchronous, thus it’s currently impossible to use it within the preprocessor.

For example, my use case is I need to know during preprocessing what type of quotes the linter will be using.

With CLIEngine it was just:

preprocess(text, filename) {
    const config = new CLIEngine({ useEslintrc: true }).getConfigForFile(path.resolve(filename));
    const quote = config.rules.quotes[1];
   /* ... */
}

However with ESLint, the equivalent function is getConfigForFile which is async. If you try to just make the processor async, like so:

async preprocess(text, filename) {
    const eslint = new ESLint();
    const config = await eslint.calculateConfigForFile(filename);
    /* ... */
}

… then it is now returning a Future instead of an array which eslint doesn’t know how to process.

What do you think is the correct solution?

Either make the the processors async as well and have eslint treat them as such, or pass the loaded config to the processor, like:

preprocess(text, filename, config) {
    const quote = config.rules.quotes;
   /* ... */
}

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Jan 12, 2022

Sounds like a good approach. 👍

0reactions
eladavroncommented, Jan 12, 2022

Thanks. It just occurred to me though, I can replace it with a regex pattern instead of a string - it will have effectively the same purpose as a string but I won’t have to worry about quotes. I just have to make sure it has the same length as the original expression does to avoid having errors appear on the wrong columns, and make sure it’s valid to avoid false errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How z/OS performs synchronous to asynchronous conversion ...
Asynchronously, which means that the processor that issued the request is freed up to run another task rather than synchronously waiting or spinning,...
Read more >
Do GPU and CPU block each other? #1537 - GitHub
During gpu inference can we continue cpu pre/post-processing of other objects asynchronously? If yes, which way do you send data between ...
Read more >
asyncio-requests - PyPI
This library provides the functionality to make async API calls via HTTP / SOAP / FTP protocols via a config. Installation. pip install...
Read more >
Component Reference - Apache JMeter - User's Manual
This sampler lets you send an HTTP/HTTPS request to a web server. It ... Requests, you may want to use JMeter's HTTP(S) Test...
Read more >
Sharing Context in MediatR Pipelines - Jimmy Bogard
Here we're placing the current request user onto an items dictionary on the request object, so that subsequent behaviors/processors can then use ...
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