Socket
Socket
Sign inDemoInstall

eslint-plugin-package-json

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-package-json

Rules for consistent, readable, and valid package.json files. 🗂️


Version published
Weekly downloads
33K
increased by2.24%
Maintainers
2
Weekly downloads
 
Created
Source

eslint-plugin-package-json

Rules for consistent, readable, and valid package.json files. 🗂️

All Contributors: 14 👪 Codecov Test Coverage Contributor Covenant License: MIT Style: Prettier npm package version

Installation

This package requires ESLint 8 and jsonc-eslint-parser:

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

Usage

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

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

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/recommended"],
			files: ["package.json"],
			parser: "jsonc-eslint-parser",
			plugins: ["package-json"],
			rules: {
				"package-json/valid-package-def": "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 extends: ["plugin:package-json/recommended"]. 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.

Name                       Description💼🔧💡
order-propertiesPackage properties must be declared in standard order🔧
prefer-repository-shorthandEnforce shorthand declaration for GitHub repository.🔧
sort-collectionsDependencies, scripts, and configuration values must be declared in alphabetical order.🔧
unique-dependenciesEnforce that if repository directory is specified, it matches the path to the package.json file💡
valid-local-dependencyChecks existence of local dependencies in the package.json
valid-nameEnforce that package names are valid npm package names💡
valid-package-defEnforce that package.json has all properties required by the npm spec
valid-repository-directoryEnforce that if repository directory is specified, it matches the path to the package.json file💡
valid-versionEnforce 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.

Contributors

Andreas Lindberg
Andreas Lindberg

🐛
Anton Khitrenovich
Anton Khitrenovich

🤔
Azat S.
Azat S.

🤔 💻
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

🤔 🐛 💻
Nick Schonning
Nick Schonning

💻
Stephen
Stephen

💻
Stephen Zhou
Stephen Zhou

🐛 💻
Yosuke Ota
Yosuke Ota

🐛 💻
b3rnhard
b3rnhard

🐛

Appreciation

Many thanks to @zetlen for creating the initial version and core infrastructure of this package! 💖

💙 This package was templated with create-typescript-app.

FAQs

Package last updated on 20 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc