prettier 2.7.1 → 3.0.1

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.
Files changed (82) hide show
  1. package/LICENSE +1054 -1906
  2. package/README.md +5 -5
  3. package/{bin-prettier.js → bin/prettier.cjs} +10 -5
  4. package/doc.d.ts +240 -0
  5. package/doc.js +1257 -1309
  6. package/doc.mjs +1312 -0
  7. package/index.cjs +655 -0
  8. package/index.d.ts +921 -0
  9. package/index.mjs +21484 -0
  10. package/internal/cli.mjs +6982 -0
  11. package/internal/internal.mjs +6531 -0
  12. package/package.json +179 -6
  13. package/plugins/acorn.d.ts +6 -0
  14. package/plugins/acorn.js +13 -0
  15. package/plugins/acorn.mjs +13 -0
  16. package/plugins/angular.d.ts +8 -0
  17. package/plugins/angular.js +2 -0
  18. package/plugins/angular.mjs +2 -0
  19. package/plugins/babel.d.ts +17 -0
  20. package/plugins/babel.js +16 -0
  21. package/plugins/babel.mjs +16 -0
  22. package/plugins/estree.d.ts +1 -0
  23. package/plugins/estree.js +35 -0
  24. package/plugins/estree.mjs +35 -0
  25. package/plugins/flow.d.ts +5 -0
  26. package/plugins/flow.js +21 -0
  27. package/plugins/flow.mjs +21 -0
  28. package/plugins/glimmer.d.ts +5 -0
  29. package/plugins/glimmer.js +30 -0
  30. package/plugins/glimmer.mjs +30 -0
  31. package/plugins/graphql.d.ts +5 -0
  32. package/plugins/graphql.js +29 -0
  33. package/plugins/graphql.mjs +29 -0
  34. package/plugins/html.d.ts +8 -0
  35. package/plugins/html.js +19 -0
  36. package/plugins/html.mjs +19 -0
  37. package/plugins/markdown.d.ts +7 -0
  38. package/plugins/markdown.js +59 -0
  39. package/plugins/markdown.mjs +59 -0
  40. package/plugins/meriyah.d.ts +5 -0
  41. package/plugins/meriyah.js +5 -0
  42. package/plugins/meriyah.mjs +5 -0
  43. package/plugins/postcss.d.ts +7 -0
  44. package/plugins/postcss.js +52 -0
  45. package/plugins/postcss.mjs +52 -0
  46. package/plugins/typescript.d.ts +5 -0
  47. package/plugins/typescript.js +25 -0
  48. package/plugins/typescript.mjs +25 -0
  49. package/plugins/yaml.d.ts +5 -0
  50. package/plugins/yaml.js +161 -0
  51. package/plugins/yaml.mjs +161 -0
  52. package/standalone.d.ts +33 -0
  53. package/standalone.js +36 -115
  54. package/standalone.mjs +37 -0
  55. package/cli.js +0 -15085
  56. package/esm/parser-angular.mjs +0 -2
  57. package/esm/parser-babel.mjs +0 -27
  58. package/esm/parser-espree.mjs +0 -26
  59. package/esm/parser-flow.mjs +0 -35
  60. package/esm/parser-glimmer.mjs +0 -27
  61. package/esm/parser-graphql.mjs +0 -15
  62. package/esm/parser-html.mjs +0 -36
  63. package/esm/parser-markdown.mjs +0 -76
  64. package/esm/parser-meriyah.mjs +0 -19
  65. package/esm/parser-postcss.mjs +0 -76
  66. package/esm/parser-typescript.mjs +0 -280
  67. package/esm/parser-yaml.mjs +0 -150
  68. package/esm/standalone.mjs +0 -116
  69. package/index.js +0 -37282
  70. package/parser-angular.js +0 -2
  71. package/parser-babel.js +0 -27
  72. package/parser-espree.js +0 -26
  73. package/parser-flow.js +0 -35
  74. package/parser-glimmer.js +0 -27
  75. package/parser-graphql.js +0 -15
  76. package/parser-html.js +0 -36
  77. package/parser-markdown.js +0 -76
  78. package/parser-meriyah.js +0 -19
  79. package/parser-postcss.js +0 -76
  80. package/parser-typescript.js +0 -280
  81. package/parser-yaml.js +0 -150
  82. package/third-party.js +0 -8978
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![Prettier Banner](https://unpkg.com/prettier-logo@1.0.3/images/prettier-banner-light.svg)
1
+ [![Prettier Banner](https://unpkg.com/prettier-logo@1.0.3/images/prettier-banner-light.svg)](https://prettier.io)
2
2
 
3
3
  <h2 align="center">Opinionated Code Formatter</h2>
4
4
 
@@ -38,11 +38,11 @@
38
38
 
39
39
  <p align="center">
40
40
  <a href="https://github.com/prettier/prettier/actions?query=workflow%3AProd+branch%3Amain">
41
- <img alt="Github Actions Build Status" src="https://img.shields.io/github/workflow/status/prettier/prettier/Prod?label=Prod&style=flat-square"></a>
41
+ <img alt="Github Actions Build Status" src="https://img.shields.io/github/actions/workflow/status/prettier/prettier/prod-test.yml?label=Prod&style=flat-square"></a>
42
42
  <a href="https://github.com/prettier/prettier/actions?query=workflow%3ADev+branch%3Amain">
43
- <img alt="Github Actions Build Status" src="https://img.shields.io/github/workflow/status/prettier/prettier/Dev?label=Dev&style=flat-square"></a>
43
+ <img alt="Github Actions Build Status" src="https://img.shields.io/github/actions/workflow/status/prettier/prettier/dev-test.yml?label=Dev&style=flat-square"></a>
44
44
  <a href="https://github.com/prettier/prettier/actions?query=workflow%3ALint+branch%3Amain">
45
- <img alt="Github Actions Build Status" src="https://img.shields.io/github/workflow/status/prettier/prettier/Lint?label=Lint&style=flat-square"></a>
45
+ <img alt="Github Actions Build Status" src="https://img.shields.io/github/actions/workflow/status/prettier/prettier/lint.yml?label=Lint&style=flat-square"></a>
46
46
  <a href="https://codecov.io/gh/prettier/prettier">
47
47
  <img alt="Codecov Coverage Status" src="https://img.shields.io/codecov/c/github/prettier/prettier.svg?style=flat-square"></a>
48
48
  <a href="https://twitter.com/acdlite/status/974390255393505280">
@@ -76,7 +76,7 @@ foo(
76
76
  reallyLongArg(),
77
77
  omgSoManyParameters(),
78
78
  IShouldRefactorThis(),
79
- isThereSeriouslyAnotherOne()
79
+ isThereSeriouslyAnotherOne(),
80
80
  );
81
81
  ```
82
82
 
@@ -42,7 +42,9 @@ var require_please_upgrade_node = __commonJS({
42
42
  if (opts.message) {
43
43
  console.error(opts.message(requiredVersion));
44
44
  } else {
45
- console.error(pkg.name + " requires at least version " + requiredVersion + " of Node, please upgrade");
45
+ console.error(
46
+ pkg.name + " requires at least version " + requiredVersion + " of Node, please upgrade"
47
+ );
46
48
  }
47
49
  if (opts.hasOwnProperty("exitCode")) {
48
50
  process.exit(opts.exitCode);
@@ -54,9 +56,12 @@ var require_please_upgrade_node = __commonJS({
54
56
  }
55
57
  });
56
58
 
57
- // bin/prettier.js
59
+ // bin/prettier.cjs
58
60
  var pleaseUpgradeNode = require_please_upgrade_node();
59
- var packageJson = require("./package.json");
61
+ var packageJson = require("../package.json");
60
62
  pleaseUpgradeNode(packageJson);
61
- var cli = require("./cli.js");
62
- module.exports = cli.run(process.argv.slice(2));
63
+ function runCli(cli) {
64
+ return cli.run(process.argv.slice(2));
65
+ }
66
+ var dynamicImport = new Function("module", "return import(module)");
67
+ module.exports.promise = dynamicImport("../internal/cli.mjs").then(runCli);
package/doc.d.ts ADDED
@@ -0,0 +1,240 @@
1
+ // https://github.com/prettier/prettier/blob/next/src/document/public.js
2
+ export namespace builders {
3
+ type DocCommand =
4
+ | Align
5
+ | BreakParent
6
+ | Cursor
7
+ | Fill
8
+ | Group
9
+ | IfBreak
10
+ | Indent
11
+ | IndentIfBreak
12
+ | Label
13
+ | Line
14
+ | LineSuffix
15
+ | LineSuffixBoundary
16
+ | Trim;
17
+ type Doc = string | Doc[] | DocCommand;
18
+
19
+ interface Align {
20
+ type: "align";
21
+ contents: Doc;
22
+ n: number | string | { type: "root" };
23
+ }
24
+
25
+ interface BreakParent {
26
+ type: "break-parent";
27
+ }
28
+
29
+ interface Cursor {
30
+ type: "cursor";
31
+ placeholder: symbol;
32
+ }
33
+
34
+ interface Fill {
35
+ type: "fill";
36
+ parts: Doc[];
37
+ }
38
+
39
+ interface Group {
40
+ type: "group";
41
+ contents: Doc;
42
+ break: boolean;
43
+ expandedStates: Doc[];
44
+ }
45
+
46
+ interface HardlineWithoutBreakParent extends Line {
47
+ hard: true;
48
+ }
49
+
50
+ interface IfBreak {
51
+ type: "if-break";
52
+ breakContents: Doc;
53
+ flatContents: Doc;
54
+ }
55
+
56
+ interface Indent {
57
+ type: "indent";
58
+ contents: Doc;
59
+ }
60
+
61
+ interface IndentIfBreak {
62
+ type: "indent-if-break";
63
+ }
64
+
65
+ interface Label {
66
+ type: "label";
67
+ }
68
+
69
+ interface Line {
70
+ type: "line";
71
+ soft?: boolean | undefined;
72
+ hard?: boolean | undefined;
73
+ literal?: boolean | undefined;
74
+ }
75
+
76
+ interface LineSuffix {
77
+ type: "line-suffix";
78
+ contents: Doc;
79
+ }
80
+
81
+ interface LineSuffixBoundary {
82
+ type: "line-suffix-boundary";
83
+ }
84
+
85
+ interface LiterallineWithoutBreakParent extends Line {
86
+ hard: true;
87
+ literal: true;
88
+ }
89
+
90
+ type LiteralLine = [LiterallineWithoutBreakParent, BreakParent];
91
+
92
+ interface Softline extends Line {
93
+ soft: true;
94
+ }
95
+
96
+ type Hardline = [HardlineWithoutBreakParent, BreakParent];
97
+
98
+ interface Trim {
99
+ type: "trim";
100
+ }
101
+
102
+ interface GroupOptions {
103
+ shouldBreak?: boolean | undefined;
104
+ id?: symbol | undefined;
105
+ }
106
+
107
+ function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
108
+
109
+ /** @see [align](https://github.com/prettier/prettier/blob/main/commands.md#align) */
110
+ function align(widthOrString: Align["n"], doc: Doc): Align;
111
+
112
+ /** @see [breakParent](https://github.com/prettier/prettier/blob/main/commands.md#breakparent) */
113
+ const breakParent: BreakParent;
114
+
115
+ /** @see [conditionalGroup](https://github.com/prettier/prettier/blob/main/commands.md#conditionalgroup) */
116
+ function conditionalGroup(alternatives: Doc[], options?: GroupOptions): Group;
117
+
118
+ /** @see [dedent](https://github.com/prettier/prettier/blob/main/commands.md#dedent) */
119
+ function dedent(doc: Doc): Align;
120
+
121
+ /** @see [dedentToRoot](https://github.com/prettier/prettier/blob/main/commands.md#dedenttoroot) */
122
+ function dedentToRoot(doc: Doc): Align;
123
+
124
+ /** @see [fill](https://github.com/prettier/prettier/blob/main/commands.md#fill) */
125
+ function fill(docs: Doc[]): Fill;
126
+
127
+ /** @see [group](https://github.com/prettier/prettier/blob/main/commands.md#group) */
128
+ function group(doc: Doc, opts?: GroupOptions): Group;
129
+
130
+ /** @see [hardline](https://github.com/prettier/prettier/blob/main/commands.md#hardline) */
131
+ const hardline: Hardline;
132
+
133
+ /** @see [hardlineWithoutBreakParent](https://github.com/prettier/prettier/blob/main/commands.md#hardlinewithoutbreakparent-and-literallinewithoutbreakparent) */
134
+ const hardlineWithoutBreakParent: HardlineWithoutBreakParent;
135
+
136
+ /** @see [ifBreak](https://github.com/prettier/prettier/blob/main/commands.md#ifbreak) */
137
+ function ifBreak(
138
+ ifBreak: Doc,
139
+ noBreak?: Doc,
140
+ options?: { groupId?: symbol | undefined },
141
+ ): IfBreak;
142
+
143
+ /** @see [indent](https://github.com/prettier/prettier/blob/main/commands.md#indent) */
144
+ function indent(doc: Doc): Indent;
145
+
146
+ /** @see [indentIfBreak](https://github.com/prettier/prettier/blob/main/commands.md#indentifbreak) */
147
+ function indentIfBreak(
148
+ doc: Doc,
149
+ opts: { groupId: symbol; negate?: boolean | undefined },
150
+ ): IndentIfBreak;
151
+
152
+ /** @see [join](https://github.com/prettier/prettier/blob/main/commands.md#join) */
153
+ function join(sep: Doc, docs: Doc[]): Doc[];
154
+
155
+ /** @see [label](https://github.com/prettier/prettier/blob/main/commands.md#label) */
156
+ function label(label: any | undefined, contents: Doc): Doc;
157
+
158
+ /** @see [line](https://github.com/prettier/prettier/blob/main/commands.md#line) */
159
+ const line: Line;
160
+
161
+ /** @see [lineSuffix](https://github.com/prettier/prettier/blob/main/commands.md#linesuffix) */
162
+ function lineSuffix(suffix: Doc): LineSuffix;
163
+
164
+ /** @see [lineSuffixBoundary](https://github.com/prettier/prettier/blob/main/commands.md#linesuffixboundary) */
165
+ const lineSuffixBoundary: LineSuffixBoundary;
166
+
167
+ /** @see [literalline](https://github.com/prettier/prettier/blob/main/commands.md#literalline) */
168
+ const literalline: LiteralLine;
169
+
170
+ /** @see [literallineWithoutBreakParent](https://github.com/prettier/prettier/blob/main/commands.md#hardlinewithoutbreakparent-and-literallinewithoutbreakparent) */
171
+ const literallineWithoutBreakParent: LiterallineWithoutBreakParent;
172
+
173
+ /** @see [markAsRoot](https://github.com/prettier/prettier/blob/main/commands.md#markasroot) */
174
+ function markAsRoot(doc: Doc): Align;
175
+
176
+ /** @see [softline](https://github.com/prettier/prettier/blob/main/commands.md#softline) */
177
+ const softline: Softline;
178
+
179
+ /** @see [trim](https://github.com/prettier/prettier/blob/main/commands.md#trim) */
180
+ const trim: Trim;
181
+
182
+ /** @see [cursor](https://github.com/prettier/prettier/blob/main/commands.md#cursor) */
183
+ const cursor: Cursor;
184
+ }
185
+
186
+ export namespace printer {
187
+ function printDocToString(
188
+ doc: builders.Doc,
189
+ options: Options,
190
+ ): {
191
+ formatted: string;
192
+ cursorNodeStart?: number | undefined;
193
+ cursorNodeText?: string | undefined;
194
+ };
195
+ interface Options {
196
+ /**
197
+ * Specify the line length that the printer will wrap on.
198
+ * @default 80
199
+ */
200
+ printWidth: number;
201
+ /**
202
+ * Specify the number of spaces per indentation-level.
203
+ * @default 2
204
+ */
205
+ tabWidth: number;
206
+ /**
207
+ * Indent lines with tabs instead of spaces
208
+ * @default false
209
+ */
210
+ useTabs?: boolean;
211
+ parentParser?: string | undefined;
212
+ __embeddedInHtml?: boolean | undefined;
213
+ }
214
+ }
215
+
216
+ export namespace utils {
217
+ function willBreak(doc: builders.Doc): boolean;
218
+ function traverseDoc(
219
+ doc: builders.Doc,
220
+ onEnter?: (doc: builders.Doc) => void | boolean,
221
+ onExit?: (doc: builders.Doc) => void,
222
+ shouldTraverseConditionalGroups?: boolean,
223
+ ): void;
224
+ function findInDoc<T = builders.Doc>(
225
+ doc: builders.Doc,
226
+ callback: (doc: builders.Doc) => T,
227
+ defaultValue: T,
228
+ ): T;
229
+ function mapDoc<T = builders.Doc>(
230
+ doc: builders.Doc,
231
+ callback: (doc: builders.Doc) => T,
232
+ ): T;
233
+ function removeLines(doc: builders.Doc): builders.Doc;
234
+ function stripTrailingHardline(doc: builders.Doc): builders.Doc;
235
+ function replaceEndOfLine(
236
+ doc: builders.Doc,
237
+ replacement?: builders.Doc,
238
+ ): builders.Doc;
239
+ function canBreak(doc: builders.Doc): boolean;
240
+ }