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

No way to import the bare plugin without predefined flat config? #3083

Open
saschanaz opened this issue Oct 7, 2024 · 13 comments
Open

No way to import the bare plugin without predefined flat config? #3083

saschanaz opened this issue Oct 7, 2024 · 13 comments

Comments

@saschanaz
Copy link
Contributor

For the flat config it seems the only way to import the plugin is to load it from the generated flat configs through flatConfigs, and there's no way to import the bare plugin without any enabled rules (e.g. just to use a certain rule without applying everything). Is this intended?

@michaelfaith
Copy link
Contributor

I'm not sure what you mean. Importing the plugin doesn't inherently apply any rules, unless you add one of the configs to your config array. Having configs attached to the plugin object, doesn't apply those configs.

@TheJaredWilcurt
Copy link
Contributor

@michaelfaith can you give a code example of what you mean

@michaelfaith
Copy link
Contributor

import importPlugin from 'eslint-plugin-import';
import tsParser from '@typescript-eslint/parser';

export default [
  {
    files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
    plugins: {
      import: importPlugin,
    },
    languageOptions: {
      parser: tsParser,
      ecmaVersion: 'latest',
      sourceType: 'module',
    },
    rules: {
      'import/no-cycle': 'warn',
    },
  },
];

@TheJaredWilcurt
Copy link
Contributor

So, with the irrelevant stuff removed, this then:

import pluginImport from 'eslint-plugin-import';

export default [
  {
    files: [
      '**/*.{js,mjs,cjs}'
    ],
    plugins: {
      import: pluginImport
    },
    rules: {
      'import/no-cycle': 'warn'
    }
  }
];

@ljharb ljharb closed this as completed Oct 7, 2024
@saschanaz
Copy link
Contributor Author

saschanaz commented Oct 8, 2024

I'm not sure how it's completed unless anyone already added it into some doc 🤔

@ljharb
Copy link
Member

ljharb commented Oct 9, 2024

@saschanaz
Copy link
Contributor Author

Huh, that's not what I see, I had to disable no-resolve explicitly 🤔

@saschanaz
Copy link
Contributor Author

saschanaz commented Oct 9, 2024

And you can't just enable any import/ rule without adding any preset. (An "empty" preset would be nice)

@ljharb
Copy link
Member

ljharb commented Oct 10, 2024

Again, all rules are off by default - the only way a rule could be enabled is if you explicitly pulled in a config that enabled it.

@saschanaz
Copy link
Contributor Author

I'm saying that there's no traditional off by default configuration that is documented. Either the plugin is not loaded at all or the preset is loaded. No documented way to just enable one of the rules without preset.

@ljharb
Copy link
Member

ljharb commented Oct 10, 2024

Ah - i see what you mean.

Then yes, https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#config---flat-eslintconfigjs should have an example added using the plugin and NOT using an existing config.

@dandv
Copy link

dandv commented Nov 5, 2024

Should there be a flatConfig version for the Typescript section as well?

@ljharb
Copy link
Member

ljharb commented Nov 5, 2024

Sure, it'd be good to add both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants