@aforemendude/prettier-plugin-wrap-comments 1.0.6 → 1.1.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.
- package/LICENSE +21 -0
- package/README.md +24 -6
- package/dist/comments/comment-body.d.ts +4 -0
- package/dist/comments/comment-body.js +36 -0
- package/dist/comments/comment-directives.d.ts +2 -0
- package/dist/comments/comment-directives.js +48 -0
- package/dist/comments/comment-eligibility.d.ts +4 -0
- package/dist/comments/comment-eligibility.js +20 -0
- package/dist/comments/comment-location.d.ts +9 -0
- package/dist/comments/comment-location.js +21 -0
- package/dist/comments/comment-ranges.d.ts +24 -0
- package/dist/comments/comment-ranges.js +36 -0
- package/dist/comments/embedded-expression-ranges.d.ts +13 -0
- package/dist/comments/embedded-expression-ranges.js +105 -0
- package/dist/comments/jsx-expression-layout.d.ts +10 -0
- package/dist/comments/jsx-expression-layout.js +117 -0
- package/dist/comments/line-comment-groups.d.ts +6 -0
- package/dist/comments/line-comment-groups.js +28 -0
- package/dist/comments/prettier-ignore.d.ts +8 -0
- package/dist/comments/prettier-ignore.js +145 -0
- package/dist/comments/printer-layout.d.ts +17 -0
- package/dist/comments/printer-layout.js +64 -0
- package/dist/comments/{block.d.ts → wrap-block-comment.d.ts} +4 -1
- package/dist/comments/{block.js → wrap-block-comment.js} +15 -14
- package/dist/comments/wrap-comments.d.ts +9 -0
- package/dist/comments/wrap-comments.js +101 -0
- package/dist/comments/wrap-line-comment-group.d.ts +4 -0
- package/dist/comments/wrap-line-comment-group.js +39 -0
- package/dist/comments/wrap-trailing-line-comment.d.ts +9 -0
- package/dist/comments/wrap-trailing-line-comment.js +78 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/plugin/create-parsers.d.ts +2 -0
- package/dist/plugin/create-parsers.js +57 -0
- package/dist/plugin/create-printers.d.ts +2 -0
- package/dist/plugin/{printers.js → create-printers.js} +9 -10
- package/dist/plugin/get-printer-layout-source.d.ts +4 -0
- package/dist/plugin/get-printer-layout-source.js +27 -0
- package/dist/plugin/jsx-comment-rewrite-metadata.d.ts +8 -0
- package/dist/plugin/jsx-comment-rewrite-metadata.js +40 -0
- package/dist/plugin/parser-names.d.ts +2 -0
- package/dist/plugin/parser-names.js +1 -0
- package/dist/utils/ast.d.ts +6 -0
- package/dist/utils/ast.js +52 -0
- package/dist/utils/display-width.d.ts +2 -0
- package/dist/utils/display-width.js +19 -0
- package/dist/{shared/markdown.d.ts → utils/format-markdown.d.ts} +1 -1
- package/dist/{shared/markdown.js → utils/format-markdown.js} +12 -2
- package/dist/utils/indentation.d.ts +4 -0
- package/dist/utils/indentation.js +21 -0
- package/dist/utils/replacements.d.ts +6 -0
- package/dist/utils/replacements.js +21 -0
- package/dist/utils/source-lines.d.ts +6 -0
- package/dist/utils/source-lines.js +40 -0
- package/dist/utils/type-guards.d.ts +2 -0
- package/dist/utils/type-guards.js +6 -0
- package/dist/utils/whitespace.d.ts +2 -0
- package/dist/utils/whitespace.js +22 -0
- package/dist/{shared/options.d.ts → utils/wrap-options.d.ts} +2 -1
- package/package.json +17 -9
- package/dist/comments/core.d.ts +0 -8
- package/dist/comments/core.js +0 -114
- package/dist/comments/line.d.ts +0 -6
- package/dist/comments/line.js +0 -108
- package/dist/comments/wrap.d.ts +0 -3
- package/dist/comments/wrap.js +0 -439
- package/dist/plugin/parsers.d.ts +0 -2
- package/dist/plugin/parsers.js +0 -35
- package/dist/plugin/printers.d.ts +0 -2
- package/dist/shared/text.d.ts +0 -15
- package/dist/shared/text.js +0 -99
- package/dist/shared/types.d.ts +0 -30
- package/dist/shared/types.js +0 -1
- /package/dist/{shared/options.js → utils/wrap-options.js} +0 -0
package/dist/shared/text.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { getTabWidth } from './options.js';
|
|
2
|
-
export function applyReplacements(text, replacements) {
|
|
3
|
-
let result = text;
|
|
4
|
-
for (const replacement of getNonOverlappingReplacements(replacements).sort((left, right) => right.start - left.start)) {
|
|
5
|
-
result = result.slice(0, replacement.start) + replacement.text + result.slice(replacement.end);
|
|
6
|
-
}
|
|
7
|
-
return result;
|
|
8
|
-
}
|
|
9
|
-
function getNonOverlappingReplacements(replacements) {
|
|
10
|
-
return [...replacements]
|
|
11
|
-
.sort((left, right) => left.start - right.start || right.end - left.end)
|
|
12
|
-
.reduce((accepted, replacement) => {
|
|
13
|
-
const previous = accepted.at(-1);
|
|
14
|
-
if (previous === undefined || !rangesOverlap(previous, replacement)) {
|
|
15
|
-
accepted.push(replacement);
|
|
16
|
-
return accepted;
|
|
17
|
-
}
|
|
18
|
-
return accepted;
|
|
19
|
-
}, []);
|
|
20
|
-
}
|
|
21
|
-
function rangesOverlap(left, right) {
|
|
22
|
-
return left.start < right.end && right.start < left.end;
|
|
23
|
-
}
|
|
24
|
-
export function getPreferredNewline(text, options) {
|
|
25
|
-
if (options.endOfLine === 'crlf') {
|
|
26
|
-
return '\r\n';
|
|
27
|
-
}
|
|
28
|
-
if (options.endOfLine === 'cr') {
|
|
29
|
-
return '\r';
|
|
30
|
-
}
|
|
31
|
-
if (options.endOfLine === 'auto') {
|
|
32
|
-
const match = /\r\n|\n|\r/u.exec(text);
|
|
33
|
-
return match?.[0] ?? '\n';
|
|
34
|
-
}
|
|
35
|
-
return '\n';
|
|
36
|
-
}
|
|
37
|
-
export function getContinuationIndent(text, commentStart, markerColumn, options) {
|
|
38
|
-
const linePrefix = getLinePrefix(text, commentStart);
|
|
39
|
-
if (/^[ \t]*$/u.test(linePrefix)) {
|
|
40
|
-
return linePrefix;
|
|
41
|
-
}
|
|
42
|
-
return makeIndent(markerColumn, options);
|
|
43
|
-
}
|
|
44
|
-
export function getLinePrefix(text, index) {
|
|
45
|
-
return text.slice(getLineStart(text, index), index);
|
|
46
|
-
}
|
|
47
|
-
export function getLineStart(text, index) {
|
|
48
|
-
const newlineIndex = text.lastIndexOf('\n', index - 1);
|
|
49
|
-
return newlineIndex === -1 ? 0 : newlineIndex + 1;
|
|
50
|
-
}
|
|
51
|
-
export function getLineEnd(text, index) {
|
|
52
|
-
const newlineIndex = text.indexOf('\n', index);
|
|
53
|
-
if (newlineIndex === -1) {
|
|
54
|
-
return text.length;
|
|
55
|
-
}
|
|
56
|
-
return text[newlineIndex - 1] === '\r' ? newlineIndex - 1 : newlineIndex;
|
|
57
|
-
}
|
|
58
|
-
export function getColumnAt(text, index, tabWidth) {
|
|
59
|
-
return getColumns(text.slice(getLineStart(text, index), index), tabWidth);
|
|
60
|
-
}
|
|
61
|
-
export function getColumns(text, tabWidth) {
|
|
62
|
-
let column = 0;
|
|
63
|
-
for (const character of text) {
|
|
64
|
-
if (character === '\t') {
|
|
65
|
-
column += tabWidth - (column % tabWidth);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
column += 1;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return column;
|
|
72
|
-
}
|
|
73
|
-
export function isStandaloneBlockComment(text, comment) {
|
|
74
|
-
const before = text.slice(getLineStart(text, comment.start), comment.start);
|
|
75
|
-
const after = text.slice(comment.end, getLineEnd(text, comment.end));
|
|
76
|
-
return /^[ \t]*$/u.test(before) && /^[ \t]*$/u.test(after);
|
|
77
|
-
}
|
|
78
|
-
export function trimBlankEdges(markdown) {
|
|
79
|
-
const lines = markdown.split('\n');
|
|
80
|
-
while (isBlankLine(lines[0])) {
|
|
81
|
-
lines.shift();
|
|
82
|
-
}
|
|
83
|
-
while (isBlankLine(lines.at(-1))) {
|
|
84
|
-
lines.pop();
|
|
85
|
-
}
|
|
86
|
-
return lines.join('\n');
|
|
87
|
-
}
|
|
88
|
-
function isBlankLine(line) {
|
|
89
|
-
return line !== undefined && line.trim() === '';
|
|
90
|
-
}
|
|
91
|
-
export function makeIndent(column, options) {
|
|
92
|
-
const tabWidth = getTabWidth(options);
|
|
93
|
-
if (options.useTabs === true) {
|
|
94
|
-
const tabs = Math.floor(column / tabWidth);
|
|
95
|
-
const spaces = column % tabWidth;
|
|
96
|
-
return `${'\t'.repeat(tabs)}${' '.repeat(spaces)}`;
|
|
97
|
-
}
|
|
98
|
-
return ' '.repeat(column);
|
|
99
|
-
}
|
package/dist/shared/types.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ParserOptions } from 'prettier';
|
|
2
|
-
export type AstWithComments = {
|
|
3
|
-
comments?: unknown;
|
|
4
|
-
program?: {
|
|
5
|
-
comments?: unknown;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export type RawComment = {
|
|
9
|
-
end?: unknown;
|
|
10
|
-
loc?: {
|
|
11
|
-
start?: {
|
|
12
|
-
column?: unknown;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
range?: unknown;
|
|
16
|
-
start?: unknown;
|
|
17
|
-
type?: unknown;
|
|
18
|
-
value?: unknown;
|
|
19
|
-
};
|
|
20
|
-
export type CommentRange = {
|
|
21
|
-
end: number;
|
|
22
|
-
kind: 'block' | 'line';
|
|
23
|
-
start: number;
|
|
24
|
-
};
|
|
25
|
-
export type Replacement = {
|
|
26
|
-
end: number;
|
|
27
|
-
start: number;
|
|
28
|
-
text: string;
|
|
29
|
-
};
|
|
30
|
-
export type WrapOptions = Pick<ParserOptions, 'endOfLine' | 'printWidth' | 'tabWidth' | 'useTabs'>;
|
package/dist/shared/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|