Détail du package

eslint-plugin-package-json

JoshuaKGoldberg361.4kMIT0.31.0

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: 24 🤝 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-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-local-dependency Checks existence of local dependencies in the package.json ✔️ ✅
valid-name Enforce that package names are valid npm package names ✔️ ✅
valid-package-def Enforce that package.json has all properties required by the npm spec
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-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.

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

🐛
chouchouji
chouchouji

💻
michael faith
michael faith

🚇 💻 🚧 🤔
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.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