Getting Started
💽 Installation
Section titled “💽 Installation”pnpm add -D eslint-plugin-package-jsonnpm install -D eslint-plugin-package-jsonyarn add -D eslint-plugin-package-json📖 Configs
Section titled “📖 Configs”Recommended Config
Section titled “Recommended Config”This plugin’s recommended configuration enables its rules on **/package.json files, parsing them with jsonc-eslint-parser.
import packageJson from "eslint-plugin-package-json";import { defineConfig } from "eslint/config";
export default defineConfig([ // your other ESLint configurations packageJson.configs.recommended,]);If you want to override the recommended rules:
import packageJson from "eslint-plugin-package-json";import { defineConfig } from "eslint/config";
export default defineConfig([ // your other ESLint configurations { extends: [packageJson.configs.recommended], files: ["package.json"], rules: { "package-json/require-author": "error", }, },]);Recommended Config for Publishable Packages
Section titled “Recommended Config for Publishable Packages”The recommended-publishable configuration has everything in it from the standard recommended config, with some additional rules added that are geared towards packages that are intended to be published.
import packageJson from "eslint-plugin-package-json";import { defineConfig } from "eslint/config";
export default defineConfig([ // your other ESLint configurations packageJson.configs["recommended-publishable"],]);Stylistic Config
Section titled “Stylistic Config”The stylistic configuration sets up the parser and files similar to the recommended config, but includes rules that are more opinionated about the style of a package.json.
This can be used in addition to the recommended config, or on its own.
import packageJson from "eslint-plugin-package-json";import { defineConfig } from "eslint/config";
export default defineConfig([ // your other ESLint configurations packageJson.configs.recommended, // or packageJson.configs["recommended-publishable"] packageJson.configs.stylistic,]);⚙️ Settings
Section titled “⚙️ Settings”Some rules can be configured in ESLint shared settings.
You can set them in settings.packageJson in an ESLint flat config.
Example:
import packageJson from "eslint-plugin-package-json";import { defineConfig } from "eslint/config";
export default defineConfig({ plugins: { "package-json": packageJson, }, rules: { // `description` won't be required in package.json with `"private": true` "package-json/require-description": "error", }, settings: { packageJson: { enforceForPrivate: false, }, },});enforceForPrivate
Section titled “enforceForPrivate”- Type:
boolean - Default: [see below]
When a package.json file has a "private": true field, it indicates that the package will not be published to npm (or another online registry).
Some fields that are nice to have in public packages become less relevant when a package is private.
This option determines whether require-* rules, if used, should enforce the presence of the corresponding property in package.json files that have "private": true.
By default, this is:
falseforrequire-nameandrequire-version.truefor every otherrequire-*rule.
By specifying this setting as true or false, it will override the defaults and apply the setting for ALL rules.
In that case, either all require-* rules will be applied to private packages or no require-* rules will be applied to private packages.
Even then, you can override the setting again at the rule level, by using the rule’s ignorePrivate option, which will take precedence over this global setting.