prettier-plugin-java 2.1.0 → 2.2.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/dist/parser.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  var javaParser = require("java-parser");
3
3
  function parse(text, parsers, opts) {
4
- var cst = javaParser.parse(text, opts.entrypoint);
5
- return cst;
4
+ return javaParser.parse(text, opts.entrypoint);
6
5
  }
7
6
  module.exports = parse;
package/dist/printer.js CHANGED
@@ -3,26 +3,6 @@ var createPrettierDoc = require("./cst-printer").createPrettierDoc;
3
3
  // eslint-disable-next-line no-unused-vars
4
4
  function genericPrint(path, options, print) {
5
5
  var node = path.getValue();
6
- // console.log(node);
7
- // if (node.comments) {
8
- // console.log(node.type, node.comments);
9
- // }
10
- // node["comments"] = [
11
- // {
12
- // ast_type: "comment",
13
- // value: "// a",
14
- // leading: false,
15
- // trailing: true,
16
- // printed: false
17
- // },
18
- // {
19
- // ast_type: "comment",
20
- // value: "// b",
21
- // leading: true,
22
- // trailing: false,
23
- // printed: false
24
- // }
25
- // ];
26
6
  return createPrettierDoc(node, options);
27
7
  }
28
8
  module.exports = genericPrint;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.indentIfBreak = exports.ifBreak = exports.dedent = exports.indent = exports.fill = exports.group = exports.join = exports.concat = void 0;
4
- var prettier = require("prettier").doc.builders;
4
+ var doc_1 = require("prettier/doc");
5
5
  var processComments = require("./comments/format-comments").processComments;
6
6
  /*
7
7
  * ------------------------------------------------------------------
@@ -17,40 +17,39 @@ function concat(docs) {
17
17
  }
18
18
  exports.concat = concat;
19
19
  function join(sep, docs) {
20
- var concatenation = prettier.join(processComments(sep), processComments(docs));
21
- return processEmptyDocs(concatenation);
20
+ return doc_1.builders.join(processComments(sep), processComments(docs));
22
21
  }
23
22
  exports.join = join;
24
- function group(doc, opts) {
25
- var group = prettier.group(processComments(doc), opts);
23
+ function group(docs, opts) {
24
+ var group = doc_1.builders.group(processComments(docs), opts);
26
25
  return group.contents === undefined ? "" : group;
27
26
  }
28
27
  exports.group = group;
29
28
  function fill(docs) {
30
- var fill = prettier.fill(processComments(docs));
31
- return processEmptyDocs(fill);
29
+ return doc_1.builders.fill(processComments(docs));
32
30
  }
33
31
  exports.fill = fill;
34
32
  function indent(doc) {
35
- var indentedDoc = prettier.indent(processComments(doc));
36
- return indentedDoc.contents.length === 0 ? "" : indentedDoc;
33
+ var processedDoc = processComments(doc);
34
+ if (processedDoc.length === 0) {
35
+ return "";
36
+ }
37
+ return doc_1.builders.indent(processedDoc);
37
38
  }
38
39
  exports.indent = indent;
39
40
  function dedent(doc) {
40
- var indentedDoc = prettier.dedent(processComments(doc));
41
- return indentedDoc.contents.length === 0 ? "" : indentedDoc;
41
+ var processedDoc = processComments(doc);
42
+ if (processedDoc.length === 0) {
43
+ return "";
44
+ }
45
+ return doc_1.builders.dedent(processComments(doc));
42
46
  }
43
47
  exports.dedent = dedent;
44
48
  function ifBreak(breakContents, flatContents) {
45
- return prettier.ifBreak(processComments(breakContents), processComments(flatContents));
49
+ return doc_1.builders.ifBreak(processComments(breakContents), processComments(flatContents));
46
50
  }
47
51
  exports.ifBreak = ifBreak;
48
52
  function indentIfBreak(contents, opts) {
49
- return prettier.indentIfBreak(processComments(contents), opts);
53
+ return doc_1.builders.indentIfBreak(processComments(contents), opts);
50
54
  }
51
55
  exports.indentIfBreak = indentIfBreak;
52
- // TODO: remove this once prettier 3.0 is released
53
- var processEmptyDocs = function (doc) {
54
- var _a;
55
- return ((_a = doc.parts) === null || _a === void 0 ? void 0 : _a.length) === 0 ? "" : doc;
56
- };
@@ -401,15 +401,23 @@ function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext
401
401
  return getDeclarationsSeparator(interfaceMemberDeclarationContext, needLineInterfaceMemberDeclaration, isInterfaceMemberASemicolon);
402
402
  }
403
403
  exports.getInterfaceBodyDeclarationsSeparator = getInterfaceBodyDeclarationsSeparator;
404
+ function getAndRemoveLeadingComment(doc) {
405
+ var isTokenWithLeadingComment = typeof doc !== "string" && "leadingComments" in doc;
406
+ if (!isTokenWithLeadingComment) {
407
+ return [];
408
+ }
409
+ var leadingComments = (0, format_comments_1.getTokenLeadingComments)(doc);
410
+ delete doc.leadingComments;
411
+ return leadingComments;
412
+ }
404
413
  function putIntoBraces(argument, separator, LBrace, RBrace) {
405
- var rightBraceLeadingComments = (0, format_comments_1.getTokenLeadingComments)(RBrace);
414
+ var rightBraceLeadingComments = getAndRemoveLeadingComment(RBrace);
406
415
  var lastBreakLine =
407
416
  // check if last element of the array is a line
408
417
  rightBraceLeadingComments.length !== 0 &&
409
418
  rightBraceLeadingComments[rightBraceLeadingComments.length - 1] === hardline
410
419
  ? rightBraceLeadingComments.pop()
411
420
  : separator;
412
- delete RBrace.leadingComments;
413
421
  var contentInsideBraces;
414
422
  if ((0, utils_2.isEmptyDoc)(argument)) {
415
423
  if (rightBraceLeadingComments.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-java",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Prettier Java Plugin",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "java-parser": "2.0.4",
13
13
  "lodash": "4.17.21",
14
- "prettier": "2.8.4"
14
+ "prettier": "3.0.0"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "yarn run test:unit && yarn run test:e2e-core",
@@ -37,10 +37,9 @@
37
37
  "@types/klaw-sync": "6.0.1",
38
38
  "@types/lodash": "4.14.190",
39
39
  "@types/node": "18.11.9",
40
- "@types/prettier": "2.7.1",
41
40
  "@types/sinon": "10.0.13",
42
41
  "ts-node": "10.9.1",
43
42
  "typescript": "4.9.3"
44
43
  },
45
- "gitHead": "28084f4c2c6b53784c5853fc51865dc8c7b083f9"
44
+ "gitHead": "f93d55a4b4764c8ff289602f91716e686f112b50"
46
45
  }