Package Exports
- eslint-plugin-package-json
Readme
eslint-plugin-package-json
Rules for consistent, readable, and valid package.json files. ποΈ
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",
},
},
],
};
Supported Rules
πΌ Configurations enabled in.
β
Set in the recommended
configuration.
π§ Automatically fixable by the --fix
CLI option.
Name | Description | πΌ | π§ |
---|---|---|---|
order-properties | Package properties must be declared in standard order | β | π§ |
prefer-repository-shorthand | Enforce shorthand declaration for GitHub repository. | β | π§ |
sort-collections | Dependencies, scripts, and configuration values must be declared in alphabetical order. | β | π§ |
valid-local-dependency | Checks existence of local dependencies in the package.json | β | |
valid-package-def | Enforce that package.json has all properties required by the npm spec | β |
These rules only run on package.json
files; they will ignore all other files being linted. They lint package.json
files at project root, and in any subfolder of the project, making this plugin great for monorepos.
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.