import-js/eslint-plugin-import

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

saschanaz opened this issue ยท 13 comments

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?

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.

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

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',
    },
  },
];

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'
    }
  }
];

I'm not sure how it's completed unless anyone already added it into some doc ๐Ÿค”

Huh, that's not what I see, I had to disable no-resolve explicitly ๐Ÿค”

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

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.

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.

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.