https://github.com/shellscape/prettier-plugin-package
An opinionated package.json formatter plugin for Prettier
https://github.com/shellscape/prettier-plugin-package
Last synced: 3 months ago
JSON representation
An opinionated package.json formatter plugin for Prettier
- Host: GitHub
- URL: https://github.com/shellscape/prettier-plugin-package
- Owner: shellscape
- License: mpl-2.0
- Created: 2019-09-05T02:00:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-07-31T15:18:33.000Z (3 months ago)
- Last Synced: 2025-08-09T13:38:26.202Z (3 months ago)
- Language: JavaScript
- Size: 524 KB
- Stars: 89
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
- awesome - prettier-plugin-package - An opinionated package.json formatter plugin for Prettier (JavaScript)
README
[tests]: https://img.shields.io/circleci/project/github/shellscape/prettier-plugin-package.svg
[tests-url]: https://circleci.com/gh/shellscape/prettier-plugin-package
[cover]: https://codecov.io/gh/shellscape/prettier-plugin-package/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/shellscape/prettier-plugin-package
[size]: https://packagephobia.now.sh/badge?p=prettier-plugin-package
[size-url]: https://packagephobia.now.sh/result?p=prettier-plugin-package

# prettier-plugin-package [![tests][tests]][tests-url] [![cover][cover]][cover-url] [![size][size]][size-url] [](https://liberamanifesto.com)
An opinionated `package.json` formatter plugin for [Prettier](https://prettier.io)
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing, taking various rules into account.
This plugin adds support for `package.json` files used within NPM modules.
## Requirements
`prettier-plugin-package` is an evergreen module. 🌲 This module requires an [LTS](https://github.com/nodejs/Release) Node version (v20.19.0+), and `prettier` v3.0.0+.
For Prettier v1.x support, please use `prettier-plugin-package@0.3.1`.
For Prettier v2.x support, please use `prettier-plugin-package@1.4.0`.
## Install
Using npm:
```console
npm install prettier prettier-plugin-package --save-dev
```
_Please consider donating if you find this project useful._
## Usage
Once installed, [Prettier plugins](https://prettier.io/docs/en/plugins.html) should be automatically recognized by Prettier. To use this plugin, confirm that it's installed and run Prettier using your preferred method. For example:
```console
$ npx prettier --write package.json
```
## Rules
This plugin enforces its own set of opinionated rules:
### Engines
Keys in `engines` are ordered alphabetically.
### Files
Keys in `files` are ordered alphabetically (keeping the negations below), followed by `README.md` and `LICENSE` if they exist in the array.
### Scripts
Keys in `scripts` are ordered alphabetically. Use prefixes wisely to properly order child scripts. e.g. `lint`, `lint:ts`.
### Sorting
Top-level keys are sorted according to a style commonly seen in the packages of [@sindresorhus](https://github.com/sindresorhus). Known keys, and their order are:
```js
[
// meta
'name',
'version',
'flat',
'private',
'publishConfig',
'description',
'license',
'repository',
'author',
'homepage',
'bugs',
// entry
'main',
'bin',
'module',
'type',
'exports',
// constraints
'engines',
'cpu',
'os',
// content and util
'scripts',
'files',
'keywords',
// dependencies
'bundledDependencies',
'optionalDependencies',
'peerDependencies',
'peerDependenciesMeta',
'dependencies',
'devDependencies',
'resolutions',
// types
'types',
'typings'
]
```
Unknown keys, or keys not part of the list above, will be alphabetically sorted and added to the end of the file. Note that this list takes into account both `npm` and `yarn` keys.
### Forthcoming
Forthcoming rules include:
- [ ] Author format
- [ ] Repository format
## Meta
[CONTRIBUTING](./.github/CONTRIBUTING.md)
[LICENSE (Mozilla Public License)](./LICENSE)