Skip to content

Rules for consistent, readable, and valid package.json files. πŸ—‚οΈ

License

Notifications You must be signed in to change notification settings

JoshuaKGoldberg/eslint-plugin-package-json

Folders and files

NameName
Last commit message
Last commit date
Mar 28, 2025
Dec 5, 2024
Feb 20, 2024
Mar 17, 2025
Mar 17, 2025
Mar 20, 2025
Feb 20, 2024
Mar 17, 2025
Nov 28, 2023
Nov 28, 2023
Nov 28, 2023
Feb 14, 2025
Nov 28, 2023
Nov 28, 2023
Feb 1, 2025
Mar 17, 2025
Sep 13, 2023
Mar 20, 2025
Mar 17, 2025
Mar 17, 2025
Jan 15, 2025
Mar 29, 2025
Mar 30, 2025
Nov 28, 2023
Apr 29, 2024
Nov 28, 2023
Nov 28, 2023

Repository files navigation

eslint-plugin-package-json

Rules for consistent, readable, and valid package.json files. πŸ—‚οΈ

All Contributors: 23 πŸ‘ͺ Codecov Test Coverage Contributor Covenant License: MIT Style: Prettier npm package version

Installation

This package requires ESLint >=8:

npm install eslint eslint-plugin-package-json --save-dev

Usage

Flat Config

This plugin's recommended configuration enables its rules on **/package.json files, parsing them with jsonc-eslint-parser.

In your ESLint configuration file:

import packageJson from "eslint-plugin-package-json";

export default [
	// your other ESLint configurations
	packageJson.configs.recommended,
];

If you want to override the recommended rules:

import packageJson from "eslint-plugin-package-json";

export default [
	// your other ESLint configurations
	packageJson.configs.recommended,
	{
		rules: {
			"package-json/valid-package-definition": "off",
		},
	},
];

See ESLint's Configuration Files guide for details on how to customize your rules and other config settings.

Legacy Config

Usage with ESLint's legacy ("eslintrc") format requires also installing jsonc-eslint-parser:

npm install jsonc-eslint-parser --save-dev

Add an override to your ESLint configuration file that specifies jsonc-eslint-parser, this plugin, and its recommended rules for your package.json file:

module.exports = {
	overrides: [
		{
			extends: ["plugin:package-json/legacy-recommended"],
			files: ["package.json"],
			parser: "jsonc-eslint-parser",
		},
	],
};

You may also want to individually configure rules. See ESLint's Configure Rules guide for details on how to customize your rules.

module.exports = {
	overrides: [
		{
			extends: ["plugin:package-json/legacy-recommended"],
			files: ["package.json"],
			parser: "jsonc-eslint-parser",
			rules: {
				"package-json/valid-package-definition": "error",
			},
		},
	],
};

Usage Alongside Prettier

prettier-plugin-packagejson is a Prettier plugin that enforces the same package.json keys ordering as the order-properties and sort-collections rules with default options. We recommend using both the Prettier plugin and eslint-plugin-package-json's recommended configuration. The default settings don't conflict, and Prettier plugins can quickly fix up ordering in your editor on save and/or as a Git hook.

Supported Rules

πŸ’Ό Configurations enabled in.
βœ… Set in the recommended configuration.
πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’‘ Manually fixable by editor suggestions.
❌ Deprecated.

Name                       Description πŸ’Ό πŸ”§ πŸ’‘ ❌
no-empty-fields Reports on unnecessary empty arrays and objects. βœ… πŸ’‘
no-redundant-files Prevents adding unnecessary / redundant files. πŸ’‘
order-properties Package properties must be declared in standard order βœ… πŸ”§
repository-shorthand Enforce either object or shorthand declaration for repository. βœ… πŸ”§
require-author Requires the author property to be present.
require-engines Requires the engines property to be present.
require-files Requires the files property to be present.
require-keywords Requires the keywords property to be present.
require-name Requires the name property to be present. βœ…
require-types Requires the types property to be present.
require-version Requires the version property to be present. βœ…
sort-collections Dependencies, scripts, and configuration values must be declared in alphabetical order. βœ… πŸ”§
unique-dependencies Checks a dependency isn't specified more than once (i.e. in dependencies and devDependencies) βœ… πŸ’‘
valid-local-dependency Checks existence of local dependencies in the package.json βœ…
valid-name Enforce that package names are valid npm package names βœ…
valid-package-def Enforce that package.json has all properties required by the npm spec ❌
valid-package-definition Enforce that package.json has all properties required by the npm spec βœ…
valid-repository-directory Enforce that if repository directory is specified, it matches the path to the package.json file βœ… πŸ’‘
valid-version Enforce that package versions are valid semver specifiers βœ…

These rules only run on package.json files; they will ignore all other files being linted. They can lint package.json files at project root and in any subfolder of the project, making this plugin great for monorepos.

Development

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! πŸ’–

Contributors

Alan
Alan

πŸ› πŸ’»
Andreas Lindberg
Andreas Lindberg

πŸ›
Anton Khitrenovich
Anton Khitrenovich

πŸ€”
Azat S.
Azat S.

πŸ€” πŸ’»
David LJ
David LJ

πŸ“–
Heggria
Heggria

πŸ€”
James
James

πŸ’»
James Zetlen
James Zetlen

πŸ’» πŸ› πŸ“– πŸš‡ 🚧 πŸ”§
JesΓΊs LeganΓ©s-Combarro
JesΓΊs LeganΓ©s-Combarro

πŸ’»
Josh Goldberg ✨
Josh Goldberg ✨

πŸ”§ πŸ› πŸ’» πŸš‡ πŸ“– 🚧 πŸ€”
Kendall Gassner
Kendall Gassner

πŸ’» 🚧
Kristjan ESPERANTO
Kristjan ESPERANTO

πŸ€” πŸ› πŸ’»
Mathias Schreck
Mathias Schreck

πŸ€”
Michael
Michael "Mike" Ferris

πŸ’»
Nick Schonning
Nick Schonning

πŸ’»
Pavel
Pavel

πŸ€” πŸ”§ πŸ“– πŸ’» πŸ›
Sasial
Sasial

πŸ’»
Stephen
Stephen

πŸ’»
Stephen Zhou
Stephen Zhou

πŸ› πŸ’» πŸ€” πŸ“–
Yosuke Ota
Yosuke Ota

πŸ› πŸ’»
b3rnhard
b3rnhard

πŸ›
chouchouji
chouchouji

πŸ’»
michael faith
michael faith

πŸš‡ πŸ’» 🚧 πŸ€”

Appreciation

Many thanks to @zetlen for creating the initial version and core infrastructure of this package! πŸ’–

πŸ’™ This package was templated with create-typescript-app.