prettier-java-next-line 2.10.4 → 2.11.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/README.md +9 -0
- package/dist/index.cjs +72 -11
- package/dist/index.d.cts +7 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.mjs +72 -11
- package/dist/tree-sitter-java_orchard.wasm +0 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -35,6 +35,15 @@ Set `braceStyle` only when a project needs the inherited same-line style:
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
Set `importOrder` to group imports the way Spotless's `importOrder` step does. Groups separated by `,` get blank lines between them, prefixes joined by `|` share a group, `#` marks a static prefix, and an empty prefix catches everything else. Each import belongs to its longest matching prefix. Module imports (`import module`) always come first in their own group. When `importOrder` is empty, static imports follow them, then all others.
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"plugins": ["prettier-java-next-line"],
|
|
43
|
+
"importOrder": "java,javax,,#java|#javax,#"
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
38
47
|
To use the matching Prettier runtime fork too, install it under the name `prettier` with an npm alias:
|
|
39
48
|
|
|
40
49
|
```bash
|
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,12 @@ var options_default = {
|
|
|
61
61
|
description: "Put opening braces on new lines (Allman style)"
|
|
62
62
|
}],
|
|
63
63
|
description: "Placement of opening braces."
|
|
64
|
+
},
|
|
65
|
+
importOrder: {
|
|
66
|
+
type: "string",
|
|
67
|
+
category: "Java",
|
|
68
|
+
default: "",
|
|
69
|
+
description: "Import groups in Spotless's format, such as `java,javax,,#java|#javax,#`. Module imports always come first. Empty puts static imports next, then all others."
|
|
64
70
|
}
|
|
65
71
|
};
|
|
66
72
|
//#endregion
|
|
@@ -309,6 +315,12 @@ function printAssignment(leftDoc, operator, rightDoc, rightNode) {
|
|
|
309
315
|
indentIfBreak$2(rightDoc, { groupId })
|
|
310
316
|
]);
|
|
311
317
|
}
|
|
318
|
+
function getLanguageByLanguageName(languages, languageName) {
|
|
319
|
+
return languages.find(({ name }) => name.toLowerCase() === languageName) ?? languages.find(({ aliases }) => aliases?.includes(languageName)) ?? languages.find(({ extensions }) => extensions?.includes(`.${languageName}`));
|
|
320
|
+
}
|
|
321
|
+
function inferParser(options, language) {
|
|
322
|
+
return getLanguageByLanguageName(options.plugins?.filter((plugin) => typeof plugin !== "string" && !(plugin instanceof URL)).reverse().flatMap((plugin) => plugin.languages ?? []) ?? [], language)?.parsers[0];
|
|
323
|
+
}
|
|
312
324
|
function printTextBlock(contents) {
|
|
313
325
|
return [
|
|
314
326
|
"\"\"\"",
|
|
@@ -317,13 +329,15 @@ function printTextBlock(contents) {
|
|
|
317
329
|
"\"\"\""
|
|
318
330
|
];
|
|
319
331
|
}
|
|
320
|
-
function embedTextBlock(path) {
|
|
332
|
+
function embedTextBlock(path, options) {
|
|
321
333
|
if (path.node.namedChildren.some(({ type }) => type === "string_interpolation") || path.node.children[0].value === "\"") return null;
|
|
322
334
|
const language = findEmbeddedLanguage(path);
|
|
323
335
|
if (!language) return null;
|
|
336
|
+
const parser = inferParser(options, language);
|
|
337
|
+
if (!parser) return null;
|
|
324
338
|
const text = unescapeTextBlockContents(textBlockContents(path.node));
|
|
325
339
|
return async (textToDoc) => {
|
|
326
|
-
return printTextBlock([escapeDocForTextBlock(await textToDoc(text, { parser
|
|
340
|
+
return printTextBlock([escapeDocForTextBlock(await textToDoc(text, { parser })), hardline$7]);
|
|
327
341
|
};
|
|
328
342
|
}
|
|
329
343
|
function textBlockContents(node) {
|
|
@@ -1176,7 +1190,11 @@ var expressions_default = {
|
|
|
1176
1190
|
}, "children")));
|
|
1177
1191
|
},
|
|
1178
1192
|
unary_expression(path, print) {
|
|
1179
|
-
|
|
1193
|
+
const parts = [path.call(print, "operatorNode")];
|
|
1194
|
+
const operandDoc = path.call(print, "operandNode");
|
|
1195
|
+
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc)));
|
|
1196
|
+
else parts.push(operandDoc);
|
|
1197
|
+
return parts;
|
|
1180
1198
|
},
|
|
1181
1199
|
field_access: printMemberChain,
|
|
1182
1200
|
generic_type(path, print) {
|
|
@@ -1918,11 +1936,11 @@ var names_default = {
|
|
|
1918
1936
|
//#region src/printers/packages-and-modules.ts
|
|
1919
1937
|
const { group: group$1, hardline: hardline$1, indent: indent$1, join: join$1, line: line$2 } = prettier_doc.builders;
|
|
1920
1938
|
var packages_and_modules_default = {
|
|
1921
|
-
program(path, print) {
|
|
1939
|
+
program(path, print, options) {
|
|
1922
1940
|
if (!path.node.namedChildren.length) return [printDanglingComments(path), hardline$1];
|
|
1923
1941
|
const parts = [];
|
|
1924
1942
|
if (path.node.namedChildren[0].type !== "import_declaration") parts.push(path.call(print, "namedChildren", 0));
|
|
1925
|
-
const
|
|
1943
|
+
const moduleImports = [];
|
|
1926
1944
|
const imports = [];
|
|
1927
1945
|
const otherDeclarations = [];
|
|
1928
1946
|
path.each((child) => {
|
|
@@ -1930,13 +1948,15 @@ var packages_and_modules_default = {
|
|
|
1930
1948
|
if (child.node.type === "import_declaration") {
|
|
1931
1949
|
const names = extractNames(child.node.namedChildren[0]);
|
|
1932
1950
|
if (child.node.namedChildren.some(({ type }) => type === "asterisk")) names.push("*");
|
|
1933
|
-
|
|
1951
|
+
const modifier = child.node.children[1].type;
|
|
1952
|
+
(modifier === "module" ? moduleImports : imports).push({
|
|
1934
1953
|
doc,
|
|
1935
|
-
names
|
|
1954
|
+
names,
|
|
1955
|
+
isStatic: modifier === "static"
|
|
1936
1956
|
});
|
|
1937
1957
|
} else if (!child.isFirst) otherDeclarations.push(doc);
|
|
1938
1958
|
}, "namedChildren");
|
|
1939
|
-
parts.push(...[
|
|
1959
|
+
parts.push(...[moduleImports.sort(compareFqn), ...groupImports(imports, options.importOrder)].filter((group) => group.length).map((group) => join$1(hardline$1, group.map(({ doc }) => doc))), ...otherDeclarations);
|
|
1940
1960
|
return [...join$1([hardline$1, hardline$1], parts), hardline$1];
|
|
1941
1961
|
},
|
|
1942
1962
|
package_declaration(path, print) {
|
|
@@ -1960,7 +1980,8 @@ var packages_and_modules_default = {
|
|
|
1960
1980
|
},
|
|
1961
1981
|
import_declaration(path, print) {
|
|
1962
1982
|
const declaration = ["import "];
|
|
1963
|
-
|
|
1983
|
+
const modifier = path.node.children[1].type;
|
|
1984
|
+
if (modifier === "module" || modifier === "static") declaration.push(modifier, " ");
|
|
1964
1985
|
const identifierIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier" || type === "scoped_identifier");
|
|
1965
1986
|
declaration.push(path.call(print, "namedChildren", identifierIndex));
|
|
1966
1987
|
if (path.node.namedChildren.some(({ type }) => type === "asterisk")) declaration.push(".*");
|
|
@@ -2014,6 +2035,46 @@ var packages_and_modules_default = {
|
|
|
2014
2035
|
function extractNames(node) {
|
|
2015
2036
|
return node.type === "identifier" ? [node.value] : [...extractNames(node.scopeNode), node.nameNode.value];
|
|
2016
2037
|
}
|
|
2038
|
+
const STATIC_PREFIX = "static ";
|
|
2039
|
+
const CATCH_ALL_PREFIX = "";
|
|
2040
|
+
function groupImports(imports, importOrder) {
|
|
2041
|
+
if (!importOrder) return [imports.filter(({ isStatic }) => isStatic), imports.filter(({ isStatic }) => !isStatic)].filter((group) => group.length).map((group) => group.sort(compareFqn));
|
|
2042
|
+
const groups = parseImportOrder(importOrder);
|
|
2043
|
+
const prefixes = groups.flat();
|
|
2044
|
+
const importsByPrefix = /* @__PURE__ */ new Map();
|
|
2045
|
+
for (const entry of imports) {
|
|
2046
|
+
const key = importKey(entry);
|
|
2047
|
+
const prefix = prefixes.filter((candidate) => key.startsWith(candidate)).reduce((best, candidate) => candidate.length > best.length ? candidate : best);
|
|
2048
|
+
importsByPrefix.set(prefix, [...importsByPrefix.get(prefix) ?? [], {
|
|
2049
|
+
key,
|
|
2050
|
+
entry
|
|
2051
|
+
}]);
|
|
2052
|
+
}
|
|
2053
|
+
return groups.map((group) => group.flatMap((prefix) => (importsByPrefix.get(prefix) ?? []).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(({ entry }) => entry))).filter((group) => group.length);
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Parses an import order in Spotless's format: groups separated by `,` are
|
|
2057
|
+
* printed with blank lines between them, prefixes joined by `|` share a group,
|
|
2058
|
+
* `#` marks a static prefix, and an empty prefix catches everything else.
|
|
2059
|
+
* Each import belongs to its longest matching prefix.
|
|
2060
|
+
*/
|
|
2061
|
+
function parseImportOrder(importOrder) {
|
|
2062
|
+
const knownPrefixes = /* @__PURE__ */ new Set();
|
|
2063
|
+
const groups = importOrder.split(",").map((group) => group.split("|").map((prefix) => prefix.startsWith("#") ? STATIC_PREFIX + prefix.slice(1) : prefix).filter((prefix) => {
|
|
2064
|
+
if (knownPrefixes.has(prefix)) return false;
|
|
2065
|
+
knownPrefixes.add(prefix);
|
|
2066
|
+
return true;
|
|
2067
|
+
}));
|
|
2068
|
+
if (!knownPrefixes.has(STATIC_PREFIX)) {
|
|
2069
|
+
const lastStaticGroupIndex = groups.findLastIndex((group) => group.some((prefix) => prefix.startsWith(STATIC_PREFIX)));
|
|
2070
|
+
groups.splice(Math.max(lastStaticGroupIndex, 0), 0, [STATIC_PREFIX]);
|
|
2071
|
+
}
|
|
2072
|
+
if (!knownPrefixes.has(CATCH_ALL_PREFIX)) groups.push([CATCH_ALL_PREFIX]);
|
|
2073
|
+
return groups;
|
|
2074
|
+
}
|
|
2075
|
+
function importKey({ names, isStatic }) {
|
|
2076
|
+
return (isStatic ? STATIC_PREFIX : "") + names.join(".");
|
|
2077
|
+
}
|
|
2017
2078
|
function compareFqn({ names: a }, { names: b }) {
|
|
2018
2079
|
const minParts = Math.min(a.length, b.length);
|
|
2019
2080
|
for (let i = 0; i < minParts; i++) {
|
|
@@ -2114,8 +2175,8 @@ var printer_default = {
|
|
|
2114
2175
|
")"
|
|
2115
2176
|
] : doc;
|
|
2116
2177
|
},
|
|
2117
|
-
embed(path) {
|
|
2118
|
-
return hasType(path, "string_literal") ? embedTextBlock(path) : null;
|
|
2178
|
+
embed(path, options) {
|
|
2179
|
+
return hasType(path, "string_literal") ? embedTextBlock(path, options) : null;
|
|
2119
2180
|
},
|
|
2120
2181
|
hasPrettierIgnore(path) {
|
|
2121
2182
|
return path.node.comments?.some(isPrettierIgnore) === true || canAttachComment(path.node, path.parent ? [path.parent] : []) && isFullyBetweenPrettierIgnore(path);
|
package/dist/index.d.cts
CHANGED
|
@@ -1575,7 +1575,7 @@ declare const _default: {
|
|
|
1575
1575
|
printers: {
|
|
1576
1576
|
java: {
|
|
1577
1577
|
print(path: import("prettier").AstPath<SyntaxNode>, options: import("prettier").ParserOptions<SyntaxNode>, print: (selector?: string | number | import("prettier").AstPath<SyntaxNode> | (string | number)[] | undefined, args?: unknown) => import("prettier").Doc, args: unknown): import("prettier/doc.js").builders.Doc;
|
|
1578
|
-
embed(path: import("prettier").AstPath<any
|
|
1578
|
+
embed(path: import("prettier").AstPath<any>, options: import("prettier").Options): ((textToDoc: (text: string, options: import("prettier").Options) => Promise<import("prettier").Doc>) => Promise<import("prettier/doc.js").builders.Doc[]>) | null;
|
|
1579
1579
|
hasPrettierIgnore(path: import("prettier").AstPath<SyntaxNode>): boolean;
|
|
1580
1580
|
canAttachComment: typeof canAttachComment;
|
|
1581
1581
|
isBlockComment(node: SyntaxNode): boolean;
|
|
@@ -1631,6 +1631,12 @@ declare const _default: {
|
|
|
1631
1631
|
}[];
|
|
1632
1632
|
description: string;
|
|
1633
1633
|
};
|
|
1634
|
+
importOrder: {
|
|
1635
|
+
type: "string";
|
|
1636
|
+
category: string;
|
|
1637
|
+
default: string;
|
|
1638
|
+
description: string;
|
|
1639
|
+
};
|
|
1634
1640
|
};
|
|
1635
1641
|
defaultOptions: {
|
|
1636
1642
|
arrowParens: "avoid";
|
package/dist/index.d.mts
CHANGED
|
@@ -1575,7 +1575,7 @@ declare const _default: {
|
|
|
1575
1575
|
printers: {
|
|
1576
1576
|
java: {
|
|
1577
1577
|
print(path: import("prettier").AstPath<SyntaxNode>, options: import("prettier").ParserOptions<SyntaxNode>, print: (selector?: string | number | import("prettier").AstPath<SyntaxNode> | (string | number)[] | undefined, args?: unknown) => import("prettier").Doc, args: unknown): import("prettier/doc.js").builders.Doc;
|
|
1578
|
-
embed(path: import("prettier").AstPath<any
|
|
1578
|
+
embed(path: import("prettier").AstPath<any>, options: import("prettier").Options): ((textToDoc: (text: string, options: import("prettier").Options) => Promise<import("prettier").Doc>) => Promise<import("prettier/doc.js").builders.Doc[]>) | null;
|
|
1579
1579
|
hasPrettierIgnore(path: import("prettier").AstPath<SyntaxNode>): boolean;
|
|
1580
1580
|
canAttachComment: typeof canAttachComment;
|
|
1581
1581
|
isBlockComment(node: SyntaxNode): boolean;
|
|
@@ -1631,6 +1631,12 @@ declare const _default: {
|
|
|
1631
1631
|
}[];
|
|
1632
1632
|
description: string;
|
|
1633
1633
|
};
|
|
1634
|
+
importOrder: {
|
|
1635
|
+
type: "string";
|
|
1636
|
+
category: string;
|
|
1637
|
+
default: string;
|
|
1638
|
+
description: string;
|
|
1639
|
+
};
|
|
1634
1640
|
};
|
|
1635
1641
|
defaultOptions: {
|
|
1636
1642
|
arrowParens: "avoid";
|
package/dist/index.mjs
CHANGED
|
@@ -61,6 +61,12 @@ var options_default = {
|
|
|
61
61
|
description: "Put opening braces on new lines (Allman style)"
|
|
62
62
|
}],
|
|
63
63
|
description: "Placement of opening braces."
|
|
64
|
+
},
|
|
65
|
+
importOrder: {
|
|
66
|
+
type: "string",
|
|
67
|
+
category: "Java",
|
|
68
|
+
default: "",
|
|
69
|
+
description: "Import groups in Spotless's format, such as `java,javax,,#java|#javax,#`. Module imports always come first. Empty puts static imports next, then all others."
|
|
64
70
|
}
|
|
65
71
|
};
|
|
66
72
|
//#endregion
|
|
@@ -309,6 +315,12 @@ function printAssignment(leftDoc, operator, rightDoc, rightNode) {
|
|
|
309
315
|
indentIfBreak$2(rightDoc, { groupId })
|
|
310
316
|
]);
|
|
311
317
|
}
|
|
318
|
+
function getLanguageByLanguageName(languages, languageName) {
|
|
319
|
+
return languages.find(({ name }) => name.toLowerCase() === languageName) ?? languages.find(({ aliases }) => aliases?.includes(languageName)) ?? languages.find(({ extensions }) => extensions?.includes(`.${languageName}`));
|
|
320
|
+
}
|
|
321
|
+
function inferParser(options, language) {
|
|
322
|
+
return getLanguageByLanguageName(options.plugins?.filter((plugin) => typeof plugin !== "string" && !(plugin instanceof URL)).reverse().flatMap((plugin) => plugin.languages ?? []) ?? [], language)?.parsers[0];
|
|
323
|
+
}
|
|
312
324
|
function printTextBlock(contents) {
|
|
313
325
|
return [
|
|
314
326
|
"\"\"\"",
|
|
@@ -317,13 +329,15 @@ function printTextBlock(contents) {
|
|
|
317
329
|
"\"\"\""
|
|
318
330
|
];
|
|
319
331
|
}
|
|
320
|
-
function embedTextBlock(path) {
|
|
332
|
+
function embedTextBlock(path, options) {
|
|
321
333
|
if (path.node.namedChildren.some(({ type }) => type === "string_interpolation") || path.node.children[0].value === "\"") return null;
|
|
322
334
|
const language = findEmbeddedLanguage(path);
|
|
323
335
|
if (!language) return null;
|
|
336
|
+
const parser = inferParser(options, language);
|
|
337
|
+
if (!parser) return null;
|
|
324
338
|
const text = unescapeTextBlockContents(textBlockContents(path.node));
|
|
325
339
|
return async (textToDoc) => {
|
|
326
|
-
return printTextBlock([escapeDocForTextBlock(await textToDoc(text, { parser
|
|
340
|
+
return printTextBlock([escapeDocForTextBlock(await textToDoc(text, { parser })), hardline$7]);
|
|
327
341
|
};
|
|
328
342
|
}
|
|
329
343
|
function textBlockContents(node) {
|
|
@@ -1176,7 +1190,11 @@ var expressions_default = {
|
|
|
1176
1190
|
}, "children")));
|
|
1177
1191
|
},
|
|
1178
1192
|
unary_expression(path, print) {
|
|
1179
|
-
|
|
1193
|
+
const parts = [path.call(print, "operatorNode")];
|
|
1194
|
+
const operandDoc = path.call(print, "operandNode");
|
|
1195
|
+
if (path.node.operandNode.comments) parts.push(group$4(indentInParentheses(operandDoc)));
|
|
1196
|
+
else parts.push(operandDoc);
|
|
1197
|
+
return parts;
|
|
1180
1198
|
},
|
|
1181
1199
|
field_access: printMemberChain,
|
|
1182
1200
|
generic_type(path, print) {
|
|
@@ -1918,11 +1936,11 @@ var names_default = {
|
|
|
1918
1936
|
//#region src/printers/packages-and-modules.ts
|
|
1919
1937
|
const { group: group$1, hardline: hardline$1, indent: indent$1, join: join$1, line: line$2 } = builders;
|
|
1920
1938
|
var packages_and_modules_default = {
|
|
1921
|
-
program(path, print) {
|
|
1939
|
+
program(path, print, options) {
|
|
1922
1940
|
if (!path.node.namedChildren.length) return [printDanglingComments(path), hardline$1];
|
|
1923
1941
|
const parts = [];
|
|
1924
1942
|
if (path.node.namedChildren[0].type !== "import_declaration") parts.push(path.call(print, "namedChildren", 0));
|
|
1925
|
-
const
|
|
1943
|
+
const moduleImports = [];
|
|
1926
1944
|
const imports = [];
|
|
1927
1945
|
const otherDeclarations = [];
|
|
1928
1946
|
path.each((child) => {
|
|
@@ -1930,13 +1948,15 @@ var packages_and_modules_default = {
|
|
|
1930
1948
|
if (child.node.type === "import_declaration") {
|
|
1931
1949
|
const names = extractNames(child.node.namedChildren[0]);
|
|
1932
1950
|
if (child.node.namedChildren.some(({ type }) => type === "asterisk")) names.push("*");
|
|
1933
|
-
|
|
1951
|
+
const modifier = child.node.children[1].type;
|
|
1952
|
+
(modifier === "module" ? moduleImports : imports).push({
|
|
1934
1953
|
doc,
|
|
1935
|
-
names
|
|
1954
|
+
names,
|
|
1955
|
+
isStatic: modifier === "static"
|
|
1936
1956
|
});
|
|
1937
1957
|
} else if (!child.isFirst) otherDeclarations.push(doc);
|
|
1938
1958
|
}, "namedChildren");
|
|
1939
|
-
parts.push(...[
|
|
1959
|
+
parts.push(...[moduleImports.sort(compareFqn), ...groupImports(imports, options.importOrder)].filter((group) => group.length).map((group) => join$1(hardline$1, group.map(({ doc }) => doc))), ...otherDeclarations);
|
|
1940
1960
|
return [...join$1([hardline$1, hardline$1], parts), hardline$1];
|
|
1941
1961
|
},
|
|
1942
1962
|
package_declaration(path, print) {
|
|
@@ -1960,7 +1980,8 @@ var packages_and_modules_default = {
|
|
|
1960
1980
|
},
|
|
1961
1981
|
import_declaration(path, print) {
|
|
1962
1982
|
const declaration = ["import "];
|
|
1963
|
-
|
|
1983
|
+
const modifier = path.node.children[1].type;
|
|
1984
|
+
if (modifier === "module" || modifier === "static") declaration.push(modifier, " ");
|
|
1964
1985
|
const identifierIndex = path.node.namedChildren.findIndex(({ type }) => type === "identifier" || type === "scoped_identifier");
|
|
1965
1986
|
declaration.push(path.call(print, "namedChildren", identifierIndex));
|
|
1966
1987
|
if (path.node.namedChildren.some(({ type }) => type === "asterisk")) declaration.push(".*");
|
|
@@ -2014,6 +2035,46 @@ var packages_and_modules_default = {
|
|
|
2014
2035
|
function extractNames(node) {
|
|
2015
2036
|
return node.type === "identifier" ? [node.value] : [...extractNames(node.scopeNode), node.nameNode.value];
|
|
2016
2037
|
}
|
|
2038
|
+
const STATIC_PREFIX = "static ";
|
|
2039
|
+
const CATCH_ALL_PREFIX = "";
|
|
2040
|
+
function groupImports(imports, importOrder) {
|
|
2041
|
+
if (!importOrder) return [imports.filter(({ isStatic }) => isStatic), imports.filter(({ isStatic }) => !isStatic)].filter((group) => group.length).map((group) => group.sort(compareFqn));
|
|
2042
|
+
const groups = parseImportOrder(importOrder);
|
|
2043
|
+
const prefixes = groups.flat();
|
|
2044
|
+
const importsByPrefix = /* @__PURE__ */ new Map();
|
|
2045
|
+
for (const entry of imports) {
|
|
2046
|
+
const key = importKey(entry);
|
|
2047
|
+
const prefix = prefixes.filter((candidate) => key.startsWith(candidate)).reduce((best, candidate) => candidate.length > best.length ? candidate : best);
|
|
2048
|
+
importsByPrefix.set(prefix, [...importsByPrefix.get(prefix) ?? [], {
|
|
2049
|
+
key,
|
|
2050
|
+
entry
|
|
2051
|
+
}]);
|
|
2052
|
+
}
|
|
2053
|
+
return groups.map((group) => group.flatMap((prefix) => (importsByPrefix.get(prefix) ?? []).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(({ entry }) => entry))).filter((group) => group.length);
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Parses an import order in Spotless's format: groups separated by `,` are
|
|
2057
|
+
* printed with blank lines between them, prefixes joined by `|` share a group,
|
|
2058
|
+
* `#` marks a static prefix, and an empty prefix catches everything else.
|
|
2059
|
+
* Each import belongs to its longest matching prefix.
|
|
2060
|
+
*/
|
|
2061
|
+
function parseImportOrder(importOrder) {
|
|
2062
|
+
const knownPrefixes = /* @__PURE__ */ new Set();
|
|
2063
|
+
const groups = importOrder.split(",").map((group) => group.split("|").map((prefix) => prefix.startsWith("#") ? STATIC_PREFIX + prefix.slice(1) : prefix).filter((prefix) => {
|
|
2064
|
+
if (knownPrefixes.has(prefix)) return false;
|
|
2065
|
+
knownPrefixes.add(prefix);
|
|
2066
|
+
return true;
|
|
2067
|
+
}));
|
|
2068
|
+
if (!knownPrefixes.has(STATIC_PREFIX)) {
|
|
2069
|
+
const lastStaticGroupIndex = groups.findLastIndex((group) => group.some((prefix) => prefix.startsWith(STATIC_PREFIX)));
|
|
2070
|
+
groups.splice(Math.max(lastStaticGroupIndex, 0), 0, [STATIC_PREFIX]);
|
|
2071
|
+
}
|
|
2072
|
+
if (!knownPrefixes.has(CATCH_ALL_PREFIX)) groups.push([CATCH_ALL_PREFIX]);
|
|
2073
|
+
return groups;
|
|
2074
|
+
}
|
|
2075
|
+
function importKey({ names, isStatic }) {
|
|
2076
|
+
return (isStatic ? STATIC_PREFIX : "") + names.join(".");
|
|
2077
|
+
}
|
|
2017
2078
|
function compareFqn({ names: a }, { names: b }) {
|
|
2018
2079
|
const minParts = Math.min(a.length, b.length);
|
|
2019
2080
|
for (let i = 0; i < minParts; i++) {
|
|
@@ -2114,8 +2175,8 @@ var printer_default = {
|
|
|
2114
2175
|
")"
|
|
2115
2176
|
] : doc;
|
|
2116
2177
|
},
|
|
2117
|
-
embed(path) {
|
|
2118
|
-
return hasType(path, "string_literal") ? embedTextBlock(path) : null;
|
|
2178
|
+
embed(path, options) {
|
|
2179
|
+
return hasType(path, "string_literal") ? embedTextBlock(path, options) : null;
|
|
2119
2180
|
},
|
|
2120
2181
|
hasPrettierIgnore(path) {
|
|
2121
2182
|
return path.node.comments?.some(isPrettierIgnore) === true || canAttachComment(path.node, path.parent ? [path.parent] : []) && isFullyBetweenPrettierIgnore(path);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-java-next-line",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Prettier Java plugin with configurable same-line and next-line braces",
|
|
5
5
|
"homepage": "https://github.com/motlin/prettier-java-next-line",
|
|
6
6
|
"repository": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"lerna:version": "lerna version --exact --no-private",
|
|
40
40
|
"lint": "eslint src test",
|
|
41
41
|
"prepare": "husky",
|
|
42
|
+
"prepublishOnly": "npm run build",
|
|
42
43
|
"test": "yarn run test:unit && yarn run test:e2e-core",
|
|
43
44
|
"test:all": "yarn run test && yarn run test:e2e-jhipster1 && yarn run test:e2e-jhipster2",
|
|
44
45
|
"test:e2e-core": "node scripts/clone-samples e2e-core && mocha \"test/repository-test/core-test.ts\"",
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"postcss": "^8.5.15",
|
|
78
79
|
"prettier": "^3.8.1",
|
|
79
80
|
"prettier-plugin-css-order": "^2.2.0",
|
|
80
|
-
"tree-sitter-java-orchard": "0.5.
|
|
81
|
+
"tree-sitter-java-orchard": "0.5.22",
|
|
81
82
|
"tsdown": "^0.23.0",
|
|
82
83
|
"typescript": "^6.0.3",
|
|
83
84
|
"typescript-eslint": "^8.57.1"
|