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

Disable unicorn/prefer-module in certain files #540

Closed
jonahsnider opened this issue May 10, 2021 · 9 comments
Closed

Disable unicorn/prefer-module in certain files #540

jonahsnider opened this issue May 10, 2021 · 9 comments

Comments

@jonahsnider
Copy link
Contributor

jonahsnider commented May 10, 2021

Some tools don't currently support ECMAScript modules for configuration yet. For example, Prettier requires a JavaScript config to export an object with module.exports. The unicorn/prefer-module rule should be disabled for known configuration files that must use CommonJS.

Files to consider ignoring:

  • .prettierrc.js
  • .prettierrc.cjs
  • prettier.config.js
  • prettier.config.cjs
  • next.config.js
@sindresorhus
Copy link
Member

We can disable it for all .cjs files.

@jonahsnider
Copy link
Contributor Author

I considered doing the same but some projects may use .cjs extensions in the source and still benefit from the warning.

@sindresorhus
Copy link
Member

If you're using .cjs, you're intentionally opting out of ESM.

@fregante
Copy link
Member

fregante commented Jul 6, 2021

I think it should be ignored on

*.cjs
*.config.js
.*.js //if supported
!.any.config.that.we.know.supports.it.config.js

@sindresorhus
Copy link
Member

@fregante Why complicate it? You can just use .cjs for those. It's only temporary anyway. Most tools will support ESM this year.

@fregante
Copy link
Member

fregante commented Jul 6, 2021

You can just use .cjs for those

Can you? The issue here is that tools don't yet fully support these changes. You can chose to let the user deal with it or you can avoid enforcing the rule for a few more months until tools catch up. Either way is ok for me.

@sindresorhus
Copy link
Member

The tools I use support .cjs now, but PR welcome if you want to add a temporary override for the cases you mentioned.

@sindresorhus
Copy link
Member

And the latest XO version ignores .cjs: https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v34.0.0

@fregante
Copy link
Member

fregante commented Aug 6, 2022

This leads me to believe that this issue can be closed as it's been resolved

Screen Shot

@fregante fregante closed this as completed Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants