- Start Date: 2019-12-09
- RFC PR:
- Authors: @manuth
Allow 3rd-party developers to determine which configuration-files are considered by eslint
.
In some cases people might want to automatically trigger a new linting process as soon as the configuration of eslint has changed. This is a key feature for language servers which provide warnings and fixes to IDEs.
Therefore the language-server needs to know which config-files are considered by eslint
.
A method called getConfigArrayForFile()
shall be added to the CLIEngine
class.
By providing such a feature people can easily watch the correct files for changes as soon as the configuration changes.
Example:
import fs = require("fs");
let engine = new CLIEngine({});
let file = "./App/src/index.ts";
let configArray = engine.getConfigArrayForFile(file);
for (let config of configArray) {
if (config.filePath.length > 0) {
fs.watchFile(
conig.filePath,
() =>
{
lint();
});
}
}
function lint() {
engine.executeOnFiles([file]);
}
lint();
I think it might be a good idea to blog about this new feature as this is a key feature for writing language servers for IDEs.
That way the integration of eslint
in all sorts of text-editors can be improved to its best.
The only downside I can think of is that on every change to the ConfigArray
or CascadingConfigArray
API either a new major version has to be released or a separate implementation of said classes has to be added for the public API.
Adding this feature provides full backwards compatibility.
Add a method which only returns filepaths and a value indicating whether said filepath is root
.
That way the drawbacks could be fixed but the developers don't have the benefit to further analyze the config-array.
A similar method already exists: The CLIEngine#getConfigForFile
-method. Though this method does not indicate which files are considered by eslint
which draws developers of language-servers unable to hot-reload eslint
as soon as a config-file changes.
- Is it reasonable to return the whole config-array or should such a method only return the
filePath
s? - Does it make sense to also return the
root
-directory in order to let language-servers runeslint
withroot
as itscwd
? - Is there some more key information other than
filePath
which should be returned? (Such asname
, for instance)
I think it should be pretty easy to implement such a feature as the only thing that is required is a simple call to CascadingConfigArrayFactory#getConfigArrayForFile
and, if required, some data extraction/manipulation.