From 08cab53d7e9e450bcc43c1a9bf791524640ae31a Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 10 Jun 2014 14:16:47 +0400 Subject: [PATCH] Fixed shebang formatting (PY-12775). --- .../com/jetbrains/python/formatter/PyPreFormatProcessor.java | 3 +++ python/testData/formatter/shebang.py | 1 + python/testData/formatter/shebang_after.py | 1 + python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 9 insertions(+) create mode 100644 python/testData/formatter/shebang.py create mode 100644 python/testData/formatter/shebang_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java index ee56016d1df9..af07fe82bd3a 100644 --- a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java +++ b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java @@ -84,6 +84,9 @@ public class PyPreFormatProcessor implements PreFormatProcessor { String text = element.getText(); int commentStart = text.indexOf('#'); if (commentStart != -1 && (commentStart + 1) < text.length()) { + if (text.charAt(commentStart+1) == '!') { + return; //shebang + } String commentText = StringUtil.trimLeading(text.substring(commentStart + 1)); String newText = "# " + commentText; diff --git a/python/testData/formatter/shebang.py b/python/testData/formatter/shebang.py new file mode 100644 index 000000000000..44f772595799 --- /dev/null +++ b/python/testData/formatter/shebang.py @@ -0,0 +1 @@ +#!/usr/bin/python3 \ No newline at end of file diff --git a/python/testData/formatter/shebang_after.py b/python/testData/formatter/shebang_after.py new file mode 100644 index 000000000000..44f772595799 --- /dev/null +++ b/python/testData/formatter/shebang_after.py @@ -0,0 +1 @@ +#!/usr/bin/python3 \ 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 39836892db77..36805442a1ea 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -398,6 +398,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testShebang() { //PY-12775 + doTest(); + } + private void doTest() { doTest(false); }