diff --git a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java index c40b543eb92c..e2c30e560014 100644 --- a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java +++ b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java @@ -109,10 +109,6 @@ public class PyPreFormatProcessor implements PreFormatProcessor { if (charAfterDash == '#' || charAfterDash == ':') { return; // doc comment } - if (commentSpansSeveralLines(comment)) { - return; - } - final String commentTextWithoutDash = origText.substring(commentStart + 1); final String newText; if (isTrailingComment(comment)) { @@ -134,38 +130,6 @@ public class PyPreFormatProcessor implements PreFormatProcessor { } } - private static boolean commentSpansSeveralLines(@NotNull PsiComment comment) { - - for (PsiElement prevElement = comment.getPrevSibling(); prevElement != null; prevElement = prevElement.getPrevSibling()) { - if (prevElement instanceof PsiWhiteSpace) { - if (StringUtil.countNewLines(prevElement.getText()) > 1) { - break; - } - } - else if (prevElement instanceof PsiComment) { - return true; - } - else { - break; - } - } - - for (PsiElement nextElement = comment.getNextSibling(); nextElement != null; nextElement = nextElement.getNextSibling()) { - if (nextElement instanceof PsiWhiteSpace) { - if (StringUtil.countNewLines(nextElement.getText()) > 1) { - break; - } - } - else if (nextElement instanceof PsiComment) { - return true; - } - else { - break; - } - } - return false; - } - private static boolean isTrailingComment(@NotNull PsiComment comment) { final PsiElement prevElement = comment.getPrevSibling(); return !(prevElement instanceof PsiWhiteSpace) || !prevElement.textContains('\n'); diff --git a/python/testData/formatter/multilineCommentIgnored.py b/python/testData/formatter/multilineCommentIgnored.py deleted file mode 100644 index 50a25959707b..000000000000 --- a/python/testData/formatter/multilineCommentIgnored.py +++ /dev/null @@ -1,7 +0,0 @@ -# This line is not considered as part of multiline comment. - -#for c in string.ascii_lowercase: -# if c not in 'aeiou': -# print(c) - -#And this one too. \ No newline at end of file diff --git a/python/testData/formatter/multilineCommentIgnored_after.py b/python/testData/formatter/multilineCommentIgnored_after.py deleted file mode 100644 index b6ee7834d415..000000000000 --- a/python/testData/formatter/multilineCommentIgnored_after.py +++ /dev/null @@ -1,7 +0,0 @@ -# This line is not considered as part of multiline comment. - -#for c in string.ascii_lowercase: -# if c not in 'aeiou': -# print(c) - -# And this one too. \ No newline at end of file diff --git a/python/testData/formatter/whitespaceInsertedAfterHashSignInMultilineComment.py b/python/testData/formatter/whitespaceInsertedAfterHashSignInMultilineComment.py new file mode 100644 index 000000000000..814f4774b27a --- /dev/null +++ b/python/testData/formatter/whitespaceInsertedAfterHashSignInMultilineComment.py @@ -0,0 +1,4 @@ +#some +#invalid +#pep-8 +#comment \ No newline at end of file diff --git a/python/testData/formatter/whitespaceInsertedAfterHashSignInMultilineComment_after.py b/python/testData/formatter/whitespaceInsertedAfterHashSignInMultilineComment_after.py new file mode 100644 index 000000000000..80d188f7dd63 --- /dev/null +++ b/python/testData/formatter/whitespaceInsertedAfterHashSignInMultilineComment_after.py @@ -0,0 +1,4 @@ +# some +# invalid +# pep-8 +# comment \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 4a5f55e0b35b..ff821d6b524f 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -496,11 +496,6 @@ public class PyFormatterTest extends PyTestCase { doTest(); } - // PY-12932 - public void testMultilineCommentIgnored() { - doTest(); - } - // PY-12938 public void testDoubleHashCommentIgnored() { doTest(); @@ -516,6 +511,11 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + // PY-13232 + public void testWhitespaceInsertedAfterHashSignInMultilineComment() { + doTest(); + } + /** * This test merely checks that call to {@link com.intellij.psi.codeStyle.CodeStyleManager#reformat(com.intellij.psi.PsiElement)} * is possible for Python sources.