prettier-plugin-expand-json 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +61 -67
package/README.md
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/porada/prettier-plugin-expand-json">
|
|
3
|
+
<picture>
|
|
4
|
+
<source srcset="https://github.com/porada/prettier-plugin-expand-json/blob/main/assets/prettier-plugin-expand-json-dark-scheme@3x.png?raw=true" media="(prefers-color-scheme: dark)" />
|
|
5
|
+
<source srcset="https://github.com/porada/prettier-plugin-expand-json/blob/main/assets/prettier-plugin-expand-json-light-scheme@3x.png?raw=true" media="(prefers-color-scheme: light)" />
|
|
6
|
+
<img src="https://github.com/porada/prettier-plugin-expand-json/blob/main/assets/prettier-plugin-expand-json-light-scheme@3x.png?raw=true" width="520" alt="" />
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
<h1 align="center">
|
|
12
|
+
prettier-plugin-expand‑json
|
|
13
|
+
</h1>
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
<p align="center">
|
|
16
|
+
Expand JSON arrays and objects into multi‑line format with Prettier.
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<a href="https://www.npmjs.com/package/prettier-plugin-expand-json"><img src="https://img.shields.io/npm/v/prettier-plugin-expand-json" alt="" /></a>
|
|
21
|
+
<a href="https://github.com/porada/prettier-plugin-expand-json/actions/workflows/test.yaml"><img src="https://img.shields.io/github/actions/workflow/status/porada/prettier-plugin-expand-json/test.yaml" alt="" /></a>
|
|
22
|
+
<a href="https://codecov.io/github/porada/prettier-plugin-expand-json"><img src="https://img.shields.io/codecov/c/github/porada/prettier-plugin-expand-json" alt="" /></a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<div> </div>
|
|
26
|
+
|
|
27
|
+
## Overview
|
|
28
|
+
|
|
29
|
+
This plugin expands all JSON arrays and objects into a consistent multi-line format.
|
|
30
|
+
|
|
31
|
+
- Works with both JSON and JSONC files.
|
|
32
|
+
- Supports files that Prettier treats as special cases, including `package.json`, `composer.json`, and others.
|
|
33
|
+
- Comes without any additional dependencies.
|
|
8
34
|
|
|
9
35
|
## Example
|
|
10
36
|
|
|
@@ -57,7 +83,7 @@ Reference `prettier-plugin-expand-json` in your [Prettier config](https://pretti
|
|
|
57
83
|
}
|
|
58
84
|
```
|
|
59
85
|
|
|
60
|
-
If you’re using
|
|
86
|
+
If you’re using any other JSON plugins, make sure `prettier-plugin-expand-json` is listed last. This applies to each `overrides` entry as well.
|
|
61
87
|
|
|
62
88
|
```json
|
|
63
89
|
{
|
|
@@ -70,12 +96,9 @@ If you’re using multiple JSON-related plugins, make sure `prettier-plugin-expa
|
|
|
70
96
|
|
|
71
97
|
```json
|
|
72
98
|
{
|
|
73
|
-
"plugins": [
|
|
74
|
-
"prettier-plugin-expand-json"
|
|
75
|
-
],
|
|
76
99
|
"overrides": [
|
|
77
100
|
{
|
|
78
|
-
"files": "
|
|
101
|
+
"files": "**/package.json",
|
|
79
102
|
"options": {
|
|
80
103
|
"plugins": [
|
|
81
104
|
"prettier-plugin-pkg",
|
|
@@ -87,9 +110,10 @@ If you’re using multiple JSON-related plugins, make sure `prettier-plugin-expa
|
|
|
87
110
|
}
|
|
88
111
|
```
|
|
89
112
|
|
|
90
|
-
##
|
|
113
|
+
## Related
|
|
91
114
|
|
|
92
|
-
|
|
115
|
+
- [**@standard-config/prettier**](https://github.com/standard-config/prettier)
|
|
116
|
+
- [**prettier-plugin-yaml**](https://github.com/porada/prettier-plugin-yaml)
|
|
93
117
|
|
|
94
118
|
## License
|
|
95
119
|
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cA8Fa,OAAA,EAAS,MAAA;AAAA,cAUT,QAAA,EAAU,MAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { applyEdits, format } from "jsonc-parser";
|
|
2
1
|
import { parsers as parsers$1 } from "prettier/plugins/babel";
|
|
3
2
|
import { printers as printers$1 } from "prettier/plugins/estree";
|
|
4
3
|
|
|
@@ -11,11 +10,7 @@ function createParser(name) {
|
|
|
11
10
|
const preprocess = async (text, options) => {
|
|
12
11
|
const priorParser = findPriorParser(name, options, parse);
|
|
13
12
|
if (typeof priorParser?.preprocess === "function") text = await priorParser.preprocess(text, omitCurrentParser(name, options, parse));
|
|
14
|
-
|
|
15
|
-
insertSpaces: !options.useTabs,
|
|
16
|
-
tabSize: options.tabWidth
|
|
17
|
-
});
|
|
18
|
-
return applyEdits(text, edits);
|
|
13
|
+
return text;
|
|
19
14
|
};
|
|
20
15
|
return {
|
|
21
16
|
...parsers$1[name],
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["babelParsers","estreePrinters"],"sources":["../src/index.ts"],"sourcesContent":["import type { Parser, ParserOptions, Plugin } from 'prettier';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["babelParsers","estreePrinters"],"sources":["../src/index.ts"],"sourcesContent":["import type { Parser, ParserOptions, Plugin } from 'prettier';\nimport type { ParserName, PluginWithParsers } from './types/index.d.ts';\nimport { parsers as babelParsers } from 'prettier/plugins/babel';\nimport { printers as estreePrinters } from 'prettier/plugins/estree';\n\nfunction createParser(name: ParserName): Parser {\n\tconst parse: Parser['parse'] = async (\n\t\ttext: string,\n\t\toptions: ParserOptions\n\t) => {\n\t\tconst priorParser = findPriorParser(name, options, parse);\n\n\t\t/* oxlint-disable-next-line typescript/no-unsafe-return */\n\t\treturn typeof priorParser?.parse === 'function'\n\t\t\t? await priorParser.parse(\n\t\t\t\t\ttext,\n\t\t\t\t\tomitCurrentParser(name, options, parse)\n\t\t\t\t)\n\t\t\t: babelParsers[name].parse(text, options);\n\t};\n\n\tconst preprocess: NonNullable<Parser['preprocess']> = async (\n\t\ttext: string,\n\t\toptions: ParserOptions\n\t) => {\n\t\tconst priorParser = findPriorParser(name, options, parse);\n\n\t\tif (typeof priorParser?.preprocess === 'function') {\n\t\t\t/* oxlint-disable-next-line eslint/no-param-reassign */\n\t\t\ttext = await priorParser.preprocess(\n\t\t\t\ttext,\n\t\t\t\tomitCurrentParser(name, options, parse)\n\t\t\t);\n\t\t}\n\n\t\treturn text;\n\t};\n\n\treturn {\n\t\t...babelParsers[name],\n\t\tastFormat: 'estree-json',\n\t\tparse,\n\t\tpreprocess,\n\t};\n}\n\nfunction findPriorParser(\n\tname: ParserName,\n\toptions: ParserOptions,\n\tcurrentParse: Parser['parse']\n): Parser | undefined {\n\tfor (const plugin of options.plugins.toReversed()) {\n\t\tif (!isParserPlugin(plugin)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst parser = plugin.parsers[name];\n\n\t\tif (parser && parser.parse !== currentParse) {\n\t\t\treturn parser;\n\t\t}\n\t}\n\n\t/* v8 ignore next -- @preserve */\n\treturn undefined;\n}\n\nfunction isParserPlugin(plugin: unknown): plugin is PluginWithParsers {\n\t/* v8 ignore if -- @preserve */\n\tif (!plugin) {\n\t\treturn false;\n\t}\n\n\treturn typeof plugin === 'object' && Object.hasOwn(plugin, 'parsers');\n}\n\nfunction omitCurrentParser(\n\tname: ParserName,\n\toptions: ParserOptions,\n\tcurrentParse: Parser['parse']\n): ParserOptions {\n\treturn {\n\t\t...options,\n\t\tplugins: options.plugins.filter((plugin) => {\n\t\t\tif (!isParserPlugin(plugin)) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst parser = plugin.parsers[name];\n\t\t\treturn !(parser && parser.parse === currentParse);\n\t\t}),\n\t};\n}\n\nexport const parsers: Plugin['parsers'] = {\n\t'json': createParser('json'),\n\t'json-stringify': createParser('json-stringify'),\n\t'jsonc': createParser('jsonc'),\n};\n\n// Necessary for comment support in JSONC files\nconst { canAttachComment, isBlockComment, printComment } =\n\testreePrinters.estree;\n\nexport const printers: Plugin['printers'] = {\n\t'estree-json': {\n\t\t...estreePrinters['estree-json'],\n\t\tcanAttachComment,\n\t\tisBlockComment,\n\t\tprintComment,\n\t},\n};\n"],"mappings":";;;;AAKA,SAAS,aAAa,MAA0B;CAC/C,MAAM,QAAyB,OAC9B,MACA,YACI;EACJ,MAAM,cAAc,gBAAgB,MAAM,SAAS,MAAM;AAGzD,SAAO,OAAO,aAAa,UAAU,aAClC,MAAM,YAAY,MAClB,MACA,kBAAkB,MAAM,SAAS,MAAM,CACvC,GACAA,UAAa,MAAM,MAAM,MAAM,QAAQ;;CAG3C,MAAM,aAAgD,OACrD,MACA,YACI;EACJ,MAAM,cAAc,gBAAgB,MAAM,SAAS,MAAM;AAEzD,MAAI,OAAO,aAAa,eAAe,WAEtC,QAAO,MAAM,YAAY,WACxB,MACA,kBAAkB,MAAM,SAAS,MAAM,CACvC;AAGF,SAAO;;AAGR,QAAO;EACN,GAAGA,UAAa;EAChB,WAAW;EACX;EACA;EACA;;AAGF,SAAS,gBACR,MACA,SACA,cACqB;AACrB,MAAK,MAAM,UAAU,QAAQ,QAAQ,YAAY,EAAE;AAClD,MAAI,CAAC,eAAe,OAAO,CAC1B;EAGD,MAAM,SAAS,OAAO,QAAQ;AAE9B,MAAI,UAAU,OAAO,UAAU,aAC9B,QAAO;;;AAQV,SAAS,eAAe,QAA8C;;AAErE,KAAI,CAAC,OACJ,QAAO;AAGR,QAAO,OAAO,WAAW,YAAY,OAAO,OAAO,QAAQ,UAAU;;AAGtE,SAAS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-
|
|
63
|
-
"prepack": "pnpm run '/^(format:check|lint:check|test|typecheck)$/' && pnpm build",
|
|
64
|
-
"prepare": "husky",
|
|
65
|
-
"test": "vitest run",
|
|
66
|
-
"typecheck": "tsc --noEmit"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
2
|
+
"name": "prettier-plugin-expand-json",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Expand JSON arrays and objects into multi-line format with Prettier",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Dom Porada",
|
|
8
|
+
"email": "dom@dom.engineering",
|
|
9
|
+
"url": "https://dom.engineering"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/porada/prettier-plugin-expand-json.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"formatting",
|
|
17
|
+
"json",
|
|
18
|
+
"jsonc",
|
|
19
|
+
"prettier",
|
|
20
|
+
"prettier-plugin"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/**"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"prettier": ">=3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@standard-config/eslint": "1.2.1",
|
|
37
|
+
"@standard-config/prettier": "1.7.0",
|
|
38
|
+
"@standard-config/tsconfig": "2.0.2",
|
|
39
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
40
|
+
"eslint": "9.39.2",
|
|
41
|
+
"husky": "9.1.7",
|
|
42
|
+
"jiti": "2.6.1",
|
|
43
|
+
"oxlint": "1.42.0",
|
|
44
|
+
"oxlint-tsgolint": "0.11.3",
|
|
45
|
+
"prettier": "3.8.1",
|
|
46
|
+
"prettier-plugin-sort-json": "4.2.0",
|
|
47
|
+
"publint": "0.3.17",
|
|
48
|
+
"tsdown": "0.20.1",
|
|
49
|
+
"typescript": "5.9.3",
|
|
50
|
+
"vitest": "4.0.18"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsdown",
|
|
54
|
+
"fix": "pnpm format && pnpm lint",
|
|
55
|
+
"format": "prettier --write --ignore-unknown .",
|
|
56
|
+
"format:check": "prettier --check --ignore-unknown .",
|
|
57
|
+
"lint": "oxlint --fix --type-aware --type-check --deny-warnings --report-unused-disable-directives && eslint . --fix",
|
|
58
|
+
"lint:check": "oxlint --type-aware --type-check --deny-warnings --report-unused-disable-directives && eslint .",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"typecheck": "tsc --noEmit"
|
|
61
|
+
}
|
|
62
|
+
}
|