-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Change Request: Add API for integrators to easily swap between flat config and eslintrc APIs #18075
Comments
To summarize what @dbaeumer said:
And also:
|
Hmm, I see. I think something like that is doable, but I'm not sure this design makes sense. First, we only have one Second, the fact that there is a So, it seems like what you really need is something that allows you to write code like this: import { loadESLint } from "eslint";
// retrieve FlatESLint
const ESLint = await loadESLint(true);
// or
// retrieve LegacyESLint
const ESLint = await loadESLint(false); And maybe Would that make sense? |
I was thinking if we could support an option // eslint v8
const eslint = new ESLint(); // defaults to configType: "eslintrc" // eslint v9
const eslint = new ESLint(); // defaults to configType: "flat", but "eslintrc" is allowed // eslint v10
const eslint = new ESLint(); // defaults to configType: "flat", and "eslintrc" is disallowed. Users can combine // works for all eslint >=8
const {shouldUseFlatConfig, ESLint} = require("eslint");
const configType = shouldUseFlatConfig() ? "flat" : "eslintrc";
const eslint = new ESLint({configType}); |
|
@aladdin-add We opted not to introduce a |
From an ease-of-use perspective, maybe we could call const { loadESLint } = require("eslint");
const ESLint = await loadESLint(); // FlatESLint or LegacyESLint
const eslint = new ESLint(); |
I was thinking something like this: const { loadESLint } = require("eslint");
const ESLint = await loadESLint({
useFlatConfig: true, // or false, or undefined to call shouldUseFlatConfig()
cwd: "."
}); @dbaeumer what do you think? |
@nzakas first thanks a lot for looking into this. I like the proposed approach. But to clarify: if in the future ESLint would add another feature we would add another flag. For example if it would use a new validation engine we would have a flah |
@dbaeumer yes, my proposed design was made with the intent that we could always add more flags if necessary. 👍 |
The TSC met today to discuss some further details on this:
@aladdin-add I know you started a PR, but I'm going to create a new one based on the discussions we had today. |
* feat: Add loadESLint() API method for v9 refs #18075 * Fix docs * Add more tests using environment variables
* feat: Add loadESLint() API method for v8 refs #18075 * Update docs * Add tests for loadESLint() to return ESLint * Move static property out of constructor for older Node.js versions * Add more tests * Update tests/lib/api.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update tests/lib/api.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Closing as the PRs for both branches have been merged. |
ESLint version
v8, v9
What problem do you want to solve?
Right now, we use the
/use-at-your-own-risk
entrypoint for accessing non-default objects likeFlatESLint
andLegacyESLint
, but doing so requires integrators to pull from different locations depending on which mode they want to run ESLint in. This is error-prone, especially if they don't know the version of ESLint ahead of time.What do you think is the correct solution?
Add an API, exported from the main entrypoint, that allows access to the correct APIs and provide that in v8, v9, and v10 to ease integration difficulty.
Potentially move
shouldUseFlatConfig
to the main entrypoint as an export.Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: