Skip to content

Latest commit

 

History

History
60 lines (45 loc) · 2.19 KB

File metadata and controls

60 lines (45 loc) · 2.19 KB

eslint-plugin-package-json

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

Installation

You'll first need to install ESLint >=8 and eslint-plugin-package-json:

$ npm install eslint eslint-plugin-package-json --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-package-json globally.

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']
        }
    ]
};

Or, individually configure the rules you want to use under the rules section.

module.exports = {
    overrides: [
        {
            files: ['package.json'],
            parser: 'jsonc-eslint-parser'
            plugins: ['package-json'],
            rules: {
                'package-json/valid-package-def': 'error'
            }
        }
    ]
};

Supported Rules

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.

Appreciation

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