From 6792b58ce40ea13114ed470163d66c81b70a234e Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Fri, 24 Apr 2015 18:34:02 +0300 Subject: [PATCH] PY-15171 Detect hanging indent in the value of key-value pair in dict literals --- python/src/com/jetbrains/python/formatter/PyBlock.java | 4 ++++ python/testData/formatter/hangingIndentInKeyValuePair.py | 5 +++++ .../testData/formatter/hangingIndentInKeyValuePair_after.py | 5 +++++ python/testSrc/com/jetbrains/python/PyFormatterTest.java | 5 +++++ 4 files changed, 19 insertions(+) create mode 100644 python/testData/formatter/hangingIndentInKeyValuePair.py create mode 100644 python/testData/formatter/hangingIndentInKeyValuePair_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 4c58ebfbe928..1b03c9f26b2c 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -407,6 +407,10 @@ public class PyBlock implements ASTBlock { final PyExpression valueExpression = ((PyKeywordArgument)firstItem).getValueExpression(); return valueExpression != null && hasHangingIndent(valueExpression); } + else if (firstItem instanceof PyKeyValueExpression) { + final PyExpression value = ((PyKeyValueExpression)firstItem).getValue(); + return value != null && hasHangingIndent(value); + } return hasHangingIndent(firstItem); } } diff --git a/python/testData/formatter/hangingIndentInKeyValuePair.py b/python/testData/formatter/hangingIndentInKeyValuePair.py new file mode 100644 index 000000000000..7dff24698bf9 --- /dev/null +++ b/python/testData/formatter/hangingIndentInKeyValuePair.py @@ -0,0 +1,5 @@ +example = {'breakfast': { + 'eggs': 1, + 'spam': 2 + } + } \ No newline at end of file diff --git a/python/testData/formatter/hangingIndentInKeyValuePair_after.py b/python/testData/formatter/hangingIndentInKeyValuePair_after.py new file mode 100644 index 000000000000..057ebe6a340d --- /dev/null +++ b/python/testData/formatter/hangingIndentInKeyValuePair_after.py @@ -0,0 +1,5 @@ +example = {'breakfast': { + 'eggs': 1, + 'spam': 2 +} +} \ 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 37ade21b235c..dc04d530f20b 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -559,6 +559,11 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + // PY-15171 + public void testHangingIndentInKeyValuePair() { + doTest(); + } + public void testAlignmentOfEmptyCollectionLiterals() { doTest(); }