Skip to content
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

Closed
wants to merge 2 commits into from
Closed

New: Add public APIs for config-arrays and file-infos #52

wants to merge 2 commits into from

Conversation

manuth
Copy link

@manuth manuth commented Dec 9, 2019

Summary

Allow 3rd-party developers to determine which configuration-files are considered by eslint.

Related Issues

@jsf-clabot
Copy link

jsf-clabot commented Dec 9, 2019

CLA assistant check
All committers have signed the CLA.

@manuth manuth changed the title Add a new RFC concerning public APIs for config-arrays New: Add a new RFC concerning public APIs for config-arrays Dec 9, 2019
@manuth manuth changed the title New: Add a new RFC concerning public APIs for config-arrays New: Add public APIs for config-arrays Dec 9, 2019
@mysticatea mysticatea added Initial Commenting This RFC is in the initial feedback stage and removed triage labels Dec 9, 2019
designs/2019-public-config-array-api/README.md Outdated Show resolved Hide resolved
Comment on lines +13 to +16
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`.
Copy link
Member

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:

  1. Config files
  2. Shareable config files -- it's needed to re-run when we upgraded shareable configs.
  3. Parser files -- it's needed to re-run when we upgraded parsers.
  4. Plugin files -- it's needed to re-run when we upgraded plugins.
  5. Rule files that --rulesdir option specified -- it's needed to re-run when we modified local rules.
  6. .eslintignore -- it's needed to re-run when we modified .eslintignore.
  7. 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.
  8. 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.

Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

@manuth manuth Dec 11, 2019

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>
@manuth manuth changed the title New: Add public APIs for config-arrays New: Add public APIs for config-arrays and file-infos Dec 11, 2019
@manuth
Copy link
Author

manuth commented Jan 15, 2020

@mysticatea is there something left to discuss?
I'm a little unsure whether or not to split this request up into 2 RFCs. What do you think?

@nzakas
Copy link
Member

nzakas commented Mar 6, 2020

Given that we are now moving forward with #9, I don't think it makes sense to continue down this path of exposing more configuration details from ESLint.

If there's something that makes sense in #9 to expose for this purpose, you can certainly update the RFC to reflect this.

@manuth manuth closed this May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Initial Commenting This RFC is in the initial feedback stage
Projects
None yet
4 participants