import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.53k stars 1.56k forks source link

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

Open saschanaz opened 1 week ago

saschanaz commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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

michaelfaith commented 1 week ago
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 commented 1 week ago

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'
    }
  }
];
saschanaz commented 1 week ago

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

ljharb commented 1 week ago

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

saschanaz commented 1 week ago

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

saschanaz commented 1 week ago

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

ljharb commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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.