0.26.3 β€’ Published 3 months ago

eslint-plugin-package-json v0.26.3

Weekly downloads
2,808
License
MIT
Repository
github
Last release
3 months ago

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-empty-fieldsReports on unnecessary empty arrays and objects.βœ…πŸ’‘
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.βœ…πŸ”§
require-authorRequires the author property to be present.
require-filesRequires the files property to be present.
require-keywordsRequires the keywords property to be present.
require-nameRequires the name property to be present.βœ…
require-versionRequires the version property to be present.βœ…
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

Appreciation

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

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

0.26.3

3 months ago

0.26.2

3 months ago

0.26.1

4 months ago

0.25.0

4 months ago

0.23.1

4 months ago

0.23.0

4 months ago

0.26.0

4 months ago

0.24.0

4 months ago

0.22.0

4 months ago

0.21.0

5 months ago

0.21.1

5 months ago

0.20.1

5 months ago

0.20.0

5 months ago

0.19.0

6 months ago

0.18.0

6 months ago

0.16.0

7 months ago

0.17.0

7 months ago

0.15.5

7 months ago

0.15.6

7 months ago

0.15.4

8 months ago

0.15.3

9 months ago

0.15.0

12 months ago

0.15.1

11 months ago

0.15.2

11 months ago

0.14.0

1 year ago

0.13.1

1 year ago

0.13.0

1 year ago

0.12.2

1 year ago

0.12.1

1 year ago

0.12.0

1 year ago

0.11.0

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.10.2

1 year ago

0.10.1

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.3.0

2 years ago

0.2.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.1.5

2 years ago

0.1.4

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago