eslint-plugin-json-files
raw JSON → 5.1.2 verified Sat Apr 25 auth: no javascript
ESLint plugin and processor for linting JSON files, particularly package.json. Current stable version 5.1.2 requires Node >=20.9 and ESLint >=5. It provides 11 rules covering package.json hygiene: sorting, schema validation, dependency restrictions, engines requirements, and no branch dependencies. Unlike generic JSON linters, it focuses on package.json-specific rules. Supports flat config (eslint.config.js) via processor configuration. Released as needed, maintained by Kelly Selden.
Common errors
error Error: Failed to load plugin 'eslint-plugin-json-files' ↓
cause Plugin not installed or missing peer dependency 'eslint'.
fix
Run 'npm install eslint eslint-plugin-json-files --save-dev'.
error Error: Plugin 'eslint-plugin-json-files' uses processor but no processor was set ↓
cause Processor not configured in flat config.
fix
Add 'processor: 'json-files/json'' to the config object.
error Error: Cannot find module 'eslint-plugin-json-files' ↓
cause CommonJS require failing in ESM-only project.
fix
Use dynamic import: 'import jsonFiles from 'eslint-plugin-json-files';' or set "type": "commonjs".
error Rule 'json-files/sort-package-json' is not configured correctly ↓
cause Rule name missing the 'json-files/' prefix.
fix
Use 'json-files/sort-package-json' instead of 'sort-package-json'.
Warnings
breaking v5 drops support for legacy eslintrc config format; only flat config (eslint.config.js) is supported. ↓
fix Migrate from .eslintrc to eslint.config.js using the flat config format shown in the quickstart.
breaking Node.js >=20.9 required starting from v5. Older Node versions will fail to load the plugin. ↓
fix Upgrade Node.js to 20.9 or later.
gotcha Processor must be explicitly set to 'json-files/json' for JSON file linting; omitting it results in no linting of JSON files. ↓
fix Add processor: 'json-files/json' in the flat config object.
deprecated The rule 'json-files/ensure-repository-directory' is deprecated and will be removed in a future major version. ↓
fix Remove the rule from config or migrate to alternative validation.
gotcha Rules only apply to package.json by default; other JSON files need explicit file matching via config. ↓
fix Add 'files' or 'ignores' in config to target specific JSON files.
Install
npm install eslint-plugin-json-files yarn add eslint-plugin-json-files pnpm add eslint-plugin-json-files Imports
- default (plugin object)
const jsonFiles = require('eslint-plugin-json-files'); - processor 'json-files/json'
processor: 'json-files/json' - rules (e.g., 'json-files/sort-package-json') wrong
rules: { 'sort-package-json': 'error' }correctrules: { 'json-files/sort-package-json': 'error' }
Quickstart
// eslint.config.js
const jsonFiles = require('eslint-plugin-json-files');
module.exports = [
{
plugins: {
'json-files': jsonFiles,
},
processor: 'json-files/json',
rules: {
'json-files/sort-package-json': 'error',
'json-files/require-license': 'error',
},
},
];