ota-meshi / eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
https://ota-meshi.github.io/eslint-plugin-jsonc/
MIT License
181 stars 17 forks source link

flat config does not work as documented #313

Closed danielrentz closed 3 months ago

danielrentz commented 3 months ago

When using config "flat/recommended-with-json" (eslint.config.js) in an environment linting .js and .json together, the plugin fails:

TypeError: Key "rules": Key "jsonc/comma-dangle": Could not find plugin "jsonc".

Root cause seems that the config contains two objects. The first one correctly configures the plugin. However, the second object contains the recommended rules without a "files" property, thus ESLint tries to apply these rules on all JS files.

My current workaround is:

return [
  // ...
  eslintPluginJson.configs["flat/recommended-with-json"][0],

  {
    files: ["**/*.json"],
    rules: {
      ...eslintPluginJson.configs["flat/recommended-with-json"][1].rules,
      // ... extra rules
    },
  }
];

See also https://github.com/ota-meshi/eslint-plugin-yml/issues/310