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

the "plugins" field in presets need to be an object #79

Closed
StarHeartHunt opened this issue May 16, 2024 · 1 comment
Closed

the "plugins" field in presets need to be an object #79

StarHeartHunt opened this issue May 16, 2024 · 1 comment

Comments

@StarHeartHunt
Copy link

When i am migrating from eslintrc to flat config, i got the following error

> eslint .


Oops! Something went wrong! :(

ESLint: 9.2.0


A config object has a "plugins" key defined as an array of strings.

Flat config requires "plugins" to be an object in this form:

    {
        plugins: {
            import-x: pluginObject
        }
    }

Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#importing-plugins-and-custom-parsers

If you're using a shareable config that you cannot rewrite in flat config format, then use the compatibility utility:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

 ELIFECYCLE  Command failed with exit code 2.

After some research, i found the "plugins" key is defined in recommended preset:

Is it supposed to be a virtual plugin or a module? I'm glad to help improving it.

Full code example
import pluginImportX from "eslint-plugin-import-x";

export const imports = [
  pluginImportX.configs.recommended,
  pluginImportX.configs.typescript,
  {
    plugins: {
      import: pluginImportX,
    },
    rules: {
      "import-x/no-named-as-default": "off",
      "import-x/no-unresolved": ["error", { ignore: ["^virtual:"] }],
      "import-x/order": [
        "error",
        {
          groups: [
            "builtin",
            "external",
            "internal",
            "parent",
            "sibling",
            "index",
          ],
          pathGroups: [
            { pattern: "vue", group: "builtin", position: "before" },
          ],
          pathGroupsExcludedImportTypes: [],
          "newlines-between": "always",
          alphabetize: {
            order: "asc",
          },
        },
      ],
    },
  },
];

export default [
  ...imports
];
@JounQin
Copy link
Member

JounQin commented May 16, 2024

The configs does not support flat config yet, see also #29

But you can config it manually by not using the configs

import pluginImportX from "eslint-plugin-import-x";

export default [
  {
    plugins: {
      import: pluginImportX
    },
    rules: {
      "import/order": ["error"] // make sure to use same prefix as you defined above in `plugins`
    }
  }
]

@JounQin JounQin closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants