prettier-plugin-wolfram 0.7.9 → 0.7.10

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
@@ -129,6 +129,7 @@ Typical `.prettierrc` example:
129
129
  "alignRuleValues": false,
130
130
  "documentationCommentColumn": 0,
131
131
  "documentationCommentPadding": 2,
132
+ "documentationCommentMarkers": false,
132
133
  "topLevelSpacingMode": "declarations",
133
134
  "preserveTildeInfixFunctions": "",
134
135
  "moduleVarsBreakThreshold": 40,
@@ -158,6 +159,7 @@ this plugin.
158
159
  | `wolfram.alignRuleValues` | boolean | `false` | Vertically aligns `Rule` and `RuleDelayed` values in multiline argument, list, and association layouts. |
159
160
  | `wolfram.documentationCommentColumn` | integer | `0` | Column for trailing documentation comments. `0` computes a column per contiguous block. |
160
161
  | `wolfram.documentationCommentPadding` | integer | `2` | Minimum spaces between code and an aligned trailing documentation comment when the column is computed automatically. |
162
+ | `wolfram.documentationCommentMarkers` | boolean | `false` | Treats trailing comments beginning with `<` as documentation comments aligned at `printWidth`. |
161
163
  | `wolfram.topLevelSpacingMode` | string | `"declarations"` | Top-level blank-line policy. Allowed values are `declarations`, `all`, and `none`. |
162
164
  | `wolfram.preserveTildeInfixFunctions` | string | `""` | Comma-separated function names that stay in `x ~ f ~ y` form instead of normalizing to `f[x, y]`. |
163
165
  | `wolfram.moduleVarsBreakThreshold` | integer | `40` | Character count at which block-structure variable lists break across lines. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-wolfram",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "description": "Prettier plugin for Wolfram Language using tree-sitter",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/options.js CHANGED
@@ -109,6 +109,13 @@ export const wolframOptions = {
109
109
  description:
110
110
  "Minimum spaces between code and an aligned trailing documentation comment in auto mode.",
111
111
  },
112
+ documentationCommentMarkers: {
113
+ type: "boolean",
114
+ default: false,
115
+ legacyName: "wolframDocumentationCommentMarkers",
116
+ description:
117
+ "Treat trailing comments beginning with < as documentation comments aligned at printWidth.",
118
+ },
112
119
  topLevelSpacingMode: {
113
120
  type: "string",
114
121
  default: "declarations",
@@ -19,7 +19,15 @@ export function isDocumentationCommentMarkerText(text) {
19
19
  return /^\(\*\s*</u.test(String(text ?? ""));
20
20
  }
21
21
 
22
- export function hasDocumentationCommentMarker(comment) {
22
+ function documentationCommentMarkersEnabled(options) {
23
+ return (
24
+ normalizeWolframOptions(options).wolframDocumentationCommentMarkers ===
25
+ true
26
+ );
27
+ }
28
+
29
+ export function hasDocumentationCommentMarker(comment, options) {
30
+ if (!documentationCommentMarkersEnabled(options)) return false;
23
31
  const node = comment?.node ?? comment;
24
32
  return (
25
33
  node?.kind === "Token`Comment" &&
@@ -27,6 +35,12 @@ export function hasDocumentationCommentMarker(comment) {
27
35
  );
28
36
  }
29
37
 
38
+ function hasMarkedDocumentationCommentEntry(entry, options) {
39
+ return (entry?.trailingComments ?? []).some((comment) =>
40
+ hasDocumentationCommentMarker(comment, options),
41
+ );
42
+ }
43
+
30
44
  function normalizeDocumentationCommentMarker(text) {
31
45
  return String(text).replace(/^\(\*\s*<\s*/u, "(* < ");
32
46
  }
@@ -34,6 +48,7 @@ function normalizeDocumentationCommentMarker(text) {
34
48
  function normalizedCommentDoc(comment, options) {
35
49
  const rendered = renderFlatDoc(comment.doc, options);
36
50
  if (
51
+ !documentationCommentMarkersEnabled(options) ||
37
52
  !isDocumentationCommentMarkerText(rendered) ||
38
53
  rendered.includes("\n")
39
54
  ) {
@@ -80,6 +95,13 @@ export function documentationCommentColumn(
80
95
  options = normalizeWolframOptions(options);
81
96
  const manual = options.wolframDocumentationCommentColumn ?? 0;
82
97
  if (manual > 0) return manual;
98
+ if (
99
+ entries.some((entry) =>
100
+ hasMarkedDocumentationCommentEntry(entry, options),
101
+ )
102
+ ) {
103
+ return options.printWidth ?? 80;
104
+ }
83
105
  const padding = Math.max(
84
106
  1,
85
107
  options.wolframDocumentationCommentPadding ?? 2,
@@ -192,7 +192,9 @@ export function printInfix(node, options, print) {
192
192
  (entry) => entry.trailingCommentDoc,
193
193
  );
194
194
  const hasMarkedDocumentationComment = trailingEntries.some((entry) =>
195
- entry.trailingComments.some(hasDocumentationCommentMarker),
195
+ entry.trailingComments.some((comment) =>
196
+ hasDocumentationCommentMarker(comment, options),
197
+ ),
196
198
  );
197
199
  const alignTrailingComments =
198
200
  (options.wolframDocumentationCommentColumn ?? 0) > 0 ||