useSortedPackageJson (JSON)
Summary
Section titled “Summary”- Rule available since:
v2.5.0 - Diagnostic Category:
assist/source/useSortedPackageJson - Sources:
- Same as
sort-package-json - Inspired from
package-json/sort-collections - Inspired from
package-json-dependencies/alphabetically-sorted-dependencies - Inspired from
unordered-dependencies
- Same as
How to enable in your editor
Section titled “How to enable in your editor”{ "editor.codeActionsOnSave": { "source.action.useSortedPackageJson.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.useSortedPackageJson.biome": true, "source.fixAll.biome": true }}source.action.useSortedPackageJson.biome How to configure
Section titled “How to configure”{ "assist": { "actions": { "source": { "useSortedPackageJson": "on" } } }}Description
Section titled “Description”Organize package.json fields according to established conventions.
The action follows the conventions of the sort-package-json tool.
Sorting rules
Section titled “Sorting rules”Known fields follow the order in the table below. Unlisted fields are sorted alphabetically
after known fields, while fields beginning with _ are placed last. “Key sort” means sorting
the keys of a nested object. “Unique items” removes repeated array entries while preserving
their order; “sort unique items” also sorts the remaining entries.
| Key | Rules |
|---|---|
| $schema | |
| name | |
| displayName | |
| version | |
| stableVersion | |
| private | |
| description | |
| categories | Unique items |
| keywords | Unique items |
| homepage | |
| bugs | Key order: url, email |
| repository | Key order: type, url |
| funding | Key order: type, url |
| license | Key order: type, url |
| qna | |
| author | Key order: name, email, url |
| maintainers | Key order (per item): name, email, url |
| contributors | Key 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 | |
| bin | Key sort |
| man | |
| directories | Key order: lib, bin, man, doc, example, test |
| files | Unique items |
| workspaces | Key order (when object): packages, catalog |
| binary | Key order: module_name, module_path, remote_path, package_name, host |
| scripts | Script sort |
| betterScripts | Script sort |
| l10n | |
| contributes | Key sort |
| activationEvents | Unique items |
| husky | Sorts the hooks field using git hook sort |
| simple-git-hooks | Key sort using git hook sort |
| pre-commit | |
| commitlint | Key sort |
| lint-staged | |
| nano-staged | |
| config | Key sort |
| nodemonConfig | Key sort |
| browserify | Key sort |
| babel | Key sort |
| browserslist | |
| xo | Key sort |
| prettier | Prettier sort |
| eslintConfig | ESLint sort |
| eslintIgnore | |
| npmpackagejsonlint | Key sort (also recognizes: npmPackageJsonLintConfig, npmpkgjsonlint) |
| release | Key sort |
| remarkConfig | Key sort |
| stylelint | |
| ava | Key sort |
| jest | Key sort |
| jest-junit | Key sort |
| jest-stare | Key sort |
| mocha | Key sort |
| nyc | Key sort |
| c8 | Key sort |
| tap | Key sort |
| oclif | Key sort (deep) |
| resolutions | Key sort |
| dependencies | Key sort |
| devDependencies | Key sort |
| dependenciesMeta | Key sort (deep) |
| peerDependencies | Key sort |
| peerDependenciesMeta | Key sort (deep) |
| optionalDependencies | Key sort |
| bundledDependencies | Sort unique items |
| bundleDependencies | Sort unique items |
| extensionPack | Sort unique items |
| extensionDependencies | Sort unique items |
| flat | |
| packageManager | |
| engines | Key sort |
| engineStrict | Key sort |
| devEngines | Key order (packageManager): name, version, onFail |
| volta | Key order: node, npm, yarn |
| languageName | |
| os | |
| cpu | |
| preferGlobal | Key sort |
| publishConfig | Key sort |
| icon | |
| badges | Key order (per item): description, url, href |
| galleryBanner | Key sort |
| preview | |
| markdown | |
| pnpm | Base property order: neverBuiltDependencies, onlyBuiltDependencies, onlyBuiltDependenciesFile, overrides, packageExtensions, patchedDependencies, peerDependencyRules, allowedDeprecatedVersions, allowNonAppliedPatches, auditConfig, ignoredOptionalDependencies, updateConfig. Other properties sorted alphabetically. Deep sorting applied. |
Special rules
Section titled “Special rules”ESLint
Section titled “ESLint”Fields are sorted by the order they are listed below:
| Key | Rules |
|---|---|
| env | |
| parser | |
| parserOptions | |
| settings | |
| plugins | |
| extends | |
| rules | Group built-in rules first, then plugin rules. Each group is sorted |
| overrides | Key order (per item): files, excludedFiles |
| globals | |
| processor | |
| noInlineConfig | |
| reportUnusedDisableDirectives |
Git Hooks
Section titled “Git Hooks”Item order:
applypatch-msgpre-applypatchpost-applypatchpre-commitpre-merge-commitprepare-commit-msgcommit-msgpost-commitpre-rebasepost-checkoutpost-mergepre-pushpre-receiveupdateproc-receivepost-receivepost-updatereference-transactionpush-to-checkoutpre-auto-gcpost-rewritesendemail-validatefsmonitor-watchmanp4-changelistp4-prepare-changelistp4-post-changelistp4-pre-submitpost-index-change
Prettier
Section titled “Prettier”Keys are sorted alphabetically except for overrides, which is placed last. Keys inside
overrides entries and their options objects are also sorted.
Scripts
Section titled “Scripts”Keys are sorted alphabetically except for pre- and post-scripts, which are placed immediately before and after their base script.
For example, preinstall and postinstall stay next to 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
Examples
Section titled “Examples”Invalid
Section titled “Invalid”{ "dependencies": { "lodash": "^4.0.0" }, "name": "my-package", "version": "1.0.0"}/package.json ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Source action diff:
1 1 │ {
2 │ - ··"dependencies":·{
3 │ - ····"lodash":·"^4.0.0"
4 │ - ··},
5 │ - ··"name":·"my-package",
6 │ - ··"version":·"1.0.0"
2 │ + ··"name":·"my-package",
3 │ + ··"version":·"1.0.0",
4 │ + ··"dependencies":·{
5 │ + ····"lodash":·"^4.0.0"
6 │ + ··}
7 7 │ }
8 8 │
{ "name": "my-package", "version": "1.0.0", "dependencies": { "lodash": "^4.0.0" }}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.