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 CHANGED
@@ -1,10 +1,36 @@
1
- [![](https://img.shields.io/npm/v/prettier-plugin-expand-json)](https://www.npmjs.com/package/prettier-plugin-expand-json)
2
- [![](https://img.shields.io/github/actions/workflow/status/porada/prettier-plugin-expand-json/test.yaml)](https://github.com/porada/prettier-plugin-expand-json/actions/workflows/test.yaml)
3
- [![](https://img.shields.io/codecov/c/github/porada/prettier-plugin-expand-json)](https://codecov.io/github/porada/prettier-plugin-expand-json)
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
- # prettier-plugin-expand-json
11
+ <h1 align="center">
12
+ prettier-plugin-expand&#8209;json
13
+ </h1>
6
14
 
7
- Expand JSON arrays and objects into multi-line notation with Prettier—for JSON and JSONC files.
15
+ <p align="center">
16
+ Expand JSON arrays and objects into multi&#8209;line&nbsp;format with&nbsp;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>&nbsp;</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 multiple JSON-related plugins, make sure `prettier-plugin-expand-json` is listed last. This applies to each `overrides` entry as well.
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": "packages/**/package.json",
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
- ## Recommended
113
+ ## Related
91
114
 
92
- Try [**@standard-config/prettier**](https://github.com/standard-config/prettier) if you’re looking for a consistent, TypeScript-first Prettier config. It comes with this plugin pre-configured.
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
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cA0Ga,OAAA,EAAS,MAAA;AAAA,cAUT,QAAA,EAAU,MAAA"}
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
- const edits = format(text, void 0, {
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],
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["babelParsers","estreePrinters"],"sources":["../src/index.ts"],"sourcesContent":["import type { Parser, ParserOptions, Plugin } from 'prettier';\nimport { applyEdits, format } from 'jsonc-parser';\nimport { parsers as babelParsers } from 'prettier/plugins/babel';\nimport { printers as estreePrinters } from 'prettier/plugins/estree';\n\ntype ParserName = 'json' | 'json-stringify' | 'jsonc';\n\ntype ParserPlugin = Omit<Plugin, 'parsers'> & {\n\tparsers: NonNullable<Plugin['parsers']>;\n};\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\t// This is where the actual expansion happens\n\t\tconst edits = format(text, undefined, {\n\t\t\tinsertSpaces: !options.useTabs,\n\t\t\ttabSize: options.tabWidth,\n\t\t});\n\n\t\treturn applyEdits(text, edits);\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 ParserPlugin {\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":";;;;;AAWA,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;EAIF,MAAM,QAAQ,OAAO,MAAM,QAAW;GACrC,cAAc,CAAC,QAAQ;GACvB,SAAS,QAAQ;GACjB,CAAC;AAEF,SAAO,WAAW,MAAM,MAAM;;AAG/B,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,QAAyC;;AAEhE,KAAI,CAAC,OACJ,QAAO;AAGR,QAAO,OAAO,WAAW,YAAY,OAAO,OAAO,QAAQ,UAAU;;AAGtE,SAAS,kBACR,MACA,SACA,cACgB;AAChB,QAAO;EACN,GAAG;EACH,SAAS,QAAQ,QAAQ,QAAQ,WAAW;AAC3C,OAAI,CAAC,eAAe,OAAO,CAC1B,QAAO;GAGR,MAAM,SAAS,OAAO,QAAQ;AAC9B,UAAO,EAAE,UAAU,OAAO,UAAU;IACnC;EACF;;AAGF,MAAa,UAA6B;CACzC,QAAQ,aAAa,OAAO;CAC5B,kBAAkB,aAAa,iBAAiB;CAChD,SAAS,aAAa,QAAQ;CAC9B;AAGD,MAAM,EAAE,kBAAkB,gBAAgB,iBACzCC,WAAe;AAEhB,MAAa,WAA+B,EAC3C,eAAe;CACd,GAAGA,WAAe;CAClB;CACA;CACA;CACA,EACD"}
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,kBACR,MACA,SACA,cACgB;AAChB,QAAO;EACN,GAAG;EACH,SAAS,QAAQ,QAAQ,QAAQ,WAAW;AAC3C,OAAI,CAAC,eAAe,OAAO,CAC1B,QAAO;GAGR,MAAM,SAAS,OAAO,QAAQ;AAC9B,UAAO,EAAE,UAAU,OAAO,UAAU;IACnC;EACF;;AAGF,MAAa,UAA6B;CACzC,QAAQ,aAAa,OAAO;CAC5B,kBAAkB,aAAa,iBAAiB;CAChD,SAAS,aAAa,QAAQ;CAC9B;AAGD,MAAM,EAAE,kBAAkB,gBAAgB,iBACzCC,WAAe;AAEhB,MAAa,WAA+B,EAC3C,eAAe;CACd,GAAGA,WAAe;CAClB;CACA;CACA;CACA,EACD"}
package/package.json CHANGED
@@ -1,68 +1,62 @@
1
1
  {
2
- "name": "prettier-plugin-expand-json",
3
- "version": "1.0.2",
4
- "description": "Expand JSON arrays and objects into multi-line notation 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
- "packageManager": "pnpm@10.28.1",
33
- "dependencies": {
34
- "jsonc-parser": "^3.3.1"
35
- },
36
- "peerDependencies": {
37
- "prettier": ">=3"
38
- },
39
- "devDependencies": {
40
- "@standard-config/eslint": "1.0.0",
41
- "@standard-config/prettier": "1.5.0",
42
- "@standard-config/tsconfig": "2.0.0",
43
- "@vitest/coverage-v8": "4.0.18",
44
- "eslint": "9.39.2",
45
- "husky": "9.1.7",
46
- "jiti": "2.6.1",
47
- "oxlint": "1.41.0",
48
- "oxlint-tsgolint": "0.11.1",
49
- "prettier": "3.8.1",
50
- "prettier-plugin-sort-json": "4.2.0",
51
- "publint": "0.3.17",
52
- "tsdown": "0.20.1",
53
- "typescript": "5.9.3",
54
- "vitest": "4.0.18"
55
- },
56
- "scripts": {
57
- "build": "tsdown",
58
- "fix": "pnpm format && pnpm lint",
59
- "format": "prettier --write --ignore-unknown .",
60
- "format:check": "prettier --check --ignore-unknown .",
61
- "lint": "oxlint --fix --type-aware --type-check --deny-warnings --report-unused-disable-directives && eslint . --fix",
62
- "lint:check": "oxlint --type-aware --type-check --deny-warnings --report-unused-disable-directives && eslint .",
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
+ }