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

Add prefer-module rule #1141

Merged
merged 8 commits into from Apr 21, 2021
Merged

Add prefer-module rule #1141

merged 8 commits into from Apr 21, 2021

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Mar 17, 2021

Fixes #1067

@fisker
Copy link
Collaborator Author

fisker commented Apr 13, 2021

I'm almost done here, questions:

  1. Should we ignore .cjs file? Or let user to choose?
  2. I used suggestion instead of auto-fix, I think all these fix breaks code. (expect removing "use strict"), WDYT?
  3. Anything missing?

@fisker
Copy link
Collaborator Author

fisker commented Apr 20, 2021

@sindresorhus ^

@sindresorhus
Copy link
Owner

Should we also enforce using "type": "module" in package.json?

@sindresorhus
Copy link
Owner

  1. I would not. We could publish and see if someone opens an issue requesting it before we add an option.
  2. Makes sense. Even use strict is not technically safe to remove as it can change semantics if not in an ESM context, as it then makes the code non-strict.
  3. I think you covered it all.

@fisker
Copy link
Collaborator Author

fisker commented Apr 21, 2021

Even use strict is not technically safe to remove as

You are right, but it most likely not going to cause problem, let's keep it this way for now.

@fisker
Copy link
Collaborator Author

fisker commented Apr 21, 2021

Should we also enforce using "type": "module" in package.json?

I don't think so, package.json self is not JavaScript file, it will not be linted normally, and if we report this problem in a .js file seems weird.

@fisker
Copy link
Collaborator Author

fisker commented Apr 21, 2021

Maybe we can create eslint-plugin-package-json 😄

@fisker fisker marked this pull request as ready for review April 21, 2021 09:35
@sindresorhus
Copy link
Owner

Maybe we can create eslint-plugin-package-json 😄

I think it's too much work to maintain a plugin just for that. How about an opt-in package-json rule in this repo?

@sindresorhus
Copy link
Owner

I pushed some docs improvements.

@sindresorhus
Copy link
Owner

Did you implement #1067 (comment)?

@sindresorhus sindresorhus merged commit a7e393c into sindresorhus:main Apr 21, 2021
@sindresorhus
Copy link
Owner

Awesome!

@fisker fisker deleted the prefer-module branch April 21, 2021 18:02
bmish added a commit to bmish/eslint-plugin-unicorn that referenced this pull request Apr 21, 2021
bmish added a commit to bmish/eslint-plugin-unicorn that referenced this pull request Apr 21, 2021
* main:
  Add `prefer-module` rule (sindresorhus#1141)
  Fix swapped rule descriptions (sindresorhus#1187)
@yoyo837
Copy link

yoyo837 commented Apr 25, 2021

Excuse me, How can i disable this rule in nodejs code file? For example, webpack config files.

@fisker
Copy link
Collaborator Author

fisker commented Apr 25, 2021

{
	overrides: [
		{
			files: [],
			rules: {
				'unicorn/prefer-module': 'off'
			}
		}
	]
}

https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-based-on-glob-patterns

@yoyo837
Copy link

yoyo837 commented Apr 25, 2021

Thanks.

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 this pull request may close these issues.

Rule proposal: prefer-module
3 participants