question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a shareable config

See original GitHub issue

If 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
aaronadamsCAcommented, Feb 4, 2021

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!

2reactions
lydellcommented, Feb 25, 2021

Thanks!

I’ve been thinking about restructuring the docs a little. Personally, I never turn off sort-imports and import/order, because I don’t even turn them on in the first place. I also never set the simple-import-sort rules to error – I set them to warning during development and to error 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" to plugins 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:

Definition for rule ‘import/order’ was not found

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found