eslint-plugin-json
eslint-plugin-json copied to clipboard
Support flat config
https://eslint.org/blog/2023/10/flat-config-rollout-plans/
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,
},
]
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).
Also, update README with flat config example(s).
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',
},
}
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.