eslint-plugin-json icon indicating copy to clipboard operation
eslint-plugin-json copied to clipboard

Support flat config

Open sdavids opened this issue 2 years ago • 3 comments

https://eslint.org/blog/2023/10/flat-config-rollout-plans/

sdavids avatar Oct 19 '23 15:10 sdavids

But it works with flat config, doesn't it?

const json = require('eslint-plugin-json');

module.exports = [
  {
    files: ['**/*.json'],
    plugins: { json },
    processor: json.processors['.json'],
    rules: json.configs.recommended.rules,
  },
]

4a-ge avatar Oct 20 '23 15:10 4a-ge

It looks like it will work that way, but it the plug-in can also be migrated to support flag configuration better:

https://eslint.org/docs/latest/extend/plugin-migration-flat-config

(it can also support both new & old).

Standard8 avatar Oct 22 '23 12:10 Standard8

Also, update README with flat config example(s).

sdavids avatar Oct 28 '23 16:10 sdavids

in Eslint v9 the work-around of @4a-ge does not work unchanged - the recommended ruleset throws. I used

import globals from "globals";
import pluginJs from "@eslint/js";
import pluginJson from "eslint-plugin-json";

export default [
  pluginJs.configs.recommended,
  pluginJson.configs.recommended,
  {
    files: [ '**/*.js' ],
    languageOptions: {
      globals: globals.nodeBuiltin,
    },
    rules: {
    },
  },
  {
    files: [ '**/*.json' ],
    plugins: {
      pluginJson,
    },
    processor: pluginJson.processors['.json'],
    rules: {
      ...pluginJson.configs.recommended.rules
    },
  }
];

and got

Oops! Something went wrong! :(

ESLint: 9.1.1


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: {
            json: 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

Manual config works, but I prefer using recommended configurations.

  {
    files: [ '**/*.json' ],
    plugins: {
      pluginJson,
    },
    processor: pluginJson.processors['.json'],
    rules: {
      'pluginJson/*': 'error',
    },
  }

BePo65 avatar Apr 28 '24 04:04 BePo65

in Eslint v9 the work-around of @4a-ge does not work unchanged - the recommended ruleset throws. I used

...

export default [
  pluginJs.configs.recommended,
  pluginJson.configs.recommended,

This is incorrect you're trying to include the whole recommended configuration, whereas you want to only include .rules as you attempted to below:

  {
    files: [ '**/*.json' ],
    plugins: {
      pluginJson,
    },
    processor: pluginJson.processors['.json'],
    rules: {
      ...pluginJson.configs.recommended.rules
    },
];

I suspect if you took out those first two lines it would work fine.

Standard8 avatar Apr 28 '24 07:04 Standard8