ๅŒ…่ฏฆ็ป†ไฟกๆฏ

eslint-plugin-package-json

JoshuaKGoldberg361.4kMIT0.31.0

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

่‡ช่ฟฐๆ–‡ไปถ

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

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