Skip to content
An opinionated package.json formatter plugin for Prettier
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.github
assets
lib
test
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.nvmrc
.prettierrc
LICENSE
README.md
codecov.yml
commitlint.config.js
package-lock.json
package.json

README.md

banner

prettier-plugin-package tests cover size libera manifesto

An opinionated package.json formatter plugin for Prettier

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 Node version (v8.0.0+).

Install

Using npm:

npm install prettier prettier-plugin-package --save-dev

Please consider donating if you find this project useful.

Usage

Once installed, Prettier plugins should be automatically recognized by Prettier. To use this plugin, confirm that it's installed and run Prettier using your preferred method. For example:

$ 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, 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. Known keys, and their order are:

[
  // meta
  'name',
  'version',
  'flat',
  'private',
  'publishConfig',
  'description',
  'license',
  'repository',
  'author',
  'homepage',
  'bugs',

  // entry
  'main',
  'bin',

  // constraints
  'engines',
  'cpu',
  'os',

  // content and util
  'scripts',
  'files',
  'keywords',

  // dependencies
  'bundledDependencies',
  'optionalDependencies',
  'peerDependencies',
  'dependencies',
  'devDependencies',
  'resolutions'
]

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

LICENSE (Mozilla Public License)

You can’t perform that action at this time.