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

Autodetect module type in recommends for FlatConfig #105

Closed
coderaiser opened this issue Aug 10, 2023 · 10 comments · Fixed by #111
Closed

Autodetect module type in recommends for FlatConfig #105

coderaiser opened this issue Aug 10, 2023 · 10 comments · Fixed by #111

Comments

@coderaiser
Copy link

coderaiser commented Aug 10, 2023

Would be great to have ability to require recommended preset with auto detect ESM/CommonJS in a similar to CommonJS way:

const nodeRecommendedScript = require("eslint-plugin-n/configs/recommended-script");

module.exports = [
    nodeRecommendedScript,
    {
        rules: {
            "n/exports-style": ["error", "module.exports"]
        }
    }
]

So it looks like:

const nodeRecommended = require("eslint-plugin-n/configs/recommended");

module.exports = [
    nodeRecommended,
]
@coderaiser
Copy link
Author

Could you please publish new version :)?

@aladdin-add
Copy link

I'll release it when #114 get merged.

@coderaiser
Copy link
Author

coderaiser commented Sep 11, 2023

I have an error:

TypeError: Key "plugins": Cannot redefine plugin "n".
image image

Coud you please help me with this?

@aladdin-add
Copy link

what is your config?

@aladdin-add
Copy link

seems like it's an issue that has been fixed. can you upgrade eslint to latest and retry?

eslint/eslint#16277

@coderaiser
Copy link
Author

coderaiser commented Sep 11, 2023

Here is my config https://github.com/coderaiser/putout/blob/v31.8.5/packages/eslint-plugin-putout/lib/config/index.js#L13,

what I changed is:

-const n = compat.config(nPlugin.configs.recommended);
+const n = nPlugin.configs['flat/mixed-esm-and-cjs'];

I have latest version of ESLint
image

I have this config-array-factory.js loaded:

image

@aladdin-add
Copy link

aladdin-add commented Sep 12, 2023

technically you cannot define a namespace for different plugins:

[plugins: {n: obj1}],
[plugins: {n: obj2}],

it will throw an error as you described.

In your case, you were using eslintrc and flat configs:

  • @eslint/eslintrc to translate plugins: ["n"] to plugins: {n: obj} - obj is a normalized plugin object.
  • flat/mixed-esm-and-cjs: plugins: {n: mod} - mod is another plugin object.

@aladdin-add
Copy link

so, this is not an issue in the package. I would recommend converting all the used eslint-plugin-n configs to flat.

I'm willing to make a PR for putout if you like. :)

@aladdin-add
Copy link

@coderaiser
Copy link
Author

What about this rules I disabled?

image

Plugin n not required for them? And if it is absent they will be just ignored, is it right?

It works good, thank you!

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

Successfully merging a pull request may close this issue.

2 participants