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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDependencies called twice #665

Open
axelboc opened this issue Aug 9, 2022 · 2 comments
Open

getDependencies called twice #665

axelboc opened this issue Aug 9, 2022 · 2 comments

Comments

@axelboc
Copy link
Contributor

axelboc commented Aug 9, 2022

While I'm in the linting head-space, I might as well... 馃槀

Looking at the typical usage example I suggested for the README in #622 (comment):

const dependencies = getDependencies();

const customReactOverride = createReactOverride({
  ...dependencies,
  rules: {
    /* some rule overrides */
  }
});

module.exports = createConfig({
  rules: {
    /* some rule overrides */
  },
  overrides: [customReactOverride],
});

Something that bothers me (very slightly) with this is that getDependencies gets called twice: once explicitly to pass to createReactOverride, and once internally by createConfig.

I feel like this is a potential source of bug, for instance if you pass a different cwd to createConfig than to getDependencies, or if getDependencies() is located in a file inside a sub-directory (like on a monorepo) and you pass the file's __dirname to it... The two calls may end up looking at two different package.json files.

Here are some ideas to fix this:

  • createConfig could accept a dependencies object (could be confusing)
  • createConfig could be replaced with a new createConfigFromDependencies function, which would be called internally by createConfig -- createConfig would still exist for users who don't need to configure any overrides (this could also be confusing)
  • createConfig could accept an overrides object instead of an array and it would then be up to createConfig to create the overrides - e.g. overrides: { react: { rules: {... } } } (but this prevents customising the dependencies if needed)
  • createConfig could optionally accept functions as overrides that receive the dependencies as arguments - e.g. overrides: [(dependencies) => createReactOverride({ ...dependencies })] (best compromise, I think)
@ljosberinn
Copy link
Owner

Yea Im also not terribly happy with that either and actually believe passing dependencies to createConfig would be the simplest solution for everyone involved.

The third proposed solution wouldn't work because then you couldn't pass multiple react overrides. probably not a scenario that happens a lot but it would limit capabilities of overrides.

I do like the last approach the most, but would need to think about ways to make it compatible with generateStandalone. Might introduce it in v5 with ESLint's FlatConfig once its out (probably v9 on their end).

@axelboc
Copy link
Contributor Author

axelboc commented Aug 11, 2022

Thanks for the info, this flat config looks very, very promising! Much simplification ahead 馃帀

@ljosberinn ljosberinn mentioned this issue Aug 11, 2022
9 tasks
@ljosberinn ljosberinn mentioned this issue May 10, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants