eslint / markdown

Lint JavaScript code blocks in Markdown documents
MIT License
406 stars 63 forks source link

TypeError: Converting circular structure to JSON #243

Closed moltar closed 8 months ago

moltar commented 8 months ago

After upgrading from 3.0.1 to 4.0.1 I've started to get the following error:

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Array'
    |     index 0 -> object with constructor 'Object'
    |     property 'plugins' -> object with constructor 'Object'
    |     ...
    |     property 'configs' -> object with constructor 'Object'
    --- property 'recommended' closes the circle
Referenced from: /prj/.eslintrc.json
    at JSON.stringify (<anonymous>)
    at /prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:45
    at Array.map (<anonymous>)
    at ConfigValidator.formatErrors (/prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2147:23)
    at ConfigValidator.validateConfigSchema (/prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:84)
    at ConfigArrayFactory._normalizeConfigData (/prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadExtendedPluginConfig (/prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3239:25)
    at ConfigArrayFactory._loadExtends (/prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3154:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/prj/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3095:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)

Is this the expected behaviour due to flat config change?


Simplified config:

{
  "env": {
    "jest": true,
    "node": true
  },
  "root": true,
  "plugins": [
    "markdown"
  ],
  "overrides": [
    {
      "extends": [
        "plugin:markdown/recommended"
      ],
      "files": [
        "**/*.md"
      ],
      "processor": "markdown/markdown"
    },
    {
      "files": [
        "**/*.md/*.+(cjs|cts|js|jsx|mjs|mts|ts|tsx)"
      ],
      "rules": {

      },
      "parserOptions": {
        "project": false
      }
    },
  ]
}
mdjermanovic commented 8 months ago

Hi @moltar, thanks for the issue!

recommended config is now in the new flat config format. Since you're using eslintrc config format, can you try with plugin:markdown/recommended-legacy:

{
  "env": {
    "jest": true,
    "node": true
  },
  "root": true,
  "plugins": [
    "markdown"
  ],
  "overrides": [
    {
      "extends": [
-       "plugin:markdown/recommended"
+       "plugin:markdown/recommended-legacy"
      ],
      "files": [
        "**/*.md"
      ],
      "processor": "markdown/markdown"
    },
    {
      "files": [
        "**/*.md/*.+(cjs|cts|js|jsx|mjs|mts|ts|tsx)"
      ],
      "rules": {

      },
      "parserOptions": {
        "project": false
      }
    },
  ]
}

https://github.com/eslint/eslint-plugin-markdown?tab=readme-ov-file#configuring

simlu commented 8 months ago

That fixed it. Could this be handled without forced changes? I.e. could the way this is important be automatically detected?

mdjermanovic commented 8 months ago

No, plugin:markdown/recommended is just a reference to configs.recommended configuration from the markdown plugin, which is now in a different format.