What is prettier-plugin-packagejson?
The prettier-plugin-packagejson npm package is a plugin for Prettier that formats your package.json file according to a consistent style. It helps maintain a clean and organized package.json file by sorting and formatting its contents.
What are prettier-plugin-packagejson's main functionalities?
Sorting dependencies
This feature sorts the dependencies in your package.json file alphabetically, ensuring a consistent order.
{
"dependencies": {
"express": "^4.17.1",
"lodash": "^4.17.21"
}
}
Sorting scripts
This feature sorts the scripts in your package.json file alphabetically, making it easier to find and manage scripts.
{
"scripts": {
"build": "webpack",
"start": "node index.js"
}
}
Sorting other fields
This feature sorts other fields like keywords, contributors, etc., alphabetically to maintain a clean and organized structure.
{
"keywords": [
"formatting",
"prettier",
"plugin"
]
}
Other packages similar to prettier-plugin-packagejson
sort-package-json
The sort-package-json package sorts the keys in your package.json file. It provides similar functionality to prettier-plugin-packagejson by organizing the structure of the package.json file, but it is a standalone tool rather than a Prettier plugin.
fixpack
The fixpack package is another tool that formats and sorts the fields in your package.json file. It focuses on keeping the package.json file clean and consistent, similar to prettier-plugin-packagejson, but it also includes additional checks for common errors and best practices.
Prettier plugin for package.json
Installation
$ npm i -D prettier prettier-plugin-packagejson
overrides
is required because native json parser takes precedence over this plugin.
{
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"plugins": ["prettier-plugin-packagejson"],
"overrides": [
{
"files": "package.json",
"options": {
"parser": "package-json"
}
}
]
}
Rules
- Primary (ordered to top)
- name
- description
- version
- author
- license
- Others
- Sort children
- dependencies
- devDependencies
- peerDependencies
- optionalDependencies
- keywords
ToDo: Add more tweaks