I'm trying my hand at upgrading a very old ESLint plugin to something more modern.
One of the problems is that in ESLint 8+, the API for getting config from a file is now async, so what was previously:
preprocess(text, filename) {
const config = new CLIEngine({ useEslintrc: true }).getConfigForFile(path.resolve(filename));
/* ... */
return [preprocessed]
}
Is now:
async preprocess(text, filename) {
const eslint = new ESLint();
var config = await eslint.calculateConfigForFile(filename);
/* ... */
return [preprocessed]
}
The problem is that ESLint doesn't seem to expect the preprocess function to be async, so it ends up treating it as an array (which is its original return value) when it is in fact a Promise.
This could be easily solved by adding an await before whatever code calls for the preprocessor, but I'm not sure that's something I can configure (or can I? Please let me know if I can).
Is there any way to do what I'm trying to achieve? Can the preprocessor be called with await or can the config be retrieved synchronously?
Thanks in advance!
** UPDATE ** On their github, the eslint maintainers said what I'm looking to do isn't possible. I've instead elected to not use the config at all and find a different solution for my problem.