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

Support flat config #80

Closed
sdavids opened this issue Oct 19, 2023 · 5 comments
Closed

Support flat config #80

sdavids opened this issue Oct 19, 2023 · 5 comments

Comments

@sdavids
Copy link

sdavids commented Oct 19, 2023

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

@4a-ge
Copy link

4a-ge commented Oct 20, 2023

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,
  },
]

@Standard8
Copy link
Contributor

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).

@sdavids
Copy link
Author

sdavids commented Oct 28, 2023

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

Standard8 added a commit to Standard8/eslint-plugin-json that referenced this issue Dec 30, 2023
Standard8 added a commit to Standard8/eslint-plugin-json that referenced this issue Dec 30, 2023
azeemba pushed a commit to Standard8/eslint-plugin-json that referenced this issue Dec 30, 2023
Standard8 added a commit to Standard8/eslint-plugin-json that referenced this issue Apr 20, 2024
@BePo65
Copy link
Contributor

BePo65 commented Apr 28, 2024

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',
    },
  }

@Standard8
Copy link
Contributor

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 added a commit to Standard8/eslint-plugin-json that referenced this issue May 12, 2024
Standard8 added a commit to Standard8/eslint-plugin-json that referenced this issue May 12, 2024
Standard8 added a commit to Standard8/eslint-plugin-json that referenced this issue May 12, 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

4 participants