Add a shareable config
See original GitHub issueIf you were to export a shareable config, you could make usage require just one line in .eslintrc
, for example:
{
"extends": ["simple-import-sort/recommended"]
}
This would also allow you to adjust the recommended config to enable additional recommended rules with future releases.
Many packages use this approach, a good example is here: https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/index.js
export const configs = {
recommended: {
plugins: ['react-hooks'],
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
},
},
};
Docs are here: https://eslint.org/docs/developer-guide/shareable-configs#sharing-multiple-configs
Thanks, very helpful plugin!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Shareable Configs - ESLint - Pluggable JavaScript Linter
Shareable configs are simply npm packages that export a configuration object. To start, create a Node.js module like you normally would. Make sure...
Read more >How to create a shareable eslint config
The short answer is simples, you need to create a config or plugin that will extend and set all the base rules you...
Read more >10up/eslint-config: A shareable ESLint config. - GitHub
@10up/eslint-config is a shareable configuration package for eslint built on top of eslint-airbnb-config and modified to meet 10up's own standards.
Read more >How to Create Your Own ESLint Config Package
The documentation mentions that if your shareable config depends on a plugin, you should also specify it as a peerDependency .
Read more >How ESLint Resolves Plugins And Shareable Configs
Plugins vs shareable configs · Shareable config —holds a reusable config (think of it as a ruleset). Example: eslint-config-airbnb · Plugin — can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you can
!!require.resolve('eslint-plugin-import')
to check if another plugin is installed.I use 7 fairly common ESLint plugins/configs and this is the only one that doesn’t ship a shareable config. It became more noticeable when I upgraded and needed to change my rules; if I’d been extending a config you shipped, you would have been able to add the new export rules to that config with the major release.
If you control the standard config most people use, I just figure it’s easier for people to install it and use it and maintain it. You maybe get fewer issues filed too. It’s not a huge thing either way, just a nice convenience!
Thanks!
I’ve been thinking about restructuring the docs a little. Personally, I never turn off
sort-imports
andimport/order
, because I don’t even turn them on in the first place. I also never set thesimple-import-sort
rules toerror
– I set them towarning
during development and toerror
in CI (this way I get yellow underlines in VSCode instead of red).So all that you need to do is adding
"simple-import-sort"
toplugins
and enable the rules you want at the places you want. Then, you just need to make sure there are no conflicting rules. If there are, remove or disable them.Btw,
"import/order": "off"
fails if that plugin isn’t installed:So then the recommended config just enables the two rules from this package and disables one. Does that gain anything? I’m worried it just makes things unclear. Now people have to look up what
simple-import-sort/recommended
means.EDIT: I was wrong about
"import/order": "off"
. That’s fine. It does not result in errors.