Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

eslint-plugin-package-json

Package Overview
Dependencies
Maintainers
0
Versions
42
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. ๐Ÿ—‚๏ธ

  • 0.20.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61K
increased by2.2%
Maintainers
0
Weekly downloads
ย 
Created
Source

eslint-plugin-package-json

Rules for consistent, readable, and valid package.json files. ๐Ÿ—‚๏ธ

All Contributors: 22 ๐Ÿ‘ช 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/configs/recommended";

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

If you want to override the recommended rules:

import packageJson from "eslint-plugin-package-json/configs/recommended";

export default [
	// your other ESLint configurations
	{
		...packageJson,
		rules: {
			...packageJson.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/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-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-redundant-filesPrevents adding unnecessary / redundant files.๐Ÿ’ก
order-propertiesPackage properties must be declared in standard orderโœ…๐Ÿ”ง
repository-shorthandEnforce either object or shorthand declaration for repository.โœ…๐Ÿ”ง
sort-collectionsDependencies, scripts, and configuration values must be declared in alphabetical order.โœ…๐Ÿ”ง
unique-dependenciesChecks a dependency isn't specified more than once (i.e. in dependencies and devDependencies)โœ…๐Ÿ’ก
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-package-definitionEnforce 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.

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

๐Ÿ›
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.

FAQs

Package last updated on 19 Jan 2025

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