UNPKG

prettier-plugin-package-perfection

Version:

A Prettier plugin that formats the package.json file by leveraging the prettier-package-json CLI library

220 lines (174 loc) 14.2 kB
<!-- ⚠️ This README has been generated from the file(s) ".config/docs/blueprint-readme-plugin.md" ⚠️--><div align="center"> <center> <a href="https://github.com/megabyte-labs/prettier-plugin-package-perfection"> <img width="148" height="148" alt="Prettier Package JSON Prettier Plugin logo" src="https://gitlab.com/megabyte-labs/npm/plugin/prettier-plugin-package-perfection/-/raw/master/logo.png" /> </a> </center> </div> <div align="center"> <center><h1 align="center"><i></i>A Prettier package.json Prettier Plugin<i></i></h1></center> <center><h4 style="color: #18c3d1;">A plugin created by <a href="https://megabyte.space" target="_blank">Megabyte Labs</a></h4><i></i></center> </div> <div align="center"> <a href="https://megabyte.space" title="Megabyte Labs homepage" target="_blank"> <img alt="Homepage" src="https://img.shields.io/website?down_color=%23FF4136&down_message=Down&label=Homepage&logo=home-assistant&logoColor=white&up_color=%232ECC40&up_message=Up&url=https%3A%2F%2Fmegabyte.space&style=for-the-badge" /> </a> <a href="https://github.com/megabyte-labs/prettier-plugin-package-perfection/blob/master/docs/CONTRIBUTING.md" title="Learn about contributing" target="_blank"> <img alt="Contributing" src="https://img.shields.io/badge/Contributing-Guide-0074D9?logo=github-sponsors&logoColor=white&style=for-the-badge" /> </a> <a href="https://app.slack.com/client/T01ABCG4NK1/C01NN74H0LW/details/" title="Chat with us on Slack" target="_blank"> <img alt="Slack" src="https://img.shields.io/badge/Slack-Chat-e01e5a?logo=slack&logoColor=white&style=for-the-badge" /> </a> <a href="https://gitter.im/megabyte-labs/community" title="Chat with the community on Gitter" target="_blank"> <img alt="Gitter" src="https://img.shields.io/gitter/room/megabyte-labs/community?logo=gitter&logoColor=white&style=for-the-badge" /> </a> <a href="https://github.com/megabyte-labs/prettier-plugin-package-perfection" title="GitHub mirror" target="_blank"> <img alt="GitHub" src="https://img.shields.io/badge/Mirror-GitHub-333333?logo=github&style=for-the-badge" /> </a> <a href="https://gitlab.com/megabyte-labs/npm/plugin/prettier-plugin-package-perfection" title="GitLab repository" target="_blank"> <img alt="GitLab" src="https://img.shields.io/badge/Repo-GitLab-fc6d26?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAHJJREFUCNdNxKENwzAQQNEfWU1ZPUF1cxR5lYxQqQMkLEsUdIxCM7PMkMgLGB6wopxkYvAeI0xdHkqXgCLL0Beiqy2CmUIdeYs+WioqVF9C6/RlZvblRNZD8etRuKe843KKkBPw2azX13r+rdvPctEaFi4NVzAN2FhJMQAAAABJRU5ErkJggg==&style=for-the-badge" /> </a> </div> <br/> <div align="center"> <a href="https://www.npmjs.com/package/prettier-plugin-package-perfection" title="Version 1.0.10" target="_blank"> <img alt="Version: 1.0.10" src="https://img.shields.io/badge/version-1.0.10-blue.svg?cacheSeconds=2592000&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAACNJREFUCNdjIACY//+BEp9hhM3hAzYQwoBIAqEDYQrCZLwAAGlFKxU1nF9cAAAAAElFTkSuQmCC&style=flat-square" /> </a> <a href="https://gitlab.com/megabyte-labs/npm/plugin/prettier-plugin-package-perfection/-/commits/master" title="GitLab CI build status" target="_blank"> <img alt="Build status" src="https://img.shields.io/gitlab/pipeline-status/megabyte-labs/npm/plugin/prettier-plugin-package-perfection?branch=master&label=build&logo=gitlab&logoColor=white&style=flat-square"> </a> <a href="https://www.npmjs.com/package/prettier-plugin-package-perfection" title="Dependency status reported by Depfu" target="_blank"> <img alt="Dependency status reported by Depfu" src="https://img.shields.io/depfu/megabyte-labs/prettier-plugin-package-perfection?logo=codeforces&logoColor=white&style=flat-square&logo=npm" /> </a> <a href="https://www.npmjs.com/package/prettier-plugin-package-perfection" title="Zip file size" target="_blank"> <img alt="Zip file size" src="https://img.shields.io/bundlephobia/minzip/prettier-plugin-package-perfection?style=flat-square&logo=npm&logoColor=white" /> </a> <a href="https://www.npmjs.com/package/prettier-plugin-package-perfection" title="Total downloads of prettier-plugin-package-perfection on npmjs.org" target="_blank"> <img alt="Total downloads of prettier-plugin-package-perfection on npmjs.org" src="https://img.shields.io/npm/dt/prettier-plugin-package-perfection?style=flat-square&logo=npm&logoColor=white" /> </a> <a href="https://snyk.io/advisor/npm-package/prettier-plugin-package-perfection" title="Number of vulnerabilities from Snyk scan on prettier-plugin-package-perfection" target="_blank"> <img alt="Number of vulnerabilities from Snyk scan on prettier-plugin-package-perfection" src="https://img.shields.io/snyk/vulnerabilities/npm/prettier-plugin-package-perfection?style=flat-square&logo=snyk&logoColor=white" /> </a> <a href="website.documentation/npm" target="_blank"> <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg?logo=readthedocs&logoColor=white&style=flat-square" /> </a> <a href="https://github.com/megabyte-labs/prettier-plugin-package-perfection/blob/master/LICENSE" target="_blank"> <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-yellow.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAHpJREFUCNdjYOD/wMDAUP+PgYHxhzwDA/MB5gMM7AwMDxj4GBgKGGQYGCyAEEgbMDDwAAWAwmk8958xpIOI5zKH2RmOyhxmZjguAiKmgIgtQOIYmFgCIp4AlaQ9OczGkJYCJEAGgI0CGwo2HmwR2Eqw5SBnNIAdBHYaAJb6KLM15W/CAAAAAElFTkSuQmCC&style=flat-square" /> </a> </div> > </br><h4 align="center">**A Prettier plugin that formats the package.json file by leveraging the prettier-package-json CLI library**</h4></br> <a href="#table-of-contents" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Table of Contents - [Overview](#overview) - [Requirements](#requirements) - [Developer Requirements](#developer-requirements) - [Usage / Installation](#usage--installation) - [Shared Configuration](#shared-configuration) - [Example Configuration](#example-configuration) - [Contributing](#contributing) - [Affiliates](#affiliates) - [License](#license) <a href="#overview" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Overview The **[prettier-package-json](https://www.npmjs.com/package/prettier-package-json)** CLI tool is easily the best `package.json` formatter available. However, despite its name, it is not a Prettier plugin. This project brings all of the great `prettier-package-json` features to Prettier as a plugin. It sorts in an opinionated style and also has some nifty features that other formatters do not have like: - Sorting in an opinionated manner (common elements at the top of the file and everything else sorted alphabetically afterwards) - Sorting scripts while keeping `pre` and `post` commands together - Removing redundant or unnecessary fields in favor of more compact syntax - More information available on the [prettier-package-json npmjs.org page](https://www.npmjs.com/package/prettier-package-json) <a href="#requirements" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Requirements If you are simply including this library in your project, all you need is a recent version of Node.js. **[Node.js >14.18.0](repository.project.node)** is sometimes required and is the only version range we actively support. Albeit, it is highly probable that lower versions will work as well depending on the requirements that this project imports. ### Developer Requirements The following versions of Node.js and Python are required for development: - **[Node.js >14.18.0](repository.project.node)** - **[Python >3.10.0](repository.project.python)** Other versions may work, but only the above versions are supported. Most development dependencies are installed automatically by our `Taskfile.yml` set-up (even Node.js and Python). Run `bash start.sh` to install **[Bodega](https://github.com/ProfessorManhattan/Bodega)** (an improved fork of [go-task](https://github.com/go-task/task)) and run the initialization sequence. The taskfiles will automatically install dependencies as they are needed, based on what development tasks you are running. For more information, check out the [CONTRIBUTING.md](https://github.com/megabyte-labs/prettier-plugin-package-perfection/blob/main/docs/CONTRIBUTING.md) or simply run: ```shell npm run help ``` `npm run help` will ensure Bodega is installed and then open an interactive dialog where you can explore and learn about various developer commands. <a href="#usage--installation" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Usage / Installation Prettier plugins are automatically registered if their package name begins with `@prettier/plugin-`, `prettier-plugin-`, or `@<scope>/prettier-plugin-`. Since this package begins with `prettier-plugin-`, all you have to do is install it via: ```shell npm install --save-dev prettier-plugin-package-perfection ``` That is it! You are good to go. Prettier should automatically pick up on the plugin. <a href="#shared-configuration" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Shared Configuration With Prettier, you can create a shared configuration that you can share across all your projects. To do this, you first have to find or create an NPM package that will house your configuration. Then, you have to set the `.prettier` key in `package.json` equal to the name of your shared configuration NPM package. You can find an [example shared configuration NPM package here](https://github.com/ProfessorManhattan/prettier-config-sexy-mode) (check out the `src/main.ts` file to see the magic). All the configuration does is export a typical configuration with `module.exports`. This opens the door for dynamically configuring your project's configuration and keeping things DRY. <a href="#example-configuration" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Example Configuration Specifically including this Prettier plugin in your configuration might look something like this: ```json { "bracketSpacing": true, "printWidth": 120, "quoteProps": "as-needed", "requirePragma": false, "semi": false, "singleQuote": true, "tabWidth": 2, "trailingComma": "none", "useTabs": false, "goTemplateBracketSpacing": true, "overrides": [ { "files": ["*.go.html"], "options": { "parser": "go-template" } }, { "files": ["*.yml"], "options": { "printWidth": 160 } } ], "plugins": [ "@prettier/plugin-xml", "prettier-plugin-go-template", "prettier-plugin-ini", "prettier-plugin-organize-imports", "prettier-plugin-package-perfection", "prettier-plugin-properties", "prettier-plugin-sh" ] } ``` <a href="#contributing" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## Contributing Contributions, issues, and feature requests are welcome! Feel free to check the [issues page](https://github.com/megabyte-labs/prettier-plugin-package-perfection/issues). If you would like to contribute, please take a look at the [contributing guide](https://github.com/megabyte-labs/prettier-plugin-package-perfection/blob/master/docs/CONTRIBUTING.md). <details> <summary><b>Sponsorship</b></summary> <br/> <blockquote> <br/> Dear Awesome Person,<br/><br/> I create open source projects out of love. Although I have a job, shelter, and as much fast food as I can handle, it would still be pretty cool to be appreciated by the community for something I have spent a lot of time and money on. Please consider sponsoring me! Who knows? Maybe I will be able to quit my job and publish open source full time. <br/><br/>Sincerely,<br/><br/> **_Brian Zalewski_**<br/><br/> </blockquote> <a title="Support us on Open Collective" href="https://opencollective.com/megabytelabs" target="_blank"> <img alt="Open Collective sponsors" src="https://img.shields.io/opencollective/sponsors/megabytelabs?logo=opencollective&label=OpenCollective&logoColor=white&style=for-the-badge" /> </a> <a title="Support us on GitHub" href="https://github.com/ProfessorManhattan" target="_blank"> <img alt="GitHub sponsors" src="https://img.shields.io/github/sponsors/ProfessorManhattan?label=GitHub%20sponsors&logo=github&style=for-the-badge" /> </a> <a href="https://www.patreon.com/ProfessorManhattan" title="Support us on Patreon" target="_blank"> <img alt="Patreon" src="https://img.shields.io/badge/Patreon-Support-052d49?logo=patreon&logoColor=white&style=for-the-badge" /> </a> ### Affiliates Below you will find a list of services we leverage that offer special incentives for signing up for their services through our special links: <a href="http://eepurl.com/h3aEdX" title="Sign up for $30 in MailChimp credits" target="_blank"> <img alt="MailChimp" src="https://cdn-images.mailchimp.com/monkey_rewards/grow-business-banner-2.png" /> </a> <a href="https://www.digitalocean.com/?refcode=751743d45e36&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge"> <img src="https://web-platforms.sfo2.digitaloceanspaces.com/WWW/Badge%203.svg" alt="DigitalOcean Referral Badge" /> </a> </details> <a href="#license" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a> ## License Copyright © 2020-2021 [Megabyte LLC](https://megabyte.space). This project is [MIT](https://gitlab.com/megabyte-labs/npm/plugin/prettier-plugin-package-perfection/-/blob/master/LICENSE) licensed.