Détail du package

eslint-plugin-package-json

JoshuaKGoldberg422.4kMIT0.44.1

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

readme

eslint-plugin-package-json

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

👪 All Contributors: 29 🤝 Code of Conduct: Kept 🧪 Coverage 📝 License: MIT 📦 npm version 💪 TypeScript: Strict

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 legacy-recommended configuration.\ ✅ 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-description Requires the description 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-type Requires the type property to be present. ✔️ ✅
require-types Requires the types property to be present.
require-version Requires the version property to be present. ✔️ ✅
restrict-dependency-ranges Restricts the range of dependencies to allow or disallow specific types of ranges. 💡
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-author Enforce that the author field is a valid npm author specification ✔️ ✅
valid-bin Enforce that the bin property is valid. ✔️ ✅ 💡
valid-bundleDependencies Enforce that the bundleDependencies (or bundledDependencies) property is valid. ✔️ ✅
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-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-scripts Enforce that the scripts property is valid. ✔️ ✅
valid-type Enforce that the type property is valid. ✔️ ✅
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.

Deprecation Policy

We never want to remove things, when we're building them! But the reality is that libraries evolve and deprecations are a fact of life. Following are the different timeframes that we've defined as it relates to deprecating APIs in this project.

RFC Timeframe (6 weeks)

When some aspect of our API is going to be deprecated (and eventually removed), it must initially go through an RFC phase. Whoever's motivating the removal of the api, should create an RFC issue explaining the proposal and inviting feedback from the community. That RFC should remain active for at least 6 weeks. The RFC text should make clear what the target date is for closing the RFC. Once the RFC period is over, if the removal is still moving forward, the API(s) should be officially deprecated.

Removal Timeframe (6 months)

Once an API has been marked as deprecated, it will remain intact for at least 6 months. After 6 months from the date of deprecation, the API is subject to removal.

Development

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! 🗂

Contributors

Alan
Alan

🐛 💻
Andreas Lindberg
Andreas Lindberg

🐛
Andrew Kazakov
Andrew Kazakov

🐛 💻 🤔
Anton Khitrenovich
Anton Khitrenovich

🤔
Azat S.
Azat S.

🤔 💻
Brad Jorsch
Brad Jorsch

🤔
Curtis Jewell
Curtis Jewell

🤔
David LJ
David LJ

📖
Eli
Eli

🤔
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

🚇 💻 🚧 🤔 🐛 🔧 📖
roottool
roottool

💻
sunnytsang1998
sunnytsang1998

🐛

Appreciation

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

💝 This package was templated with create-typescript-app using the Bingo engine.

changelog

Changelog

0.44.1 (2025-07-10)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.20.0 (#1170) (941cf73)

0.44.0 (2025-07-09)

Features

  • valid-bundleDependencies: add new rule for validating bundleDependencies (#1148) (ee44973), closes #819

0.43.4 (2025-07-09)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.19.0 (#1167) (9c72efd)

0.43.3 (2025-07-08)

Bug Fixes

  • deps: update dependency @altano/repository-tools to v2 (#1164) (0c54bc9)

0.43.2 (2025-07-04)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.18.0 (#1160) (dfebe75)

0.43.1 (2025-07-03)

Bug Fixes

  • disallow extra properties in rule options (#1156) (4186e96)

0.43.0 (2025-07-02)

Features

  • valid-scripts: add new rule for validating scripts (#1138) (99cc2a5), closes #839

0.42.1 (2025-07-01)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.17.0 (#1152) (16239d0)

0.42.0 (2025-06-25)

Features

0.41.0 (2025-06-24)

Features

0.40.5 (2025-06-23)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.16.0 (#1135) (4a4a2a0)

0.40.4 (2025-06-20)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.15.0 (#1131) (4bf7d9c)

0.40.3 (2025-06-19)

Bug Fixes

  • deps: update dependency eslint-fix-utils to ^0.4.0 (#1130) (b66db8c)

0.40.2 (2025-06-19)

Bug Fixes

  • deps: update dependency package-json-validator to ~0.14.0 (#1125) (5f61f89)

0.40.1 (2025-06-18)

Bug Fixes

  • deps: update dependency eslint-fix-utils to ^0.3.0 (#1124) (1e30861)

0.40.0 (2025-06-16)

Features

0.39.2 (2025-06-15)

Bug Fixes

  • deps: update dependency detect-newline to v4 (#875) (26c08d9)

0.39.1 (2025-06-15)

Bug Fixes

  • deps: update dependency @altano/repository-tools to v1 (#1006) (da63ce3)

0.39.0 (2025-06-13)

Features

0.38.1 (2025-06-13)

Bug Fixes

  • valid-local-dependency: don't flag archives as invalid (#1109) (3d89865), closes #1086

0.38.0 (2025-06-13)

Features

0.37.0 (2025-06-12)

Features

0.36.0 (2025-06-11)

Features

0.35.1 (2025-06-10)

Bug Fixes

  • deps: update dependency detect-indent to v7 (#874) (65300dc)

0.35.0 (2025-06-10)

Features

0.34.0 (2025-06-10)

Features

  • valid-package-definition: add ignoreProperties option (#1077) (530e343), closes #1076

0.33.2 (2025-06-01)

Bug Fixes

  • prevent no-redundant-files crash with wildcard and main field (#1078) (ad4f95f), closes #1066

0.33.1 (2025-06-01)

Bug Fixes

0.33.0 (2025-05-31)

Features

0.32.0 (2025-05-31)

No meaningful change. CI error.

0.31.0 (2025-04-26)

Features

0.30.0 (2025-04-22)

Features

0.29.1 (2025-04-09)

Bug Fixes

  • bump to create-typescript-app@2 with transitions action (#993) (5b5c298), closes #969

0.29.0 (2025-03-17)

Features

0.28.0 (2025-03-17)

Features

0.27.0 (2025-03-17)

Features

  • empty feature commit to trigger new minor version (b6b58d4)

0.26.4 (2025-03-17)

0.26.3 (2025-03-07)

Bug Fixes

  • deps: update dependency sort-package-json to v3 (#939) (a61e725)

0.26.2 (2025-03-04)

Bug Fixes

  • deps: update dependency sort-package-json to v2.15.1 (#933) (f3a8169)

0.26.1 (2025-03-02)

Bug Fixes

  • deps: update dependency sort-package-json to v2.15.0 (#925) (3ce4286)

0.26.0 (2025-02-10)

Features

0.25.0 (2025-02-09)

Features

  • require-keywords: add require-keywords rule (#884) (99237f0), closes #866

0.24.0 (2025-02-08)

Features

0.23.1 (2025-02-07)

Bug Fixes

  • deps: update dependency semver to v7.7.1 (#880) (152cfc1)

0.23.0 (2025-02-04)

Features

  • require-version: add require-version rule (#861) (848377d)

0.22.0 (2025-02-03)

Features

  • require-author: add new require-author rule (#851) (cde68da), closes #795

0.21.1 (2025-01-24)

Bug Fixes

  • no-redundant-files: detect variations of README.md as redundant (#765) (7453095), closes #763 #763

0.21.0 (2025-01-23)

Features

0.20.1 (2025-01-19)

Bug Fixes

0.20.0 (2025-01-17)

Features

0.19.0 (2024-12-31)

Features

  • valid-package-definition: rename rule from valid-package-def (#711) (4f3907b), closes #132 #132

0.18.0 (2024-12-05)

Features

0.17.0 (2024-11-30)

Features

0.16.0 (2024-11-30)

Features

0.15.6 (2024-11-09)

Bug Fixes

0.15.5 (2024-11-06)

Bug Fixes

0.15.4 (2024-10-18)

Bug Fixes

  • update dependency package-json-validator to v0.7.0 (#569) (9d44862), closes #000

0.15.3 (2024-09-12)

Bug Fixes

  • valid-repository-directory: use repository root for more accurate linting (#498) (d149400), closes #252

0.15.2 (2024-07-10)

Bug Fixes

  • skip check for name to match npm package when private is true (#455) (cc10e05), closes #000

0.15.1 (2024-07-10)

Bug Fixes

0.15.0 (2024-06-17)

Features

  • order-properties: more precise error reporting (#328) (4a3fbc8), closes #320

0.14.0 (2024-05-31)

Features

0.13.1 (2024-04-29)

Bug Fixes

0.13.0 (2024-04-29)

Bug Fixes

Features

  • sort-order rule shouldn't change sub-keys, better auto-fix (#312) (a894550), closes #80

0.12.1 (2024-03-28)

Bug Fixes

  • valid-package-def: ignore pnpm workspace protocol (#258) (4b061e6), closes #251

0.12.0 (2024-03-25)

Features

  • switch prefer-repository-shorthand to repository-shorthand (#248) (580edb3), closes #223

0.11.0 (2024-03-24)

Features

0.10.4 (2024-02-20)

Bug Fixes

0.10.3 (2024-02-20)

Bug Fixes

0.10.2 (2024-02-01)

Bug Fixes

0.10.1 (2024-01-25)

Bug Fixes

0.10.0 (2024-01-20)

Features

0.9.0 (2024-01-20)

Features

0.8.1 (2024-01-20)

Bug Fixes

0.8.0 (2024-01-20)

Features

0.7.0 (2024-01-20)

Features

0.6.0 (2024-01-20)

Features

  • change order-properties order default to sort-package-json (#122) (246261d), closes #58

0.5.0 (2024-01-20)

Features

  • add prefer-repository-shorthand rule (#70) (0c7fb19), closes #71

0.4.0 (2024-01-20)

Bug Fixes

Features