Dรฉtail du package

eslint-plugin-package-json

JoshuaKGoldberg422.4kMIT0.43.2

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: 28 ๐Ÿค 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-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.

๐Ÿค” ๐Ÿ’ป
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.