-
Notifications
You must be signed in to change notification settings - Fork 241
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
feat: support new config system #1245
feat: support new config system #1245
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super exciting, thanks!
"main": "lib/legacy.js", | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I don't think we produce ESM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exports
can benefit CJS projects, like eslint-plugin-jest.
There's a difference in module resolution between the legacy and new config system.
In the legacy config system, as we know,
- A shareable config or plugin is not loaded(
require
orimport
) in eslintrc.js. - Instead, a user just specifies the name as a string (e.g.
plugin:jest/recommended
orplugin: [ 'jest' ]
), and eslint internallyrequire()
(notimport()
) them.
In the new config system,
- A shareable config or plugin is explicitly loaded by a user, directly or transitively, following the native module resolution by nodejs. eslint does not load by itself anymore.
- A shareable config or plugin can be
require
d orimport
ed, as eslint support both CJS and ESM for eslint.config.js.
Thus,
if ( the plugin is require()d ){
the user is either using legacy or new config system.
} else if( the plugin is import()ed ) {
the user is using new config system
}
Therefore, by this PR,
- A user who uses the legacy config system can let eslint to do
require('eslint-plugin-jest')
. This is not breaking change. - A user who uses the new config system in ESM can
import jest from 'eslint-plugin-jest'
. This feels natural. This can be possible by the conditional export. - A user who uses the new config system in CJS can
require( 'eslint-plugin-jest/new')
.
tbh I'm kind of tempted to ignore the new config format until v9 of ESLint is released, from a documentation perspective - I'm really looking forward to it and am happy with doing the minimum we need to let people start using it now, but it feels like it could be taxing on our brains to deal with ensuring we have clean documentation for both config formats everywhere (we could still have something saying we do support the new config format though). What do people think? |
Adding support for the new config format is very good idea, but the amount of documentation is currently overwhelming. How do other plugins deal with this? Perhaps it would be enough mentioning: " |
I think we don't have to change |
@jjangga0214 my understanding is that technically the config for rules is slightly changed, but it is actually the Readme change that I'm not happy with currently - I think we should just have a short sentence saying we're compatible with the new config system with a link to the docs, and leave it as that for now. Then we can switch over when ESLint v9 is released. |
@G-Rath |
@jjangga0214 I understand that, but that documentation should ideally be consistent with the surrounding content otherwise it can be jaring and confusing, which can undermine that feeling of assurance. I'm generally happy to help with documentation but I'm pretty busy right now, still have not had a chance to checkout the new config system myself, and in the meantime (from what I understand) without this PR people can't use this plugin at all with the new config system; so I think let's go with the simpler form here to get this landed, and then we can bikeshed about the documentation in another dedicated PR :) (Also ESLint v8 is about two weeks shy of being a year old, so we might only be waiting a month or two before v9 comes out anyway) |
@G-Rath I allowed editing by maintainers. |
As someone who's also trying to migrate to the new config format and uses this plugin it would be great to get support on this. |
Either conditional exports or create a new package name since plugins no longer need to be prefixed with Either way, would be nice to see this effort completed. Currently, I'm modifying it myself in import js from '@eslint/js'
import globals from 'globals'
import jest from 'eslint-plugin-jest'
/**
* Can't extend jest's configuration due to the
* incompatibility between the classic config,
* and the new flat config. Change it here, for now.
* @see https://github.com/eslint/eslint/issues/17355
*/
jest.configs.recommended.plugins = { jest }
jest.configs.recommended.languageOptions = {
globals: {
...globals.jest
}
}
delete jest.configs.recommended.env
export default [
js.configs.recommended,
jest.configs.recommended,
{
languageOptions: {
ecmaVersion: 2023,
sourceType: 'module',
globals: {
...globals.node,
...globals.jest
}
},
files: ['**/*.js'],
plugins: {
jest
},
rules: {
'no-console': 'error'
}
}
] |
Closing in favor of #1408 |
Supporting eslint's new config system of eslint.
The legacy config system always has
require()
d plugins and sharable configs, while the new system is available in both ESM and CJS.Therefore conditional export is great to keep compatibility while introducing the new config.
plugin:
protocol(e.g.plugin:jest/recommended
) is not valid any more. In the new config system, a bi-directional dependency between a plugin object and a preset config object is detached. From now on, only a config object should depend on a plugin object, not vice-versa. Thus, the new plugin (a new entry point index.js) doesn't haveconfigs
property, following the spec, though having the property does not mean incompatibility.Users should have a way to import shareable configs independently.
Hence
eslint-plugin-jest/all
,eslint-plugin-jest/recommended
,eslint-plugin-jest/style
are introduced as new entrypoints.