Default Rules

March 26, 2024 ยท View on GitHub

package.json fields are sorted by the order they are listed below. The default key sort order is alphabetical.

Note: when a specific key order is used, any other keys will be sorted in the end of the object

KeyRules
$schema
name
displayName
version
private
description
categoriesUnique items
keywordsUnique items
homepage
bugsKey order: url, email
repositoryKey order: type, url
fundingKey order: type, url
licenseKey order: type, url
qna
authorKey order: name, email, url
maintainersKey order (per item): name, email, url
contributorsKey order (per item): name, email, url
publisher
sideEffects
type
imports
exports
main
svelte
umd:main
jsdelivr
unpkg
module
source
jsnext:main
browser
react-native
types
typesVersions
typings
style
example
examplestyle
assets
binKey sort
man
directoriesKey order: lib, bin, man, doc, example, test
filesUnique items
workspaces
binary,Key order: module_name, module_path, remote_path, package_name, host
scriptsScript sort
betterScriptsScript sort
contributesKey sort
activationEventsUnique items
huskySorts the hooks field using git hook sort
simple-git-hooksKey sort using git hook sort
pre-commit
commitlintKey sort
lint-staged
nano-staged
configKey sort
nodemonConfigKey sort
browserifyKey sort
babelKey sort
browserslist
xoKey sort
prettierPrettier sort
eslintConfigESLint sort
eslintIgnore
npmpackagejsonlintKey sort (also recognizes: npmPackageJsonLintConfig, npmpkgjsonlint)
releaseKey sort
remarkConfigKey sort
stylelint
avaKey sort
jestKey sort
mochaKey sort
nycKey sort
tapKey sort
oclifKey sort (deep)
resolutionsKey sort
dependenciesKey sort
devDependenciesKey sort
dependenciesMetaKey sort (deep)
peerDependenciesKey sort
peerDependenciesMetaKey sort (deep)
optionalDependenciesKey sort
bundledDependenciesSort unique items
bundleDependenciesSort unique items
extensionPackSort unique items
extensionDependenciesSort unique items
flat
packageManager
enginesKey sort
engineStrictKey sort
voltaKey order: node, npm, yarn
languageName
os
cpu
preferGlobalKey sort
publishConfigKey sort
icon
badgesKey order (per item): description, url, href
galleryBannerKey sort
preview
markdown
pnpmKey sort (deep)

Special Rules

ESLint

Fields are sorted by the order they are listed below:

KeyRules
env
parser
parserOptions
settings
plugins
extends
rulesGroup built-in rules first, then plugin rules. Each group is sorted
overridesKey order (per item): files, excludedFiles
globals
processor
noInlineConfig
reportUnusedDisableDirectives

Git Hooks

Item order:

  • applypatch-msg
  • pre-applypatch
  • post-applypatch
  • pre-commit
  • pre-merge-commit
  • prepare-commit-msg
  • commit-msg
  • post-commit
  • pre-rebase
  • post-checkout
  • post-merge
  • pre-push
  • pre-receive
  • update
  • post-receive
  • post-update
  • push-to-checkout
  • pre-auto-gc
  • post-rewrite
  • sendemail-validate
  • fsmonitor-watchman
  • p4-pre-submit
  • post-index-chang

Prettier

Keys are sorted alphabetically except for overrides, which is placed last. Keys are also sorted in overrides and overrides.options items.

Scripts

Keys are sorted alphabetically except for pre/post scripts. Those are placed before and after their corresponding base npm script.

An example - notice how preinstall and postinstall are placed before and after install:

{
  "scripts": {
    "build": "",
    "preinstall": "",
    "install": "",
    "postinstall": "",
    "lint": ""
  }
}

Scripts for which the pre/post order is applied:

  • install
  • pack
  • prepare
  • publish
  • restart
  • shrinkwrap
  • start
  • stop
  • test
  • uninstall
  • version