prettier-plugin-multiline-arrays-2 1.0.0

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 (69) hide show
  1. package/LICENSE +3 -0
  2. package/LICENSE-CC0 +121 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +91 -0
  5. package/dist/augments/array.d.ts +3 -0
  6. package/dist/augments/array.js +21 -0
  7. package/dist/augments/array.test.d.ts +1 -0
  8. package/dist/augments/array.test.js +34 -0
  9. package/dist/augments/doc.d.ts +5 -0
  10. package/dist/augments/doc.js +30 -0
  11. package/dist/augments/string.d.ts +1 -0
  12. package/dist/augments/string.js +6 -0
  13. package/dist/index.d.ts +11 -0
  14. package/dist/index.js +46 -0
  15. package/dist/options.d.ts +32 -0
  16. package/dist/options.js +71 -0
  17. package/dist/options.test.d.ts +1 -0
  18. package/dist/options.test.js +48 -0
  19. package/dist/plugin-marker.d.ts +1 -0
  20. package/dist/plugin-marker.js +2 -0
  21. package/dist/preprocessing.d.ts +2 -0
  22. package/dist/preprocessing.js +94 -0
  23. package/dist/printer/child-docs.d.ts +18 -0
  24. package/dist/printer/child-docs.js +89 -0
  25. package/dist/printer/comment-triggers.d.ts +25 -0
  26. package/dist/printer/comment-triggers.js +327 -0
  27. package/dist/printer/comments.d.ts +2 -0
  28. package/dist/printer/comments.js +34 -0
  29. package/dist/printer/insert-new-lines.d.ts +15 -0
  30. package/dist/printer/insert-new-lines.js +580 -0
  31. package/dist/printer/insert-new-lines.test.d.ts +1 -0
  32. package/dist/printer/insert-new-lines.test.js +36 -0
  33. package/dist/printer/leading-new-line.d.ts +7 -0
  34. package/dist/printer/leading-new-line.js +31 -0
  35. package/dist/printer/multiline-array-printer.d.ts +4 -0
  36. package/dist/printer/multiline-array-printer.js +42 -0
  37. package/dist/printer/original-printer.d.ts +3 -0
  38. package/dist/printer/original-printer.js +10 -0
  39. package/dist/printer/supported-node-types.d.ts +9 -0
  40. package/dist/printer/supported-node-types.js +16 -0
  41. package/dist/printer/trailing-comma.d.ts +6 -0
  42. package/dist/printer/trailing-comma.js +28 -0
  43. package/dist/readme-examples/formatted-with-comments.example.d.ts +3 -0
  44. package/dist/readme-examples/formatted-with-comments.example.js +16 -0
  45. package/dist/readme-examples/formatted.example.d.ts +2 -0
  46. package/dist/readme-examples/formatted.example.js +12 -0
  47. package/dist/readme-examples/not-formatted.example.d.ts +2 -0
  48. package/dist/readme-examples/not-formatted.example.js +6 -0
  49. package/dist/readme-examples/prettier-options.example.d.ts +4 -0
  50. package/dist/readme-examples/prettier-options.example.js +5 -0
  51. package/dist/test/babel-ts.test.d.ts +1 -0
  52. package/dist/test/babel-ts.test.js +10 -0
  53. package/dist/test/javascript.test.d.ts +1 -0
  54. package/dist/test/javascript.test.js +702 -0
  55. package/dist/test/json.test.d.ts +1 -0
  56. package/dist/test/json.test.js +403 -0
  57. package/dist/test/json5.test.d.ts +1 -0
  58. package/dist/test/json5.test.js +210 -0
  59. package/dist/test/prettier-config.d.ts +2 -0
  60. package/dist/test/prettier-config.js +12 -0
  61. package/dist/test/prettier-versions.mock.script.d.ts +1 -0
  62. package/dist/test/prettier-versions.mock.script.js +123 -0
  63. package/dist/test/run-tests.mock.d.ts +17 -0
  64. package/dist/test/run-tests.mock.js +95 -0
  65. package/dist/test/typescript-tests.mock.d.ts +2 -0
  66. package/dist/test/typescript-tests.mock.js +1575 -0
  67. package/dist/test/typescript.test.d.ts +1 -0
  68. package/dist/test/typescript.test.js +10 -0
  69. package/package.json +117 -0
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ This package is distributed under either the MIT license or CC0-1.0.
2
+
3
+ See LICENSE-MIT and LICENSE-CC0 for the full license texts.
package/LICENSE-CC0 ADDED
@@ -0,0 +1,121 @@
1
+ CC0 1.0 Universal
2
+
3
+ Creative Commons Legal Code
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 electrovir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # prettier-plugin-multiline-arrays-2
2
+
3
+ [![npm](https://img.shields.io/npm/v/prettier-plugin-multiline-arrays-2.svg)](https://www.npmjs.com/package/prettier-plugin-multiline-arrays-2)
4
+ [![CI](https://github.com/Nick2bad4u/prettier-plugin-multiline-arrays-2/actions/workflows/ci.yml/badge.svg)](https://github.com/Nick2bad4u/prettier-plugin-multiline-arrays-2/actions/workflows/ci.yml)
5
+ [![License: MIT OR CC0-1.0](https://img.shields.io/badge/license-MIT%20OR%20CC0--1.0-blue.svg)](LICENSE-MIT)
6
+
7
+ Prettier plugin to force array elements to wrap onto new lines, even when there is only one element. It supports TypeScript, JavaScript, JSON, and JSON5, with options for wrap thresholds and per-line element patterns.
8
+
9
+ This is a maintained fork of [electrovir/prettier-plugin-multiline-arrays](https://github.com/electrovir/prettier-plugin-multiline-arrays). Credit to the original plugin for the core idea and implementation.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install --save-dev prettier-plugin-multiline-arrays-2
15
+ ```
16
+
17
+ Add the plugin to your Prettier config:
18
+
19
+ ```js
20
+ export default {
21
+ plugins: ["prettier-plugin-multiline-arrays-2"],
22
+ };
23
+ ```
24
+
25
+ When combining this plugin with parser/preprocessor plugins such as `prettier-plugin-organize-imports`, put `prettier-plugin-multiline-arrays-2` last. Prettier 3.9 selects the last plugin-provided parser for a parser name, and this plugin needs its parser wrapper to run so it can delegate to companion preprocessors and then apply multiline array printing.
26
+
27
+ ## Options
28
+
29
+ - `multilineArraysWrapThreshold`: number. Arrays with more elements than this value are forced to wrap. The default is `-1`, which disables automatic threshold wrapping.
30
+ - `multilineArraysLinePattern`: string. Space- or comma-separated list of numbers controlling how many elements appear on each line. The pattern repeats for longer arrays. The default is `"1"`.
31
+
32
+ Example:
33
+
34
+ ```json
35
+ {
36
+ "multilineArraysWrapThreshold": 3,
37
+ "multilineArraysLinePattern": "2 1"
38
+ }
39
+ ```
40
+
41
+ ## Comment Overrides
42
+
43
+ Use comments to override the next array:
44
+
45
+ ```ts
46
+ // prettier-multiline-arrays-next-threshold: 4
47
+ const thresholdArray = ["a", "b", "c", "d", "e"];
48
+
49
+ // prettier-multiline-arrays-next-line-pattern: 2 1
50
+ const patternedArray = ["a", "b", "c", "d", "e"];
51
+ ```
52
+
53
+ Use `set` comments to affect later arrays in a file:
54
+
55
+ ```ts
56
+ // prettier-multiline-arrays-set-threshold: 5
57
+ // prettier-multiline-arrays-set-line-pattern: 2 1 3
58
+ ```
59
+
60
+ Use `prettier-multiline-arrays-reset` to return to the configured defaults.
61
+
62
+ ## Precedence
63
+
64
+ 1. Comment overrides.
65
+ 2. Manual wrapping from leading new lines or trailing commas.
66
+ 3. Prettier options.
67
+ 4. Default behavior.
68
+
69
+ ## Development
70
+
71
+ ```sh
72
+ npm ci
73
+ npm run build
74
+ npm test
75
+ npm run release:check
76
+ ```
77
+
78
+ The test suite runs against Node's built-in test runner through `tsx` and includes a `test:prettier-latest` check to verify compatibility with the current npm `latest` Prettier release.
79
+
80
+ ## Publishing
81
+
82
+ This package is prepared for npm trusted publishing from GitHub Actions. Before the first release, create the package on npm and add a trusted publisher with these values:
83
+
84
+ - Package: `prettier-plugin-multiline-arrays-2`
85
+ - Provider: GitHub Actions
86
+ - Repository owner: `Nick2bad4u`
87
+ - Repository name: `prettier-plugin-multiline-arrays-2`
88
+ - Workflow filename: `npm-release.yml`
89
+ - Environment: leave unset unless you add a matching GitHub environment to the workflow
90
+
91
+ The release workflow uses GitHub OIDC through `id-token: write` and publishes with provenance. It intentionally does not require an npm automation token.
@@ -0,0 +1,3 @@
1
+ import type { SourceLocation } from "estree";
2
+ /** Both line and column in "range" are 0 indexed. */
3
+ export declare function extractTextBetweenRanges(input: string[], range: Omit<SourceLocation, "source">): string;
@@ -0,0 +1,21 @@
1
+ /** Both line and column in "range" are 0 indexed. */
2
+ export function extractTextBetweenRanges(input, range) {
3
+ if (range.start.line > range.end.line) {
4
+ throw new Error(`Start line "${range.start.line}" cannot be greater than end line "${range.end.line}"`);
5
+ }
6
+ else if (range.start.line === range.end.line) {
7
+ if (range.start.column >= range.end.column) {
8
+ throw new Error(`When start and end are on the same line, the start column "${range.start.column}" must be less than the end column "${range.end.column}".`);
9
+ }
10
+ return (input[range.start.line]?.slice(range.start.column + 1, range.end.column) ?? "");
11
+ }
12
+ let extractedText = input[range.start.line]?.slice(range.start.column + 1) ?? "";
13
+ extractedText += "\n";
14
+ for (let lineIndex = range.start.line + 1; lineIndex < range.end.line; lineIndex++) {
15
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
+ extractedText += input[lineIndex];
17
+ extractedText += "\n";
18
+ }
19
+ extractedText += input[range.end.line]?.slice(0, range.end.column) ?? "";
20
+ return extractedText;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { assert } from '@augment-vir/assert';
2
+ import { describe, it } from '@augment-vir/test';
3
+ import { extractTextBetweenRanges } from './array.js';
4
+ describe(extractTextBetweenRanges.name, () => {
5
+ it('extracts text from multiple lines', () => {
6
+ assert.strictEquals(extractTextBetweenRanges([
7
+ 'a b c d e f g h i j k l m n',
8
+ 'o p q r s',
9
+ 't u v w x y',
10
+ 'z',
11
+ ], {
12
+ start: {
13
+ line: 0,
14
+ column: 4,
15
+ },
16
+ end: {
17
+ line: 2,
18
+ column: 3,
19
+ },
20
+ }), ' d e f g h i j k l m n\no p q r s\nt u');
21
+ });
22
+ it('extracts text from the same line', () => {
23
+ assert.strictEquals(extractTextBetweenRanges(['a b c d e f g h i j k l m n'], {
24
+ start: {
25
+ line: 0,
26
+ column: 4,
27
+ },
28
+ end: {
29
+ line: 0,
30
+ column: 7,
31
+ },
32
+ }), ' d');
33
+ });
34
+ });
@@ -0,0 +1,5 @@
1
+ import type { Doc, doc } from "prettier";
2
+ type NestedStringArray = (string | NestedStringArray)[];
3
+ export declare function stringifyDoc(input: Doc | null | undefined, recursive?: boolean): NestedStringArray;
4
+ export declare function isDocCommand(inputDoc: Doc | undefined | null): inputDoc is doc.builders.DocCommand;
5
+ export {};
@@ -0,0 +1,30 @@
1
+ import { stringify } from "@augment-vir/common";
2
+ const childProperties = [
3
+ "breakContents",
4
+ "contents",
5
+ "flatContents",
6
+ "parts",
7
+ ];
8
+ export function stringifyDoc(input, recursive = false) {
9
+ if (typeof input === "string" || !input) {
10
+ return [stringify(input)];
11
+ }
12
+ else if (Array.isArray(input)) {
13
+ return input.map((entry) => stringifyDoc(entry, recursive));
14
+ }
15
+ else if (recursive) {
16
+ const children = childProperties.reduce((accum, currentProperty) => {
17
+ if (currentProperty in input) {
18
+ accum.push(`${currentProperty}:`, stringifyDoc(input[currentProperty], recursive));
19
+ }
20
+ return accum;
21
+ }, []);
22
+ if (children.length) {
23
+ return [`${input.type}:`, stringifyDoc(children, recursive)];
24
+ }
25
+ }
26
+ return [input.type];
27
+ }
28
+ export function isDocCommand(inputDoc) {
29
+ return (!!inputDoc && typeof inputDoc !== "string" && !Array.isArray(inputDoc));
30
+ }
@@ -0,0 +1 @@
1
+ export declare function capitalizeFirst(input: string): string;
@@ -0,0 +1,6 @@
1
+ export function capitalizeFirst(input) {
2
+ if (!input) {
3
+ return input;
4
+ }
5
+ return (input[0] || "").toUpperCase() + input.slice(1);
6
+ }
@@ -0,0 +1,11 @@
1
+ import { type Parser, type RequiredOptions, type SupportOption } from "prettier";
2
+ import { type MultilineArrayOptions } from "./options.js";
3
+ export * from "./options.js";
4
+ export { pluginMarker } from "./plugin-marker.js";
5
+ export declare const parsers: Record<string, Parser>;
6
+ export declare const options: Record<keyof MultilineArrayOptions, SupportOption>;
7
+ export declare const defaultOptions: Partial<RequiredOptions> & Required<MultilineArrayOptions>;
8
+ declare module "prettier" {
9
+ interface Options extends Partial<MultilineArrayOptions> {
10
+ }
11
+ }
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { getObjectTypedKeys, mapObjectValues } from "@augment-vir/common";
2
+ import {} from "prettier";
3
+ import { parsers as babelParsers } from "prettier/plugins/babel";
4
+ import { parsers as tsParsers } from "prettier/plugins/typescript";
5
+ import { defaultMultilineArrayOptions, optionHelp, } from "./options.js";
6
+ import { wrapParser } from "./preprocessing.js";
7
+ import { multilineArrayPrinter } from "./printer/multiline-array-printer.js";
8
+ // exports in case others want to utilize these
9
+ export * from "./options.js";
10
+ export { pluginMarker } from "./plugin-marker.js";
11
+ export const parsers = mapObjectValues({
12
+ typescript: tsParsers.typescript,
13
+ babel: babelParsers.babel,
14
+ "babel-ts": babelParsers["babel-ts"],
15
+ json: babelParsers.json,
16
+ json5: babelParsers.json5,
17
+ }, (languageName, parserEntry) => {
18
+ return wrapParser(parserEntry, languageName);
19
+ });
20
+ const printers = {
21
+ estree: multilineArrayPrinter,
22
+ "estree-json": multilineArrayPrinter,
23
+ };
24
+ export const options = getObjectTypedKeys(defaultMultilineArrayOptions).reduce((accum, key) => {
25
+ const defaultValue = defaultMultilineArrayOptions[key];
26
+ const supportOption = {
27
+ name: key,
28
+ type: (typeof defaultValue === "number"
29
+ ? "int"
30
+ : typeof defaultValue),
31
+ category: "multilineArray",
32
+ default: defaultValue,
33
+ description: optionHelp[key],
34
+ };
35
+ accum[key] = supportOption;
36
+ return accum;
37
+ }, {});
38
+ export const defaultOptions = defaultMultilineArrayOptions;
39
+ /** Not actually exported: this is just for type checking purposes. */
40
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
41
+ const plugin = {
42
+ options,
43
+ printers,
44
+ defaultOptions,
45
+ parsers,
46
+ };
@@ -0,0 +1,32 @@
1
+ import { type Values } from "@augment-vir/common";
2
+ import type { SupportOptionType as PrettierOptionType } from "prettier";
3
+ export declare const envDebugKey = "MULTILINE_DEBUG";
4
+ export declare const nextLinePatternComment = "prettier-multiline-arrays-next-line-pattern:";
5
+ export declare const untilNextLinePatternCommentRegExp: RegExp;
6
+ export declare const setLinePatternComment = "prettier-multiline-arrays-set-line-pattern:";
7
+ export declare const untilSetLinePatternCommentRegExp: RegExp;
8
+ export declare const nextWrapThresholdComment = "prettier-multiline-arrays-next-threshold:";
9
+ export declare const untilNextWrapThresholdCommentRegExp: RegExp;
10
+ export declare const setWrapThresholdComment = "prettier-multiline-arrays-set-threshold:";
11
+ export declare const untilSetWrapThresholdCommentRegExp: RegExp;
12
+ export declare const resetComment = "prettier-multiline-arrays-reset";
13
+ export type MultilineArrayOptions = {
14
+ /**
15
+ * If there are MORE elements in the array than this, the array will be
16
+ * forced to wrap.
17
+ *
18
+ * This defaults to -1, indicating that no special wrapping enforcement will
19
+ * take place.
20
+ *
21
+ * Set to 2 to only wrap if there are more than 2 element. Etc.
22
+ */
23
+ multilineArraysWrapThreshold: number;
24
+ multilineArraysLinePattern: string;
25
+ };
26
+ export declare const optionHelp: Record<keyof MultilineArrayOptions, string>;
27
+ export declare const optionPropertyValidators: {
28
+ [Property in keyof MultilineArrayOptions]: (input: unknown) => input is MultilineArrayOptions[Property];
29
+ };
30
+ export declare const defaultMultilineArrayOptions: MultilineArrayOptions;
31
+ export declare function getPrettierOptionType(input: Values<MultilineArrayOptions>): PrettierOptionType;
32
+ export declare function fillInOptions<T extends object>(input: T | undefined): MultilineArrayOptions & T;
@@ -0,0 +1,71 @@
1
+ import { getObjectTypedKeys } from "@augment-vir/common";
2
+ export const envDebugKey = "MULTILINE_DEBUG";
3
+ export const nextLinePatternComment = "prettier-multiline-arrays-next-line-pattern:";
4
+ // all the text up until the comment trigger
5
+ export const untilNextLinePatternCommentRegExp = new RegExp(`.*${nextLinePatternComment}`);
6
+ export const setLinePatternComment = "prettier-multiline-arrays-set-line-pattern:";
7
+ // all the text up until the comment trigger
8
+ export const untilSetLinePatternCommentRegExp = new RegExp(`.*${setLinePatternComment}`);
9
+ export const nextWrapThresholdComment = "prettier-multiline-arrays-next-threshold:";
10
+ // all the text up until the comment trigger
11
+ export const untilNextWrapThresholdCommentRegExp = new RegExp(`.*${nextWrapThresholdComment}`);
12
+ export const setWrapThresholdComment = "prettier-multiline-arrays-set-threshold:";
13
+ // all the text up until the comment trigger
14
+ export const untilSetWrapThresholdCommentRegExp = new RegExp(`.*${setWrapThresholdComment}`);
15
+ export const resetComment = "prettier-multiline-arrays-reset";
16
+ export const optionHelp = {
17
+ multilineArraysWrapThreshold: `A number indicating that all arrays should wrap when they have MORE than the specified number. Defaults to -1, indicating that no special wrapping enforcement will take place.\nExample: multilineArraysWrapThreshold: 3\nCan be overridden with a comment starting with ${nextWrapThresholdComment}.\nComment example: // ${nextWrapThresholdComment} 5`,
18
+ multilineArraysLinePattern: `A string with a space separated list of numbers indicating how many elements should be on each line. The pattern repeats if an array is longer than the pattern. Defaults to an empty string. Any invalid numbers causes the whole pattern to revert to the default. This overrides the wrap threshold option.\nExample: elementsPerLinePattern: "3 2 1"\nCan be overridden with a comment starting with ${nextLinePatternComment}.\nComment example: // ${nextLinePatternComment} 3 2 1\nThis option overrides Prettier's default wrapping; multiple elements on one line will not be wrapped even if they don't fit within the column count.`,
19
+ };
20
+ export const optionPropertyValidators = {
21
+ multilineArraysWrapThreshold(input) {
22
+ return typeof input === "number" && !isNaN(input);
23
+ },
24
+ multilineArraysLinePattern(input) {
25
+ if (typeof input !== "string") {
26
+ return false;
27
+ }
28
+ const splitNumbers = input.split(" ");
29
+ return splitNumbers.every((splitNumber) => {
30
+ const numericSplit = Number(splitNumber);
31
+ return !isNaN(numericSplit);
32
+ });
33
+ },
34
+ };
35
+ export const defaultMultilineArrayOptions = {
36
+ multilineArraysWrapThreshold: -1,
37
+ multilineArraysLinePattern: "",
38
+ };
39
+ const optionTypeToPrettierOptionTypeMapping = {
40
+ number: "int",
41
+ boolean: "boolean",
42
+ string: "string",
43
+ };
44
+ export function getPrettierOptionType(input) {
45
+ const mappedType = optionTypeToPrettierOptionTypeMapping[typeof input];
46
+ if (mappedType) {
47
+ return mappedType;
48
+ }
49
+ else {
50
+ throw new Error(`Unmapped option type: '${typeof input}'`);
51
+ }
52
+ }
53
+ export function fillInOptions(input) {
54
+ if (!input || typeof input !== "object") {
55
+ return defaultMultilineArrayOptions;
56
+ }
57
+ const newOptions = {
58
+ ...input,
59
+ };
60
+ getObjectTypedKeys(defaultMultilineArrayOptions).forEach((optionsKey) => {
61
+ const inputValue = input[optionsKey];
62
+ const defaultValue = defaultMultilineArrayOptions[optionsKey];
63
+ if (optionPropertyValidators[optionsKey](inputValue)) {
64
+ newOptions[optionsKey] = inputValue;
65
+ }
66
+ else {
67
+ newOptions[optionsKey] = defaultValue;
68
+ }
69
+ });
70
+ return newOptions;
71
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { describe, itCases } from '@augment-vir/test';
2
+ import { optionPropertyValidators } from './options.js';
3
+ describe('optionPropertyValidators', () => {
4
+ itCases((optionType, input) => {
5
+ return optionPropertyValidators[optionType](input);
6
+ }, [
7
+ {
8
+ it: 'allows -1 for multilineArraysWrapThreshold',
9
+ inputs: [
10
+ 'multilineArraysWrapThreshold',
11
+ -1,
12
+ ],
13
+ expect: true,
14
+ },
15
+ {
16
+ it: 'allows numbers for multilineArraysWrapThreshold',
17
+ inputs: [
18
+ 'multilineArraysWrapThreshold',
19
+ 63,
20
+ ],
21
+ expect: true,
22
+ },
23
+ {
24
+ it: 'rejects strings for multilineArraysWrapThreshold',
25
+ inputs: [
26
+ 'multilineArraysWrapThreshold',
27
+ '63',
28
+ ],
29
+ expect: false,
30
+ },
31
+ {
32
+ it: 'allows numeric strings for multilineArraysLinePattern',
33
+ inputs: [
34
+ 'multilineArraysLinePattern',
35
+ '63',
36
+ ],
37
+ expect: true,
38
+ },
39
+ {
40
+ it: 'rejects non-numeric strings for multilineArraysLinePattern',
41
+ inputs: [
42
+ 'multilineArraysLinePattern',
43
+ '63 keys',
44
+ ],
45
+ expect: false,
46
+ },
47
+ ]);
48
+ });
@@ -0,0 +1 @@
1
+ export declare const pluginMarker: {};
@@ -0,0 +1,2 @@
1
+ // used to find our own plugin
2
+ export const pluginMarker = {};
@@ -0,0 +1,2 @@
1
+ import type { Parser } from "prettier";
2
+ export declare function wrapParser(originalParser: Parser, parserName: string): Parser<any>;