Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshuakgoldberg/eslint-plugin-package-json
Rules for consistent, readable, and valid package.json files. ποΈ
https://github.com/joshuakgoldberg/eslint-plugin-package-json
eslint eslint-plugin json
Last synced: 5 days ago
JSON representation
Rules for consistent, readable, and valid package.json files. ποΈ
- Host: GitHub
- URL: https://github.com/joshuakgoldberg/eslint-plugin-package-json
- Owner: JoshuaKGoldberg
- License: mit
- Created: 2018-09-28T09:09:55.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T12:34:11.000Z (about 2 months ago)
- Last Synced: 2024-10-29T13:09:07.527Z (about 2 months ago)
- Topics: eslint, eslint-plugin, json
- Language: TypeScript
- Size: 2.26 MB
- Stars: 117
- Watchers: 5
- Forks: 21
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
eslint-plugin-package-json
Rules for consistent, readable, and valid package.json files. ποΈ
## Installation
This package requires [ESLint](http://eslint.org) >=8:
```shell
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`](https://github.com/ota-meshi/jsonc-eslint-parser).
In your ESLint configuration file:
```ts
import packageJson from "eslint-plugin-package-json/configs/recommended";export default [
// your other ESLint configurations
packageJson,
];
```If you want to override the recommended rules:
```ts
import packageJson from "eslint-plugin-package-json/configs/recommended";export default [
// your other ESLint configurations
{
...packageJson,
rules: {
...packageJson.rules,
"package-json/valid-package-def": "off",
},
},
];
```See [ESLint's _Configuration Files_ guide](https://eslint.org/docs/latest/use/configure/configuration-files-new) 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`](https://github.com/ota-meshi/jsonc-eslint-parser):
```shell
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:
```js
module.exports = {
overrides: [
{
extends: ["plugin:package-json/recommended"],
files: ["package.json"],
parser: "jsonc-eslint-parser",
plugins: ["package-json"],
},
],
};
```You may also want to individually configure rules.
See [ESLint's _Configure Rules_ guide](https://eslint.org/docs/latest/use/configure/rules) for details on how to customize your rules.```js
module.exports = {
overrides: [
{
extends: ["plugin:package-json/recommended"],
files: ["package.json"],
parser: "jsonc-eslint-parser",
plugins: ["package-json"],
rules: {
"package-json/valid-package-def": "error",
},
},
],
};
```### Usage Alongside Prettier
**[`prettier-plugin-packagejson`](https://github.com/matzkoh/prettier-plugin-packagejson)** is a [Prettier plugin](https://prettier.io/docs/en/plugins) that enforces the same `package.json` keys ordering as the [`order-properties`](docs/rules/order-properties.md) and [sort-collections](docs/rules/sort-collections.md) 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 `recommended` configuration.\
π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | π§ | π‘ |
| :--------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------ | :- | :- | :- |
| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | β | π§ | |
| [repository-shorthand](docs/rules/repository-shorthand.md) | Enforce either object or shorthand declaration for repository. | β | π§ | |
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | β | π§ | |
| [unique-dependencies](docs/rules/unique-dependencies.md) | Checks a dependency isn't specified more than once (i.e. in `dependencies` and `devDependencies`) | β | | π‘ |
| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | β | | |
| [valid-name](docs/rules/valid-name.md) | Enforce that package names are valid npm package names | β | | |
| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by the npm spec | β | | |
| [valid-repository-directory](docs/rules/valid-repository-directory.md) | Enforce that if repository directory is specified, it matches the path to the package.json file | β | | π‘ |
| [valid-version](docs/rules/valid-version.md) | 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`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md).
Thanks! π## Contributors
Alan
π π»
Andreas Lindberg
π
Anton Khitrenovich
π€
Azat S.
π€ π»
David LJ
π
Heggria
π€
James
π»
James Zetlen
π» π π π π§ π§
JesΓΊs LeganΓ©s-Combarro
π»
Josh Goldberg β¨
π§ π π» π π π§ π€
Kendall Gassner
π» π§
Kristjan ESPERANTO
π€ π π»
Mathias Schreck
π€
Michael "Mike" Ferris
π»
Nick Schonning
π»
Pavel
π€ π§ π
Sasial
π»
Stephen
π»
Stephen Zhou
π π» π€ π
Yosuke Ota
π π»
b3rnhard
π
## Appreciation
Many thanks to [@zetlen](https://github.com/zetlen) for creating the initial version and core infrastructure of this package! π
> π This package was templated with [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).