Skip to content

Commit

Permalink
rework code
Browse files Browse the repository at this point in the history
  • Loading branch information
nonomoho committed Nov 14, 2019
1 parent f744c9f commit 180de0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
23 changes: 10 additions & 13 deletions packages/java-parser/src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function shouldIgnore(node, comments, ignoredNodes) {
function filterFormatterOffOn(comments) {
return [...comments].filter(comment =>
comment.image.match(
/(\/\/(\s*)@formatter:off(\s*))|(\/\*(\s*)@formatter:off(\s*)\*\/)|(\/\/(\s*)@formatter:on(\s*))|(\/\*(\s*)@formatter:on(\s*)\*\/)/gm
/(\/\/(\s*)@formatter:(off|on)(\s*))|(\/\*(\s*)@formatter:(off|on)(\s*)\*\/)/gm
)
);
}
Expand All @@ -168,9 +168,8 @@ function matchFormatterOffOnPair(comments) {
let isCurrentCommentOff = true;
const pairs = [];
let paired = {};
comments.forEach((comment, index, array) => {
isCurrentCommentOff =
comment.image.slice(comment.image.length - 3) === "off";
comments.forEach(comment => {
isCurrentCommentOff = comment.image.slice(-3) === "off";

if (!isPreviousCommentOff) {
if (isCurrentCommentOff) {
Expand All @@ -183,22 +182,20 @@ function matchFormatterOffOnPair(comments) {
paired = {};
}
}

if (index === array.length - 1 && isCurrentCommentOff) {
paired.on = undefined;
pairs.push(paired);
paired = {};
}

isPreviousCommentOff = isCurrentCommentOff;
});

if (comments.length > 0 && isCurrentCommentOff) {
paired.on = undefined;
pairs.push(paired);
}

return pairs;
}

function shouldNotFormat(node, commentPairs) {
const matchingPair = _.find(
commentPairs.reverse(),
const matchingPair = _.findLast(
commentPairs,
comment => comment.off.extendedRange.endOffset < node.location.startOffset
);
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void myMethod(int param1, int param2, int param3, int param4, int param5,

}
}

public class PrettierIgnoreClass {
public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,19 @@ public void myMethod(int param1, int param2, int param3, int param4, int param5,
}
}

// @formatter:on
public class PrettierIgnoreClass {
public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) {

}
public void myMethod(
int param1,
int param2,
int param3,
int param4,
int param5,
int param6,
int param7,
int param8,
int param9,
int param10
) {}
}

0 comments on commit 180de0c

Please sign in to comment.