eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

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

Open saschanaz opened this issue 1 year ago • 11 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?

saschanaz avatar Oct 07 '24 13:10 saschanaz

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 avatar Oct 07 '24 17:10 michaelfaith

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

TheJaredWilcurt avatar Oct 07 '24 17:10 TheJaredWilcurt

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

michaelfaith avatar Oct 07 '24 17:10 michaelfaith

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

TheJaredWilcurt avatar Oct 07 '24 17:10 TheJaredWilcurt

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

saschanaz avatar Oct 08 '24 08:10 saschanaz

@saschanaz https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#config---flat-eslintconfigjs already says "all rules are off by default".

ljharb avatar Oct 09 '24 01:10 ljharb

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

saschanaz avatar Oct 09 '24 11:10 saschanaz

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

saschanaz avatar Oct 09 '24 11:10 saschanaz

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.

ljharb avatar Oct 10 '24 01:10 ljharb

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.

saschanaz avatar Oct 10 '24 07:10 saschanaz

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.

ljharb avatar Oct 10 '24 07:10 ljharb

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

dandv avatar Nov 05 '24 08:11 dandv

Sure, it'd be good to add both.

ljharb avatar Nov 05 '24 11:11 ljharb