-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from matzkoh/topic-use-external-sort-lib
BREAKING CHANGE: replace sort logic with sort-package-json
- Loading branch information
Showing
7 changed files
with
110 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,18 @@ | ||
# Prettier plugin for package.json | ||
|
||
[![CircleCI](https://circleci.com/gh/matzkoh/prettier-plugin-packagejson.svg?style=shield)](https://circleci.com/gh/matzkoh/prettier-plugin-packagejson) | ||
[![Renovate](https://badges.renovateapi.com/github/matzkoh/prettier-plugin-packagejson)](https://renovatebot.com/) | ||
[![npm](https://img.shields.io/npm/v/prettier-plugin-packagejson.svg)](https://www.npmjs.com/package/prettier-plugin-packagejson) | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm i -D prettier prettier-plugin-packagejson | ||
``` | ||
|
||
`overrides` is required because native json parser takes precedence over this plugin. | ||
# prettier-plugin-packagejson | ||
|
||
```json | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
This is [Prettier] plugin to make the keys of package.json well sorted order. | ||
|
||
"overrides": [ | ||
{ | ||
"files": "package.json", | ||
"options": { | ||
"parser": "package-json" | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
Using [sort-package-json]. | ||
|
||
## Rules | ||
[Prettier]: https://github.com/prettier/prettier | ||
[sort-package-json]: https://github.com/keithamus/sort-package-json | ||
|
||
- Primary (ordered to top) | ||
1. name | ||
2. description | ||
3. version | ||
4. author | ||
5. license | ||
- Others | ||
- Sorted alphabetically | ||
- Sort children | ||
- dependencies | ||
- devDependencies | ||
- peerDependencies | ||
- optionalDependencies | ||
- keywords | ||
## Installation | ||
|
||
ToDo: Add more tweaks | ||
```bash | ||
$ npm i -D prettier prettier-plugin-packagejson | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
const { parsers } = require('prettier/parser-babylon') | ||
const sortPackageJson = require('sort-package-json') | ||
const parser = parsers['json-stringify'] | ||
const printer = require('./printer') | ||
|
||
exports.parsers = { | ||
'package-json': { | ||
'json-stringify': { | ||
...parser, | ||
astFormat: 'package-json', | ||
}, | ||
} | ||
|
||
exports.printers = { | ||
'package-json': { | ||
...printer, | ||
preprocess(text, options) { | ||
if (parser.preprocess) { | ||
text = parser.preprocess(text, options) | ||
} | ||
return sortPackageJson(text) | ||
}, | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
{ | ||
"name": "prettier-plugin-packagejson", | ||
"description": "Prettier package.json plugin to make the order of properties nice.", | ||
"version": "0.0.0-development", | ||
"license": "MIT", | ||
"dependencies": { | ||
"prettier": "1.18.2" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"description": "Prettier package.json plugin to make the order of properties nice.", | ||
"keywords": [ | ||
"package.json", | ||
"plugin", | ||
"prettier" | ||
], | ||
"homepage": "https://github.com/matzkoh/prettier-plugin-packagejson#readme", | ||
"bugs": { | ||
"url": "https://github.com/matzkoh/prettier-plugin-packagejson/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/matzkoh/prettier-plugin-packagejson.git" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "node test" | ||
}, | ||
"dependencies": { | ||
"sort-package-json": "1.22.1" | ||
}, | ||
"devDependencies": { | ||
"prettier": "1.18.2" | ||
}, | ||
"peerDependencies": { | ||
"prettier": ">= 1.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters