Change Request: Make processors (pre/post) async or pass config to them
See original GitHub issueESLint 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sounds like a good approach. 👍
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.