gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.09k stars 157 forks source link

jsdoc/recommend error when using Flat Config #1131

Closed snebjorn closed 1 year ago

snebjorn commented 1 year ago

Expected behavior

Recommended config works.

This is actually the official ESLint docs https://eslint.org/docs/latest/use/configure/configuration-files-new#using-configurations-included-in-plugins

Using configurations included in plugins

You can use a configuration included in a plugin by adding that configuration directly to the eslint.config.js configurations array. Often, you do this for a plugin’s recommended configuration. Here’s an example:

import jsdoc from "eslint-plugin-jsdoc";

export default [
    // configuration included in plugin
    jsdoc.configs.recommended,
    // other configuration objects...
    {
        files: ["**/*.js"],
        plugins: {
            jsdoc: jsdoc
        },
        rules: {
            "jsdoc/require-description": "warn",
        }
    }
];

Actual behavior

Oops! Something went wrong! :(

ESLint: 8.44.0

TypeError: Key "plugins": Key "0": Expected an object. at Object.validate (myrepo\node_modules\eslint\lib\config\flat-config-schema.js:315:23) at ObjectSchema.validate (myrepo\node_modules\@humanwhocodes\object-schema\src\object-schema.js:218:35) at myrepo\node_modules\@humanwhocodes\object-schema\src\object-schema.js:171:18 at Array.reduce () at ObjectSchema.merge (myrepo\node_modules\@humanwhocodes\object-schema\src\object-schema.js:169:24) at myrepo\node_modules\@humanwhocodes\config-array\api.js:916:42 at Array.reduce () at FlatConfigArray.getConfig (myrepo\node_modules\@humanwhocodes\config-array\api.js:915:39) at FlatConfigArray.isFileIgnored (myrepo\node_modules\@humanwhocodes\config-array\api.js:943:15) at myrepo\node_modules\eslint\lib\eslint\eslint-helpers.js:312:49

ESLint Config

Flat config

import jsdoc from "eslint-plugin-jsdoc";

export default [
  jsdoc.configs.recommended,
  // omitted...
];

ESLint sample

It's a problem with the config. So running eslint should trigger the error.

$ eslint .

Environment

Workaround

I got it working using this workaround

import jsdoc from "eslint-plugin-jsdoc";

export default [
  {
    ...jsdoc.configs.recommended,
    plugins: {
      jsdoc,
    },
  },
  // omitted...
];
kkmuffme commented 1 year ago

Same for me.

Also reported in eslint to improve their error message for those case https://github.com/eslint/eslint/issues/17369

kkmuffme commented 1 year ago

See https://github.com/eslint/eslint/issues/17355

brettz9 commented 1 year ago

I've posted #1147 if anyone might take a look.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 46.5.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: