-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: Add public APIs for config-arrays and file-infos #52
Conversation
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your proposal.
I agree that exposing ConfigArray is worthful, but I feel that this goal and this proposal is different a bit because ConfigArray doesn't have enough information for that. There are related files to configurations:
- Config files
- Shareable config files -- it's needed to re-run when we upgraded shareable configs.
- Parser files -- it's needed to re-run when we upgraded parsers.
- Plugin files -- it's needed to re-run when we upgraded plugins.
- Rule files that
--rulesdir
option specified -- it's needed to re-run when we modified local rules. .eslintignore
-- it's needed to re-run when we modified.eslintignore
.- The files that are imported by
require("source")
in the above files. -- it's needed to re-run if config files or other files imported other files and the imported files are modified. - The files of ESLint -- it's needed to re-run when we upgraded ESLint. This is a common case because ESLint is regularly updated every month.
The filePath
property of ConfigArray contains 1., 2., and 6. But if we approve #9, it will contain only $CWD/eslint.config.js
because all other files become "the files that are imported by require("source")
." Therefore, I guess that the filePath
property of ConfigArray will be not useful for this purpose.
If you want to get only 1., actually, it may be hard to distinguish if the filePath
property of ConfigArray is 1. or not. Maybe true if the path is $CWD/**
but not node_modules/**
.
It's hard to know the files that are imported by require("source")
.
And Node.js has the cache for imported files. If we don't clear the cache, for example, when we updated plugin versions then the language server may use old plugin code partially and raise cryptic errors. Currently, we can clear the cache with require.cache
, but if we started to use import("source")
instead (it's required in order to support ES modules for plugins/configs) in the near future, we will lose the capability to clear the cache. Therefore, I think hard to re-run linting without restarting the Node.js process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Humh...
I totally get your point - adding such a method to the public API, in this case, wouldn't add the desired ability of knowing which files to watch.
import {} from "source";
, import "source";
and import var = require("source");
, btw, affect require.cache
as well so clearing or checking the cache would work out pretty well also for ES modules.
Anyway to reach the goal I'm after you'd have to import the plugins and settings and check require.cache
for changes, right?
Sounds like this would require another separate method other than getConfigArrayForFile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, affect require.cache as well so clearing or checking the cache would work out pretty well also for ES modules.
It's only if the "source"
was CJS. If the "source"
is ESM, Node.js caches it only in the internal cache and we cannot access it. The require.cache
doesn't include imported ESM files.
Anyway to reach the goal I'm after you'd have to import the plugins and settings and check require.cache for changes, right?
Currently, ESLint doesn't support ESM, so it may work. However, after we supported ESM, it's going to not work properly.
Sounds like this would require another separate method other than getConfigArrayForFile?
Yes. I think getConfigArrayForFile
is not useful for this purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright - so cleaning the cache is of no use as it will stop working at some point anyway...?
Forking a new process might be of no use, too, as this would draw me unable to get the result from eslint
... Or is there some way to pass JavaScript-objects from/to forked processes or any other alternative?
Yes. I think
getConfigArrayForFile
is not useful for this purpose.
Fine - shall we cover both the getConfigArrayForFile
and the language-server stuff in this RFC?
Co-Authored-By: Toru Nagashima <public@mysticatea.dev>
@mysticatea is there something left to discuss? |
Summary
Allow 3rd-party developers to determine which configuration-files are considered by
eslint
.Related Issues
ConfigArrayFactory
andCascadingConfigArrayFactory
to the public API eslint#12631