PY-16761 In Google code style requires section title to be capitalized, so "Args...
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Sat, 5 Sep 2015 22:31:49 +0000 (01:31 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Sat, 5 Sep 2015 22:31:49 +0000 (01:31 +0300)
python/src/com/jetbrains/python/documentation/GoogleCodeStyleDocString.java
python/testData/docstrings/googleParamNamedLikeSection.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/PySectionBasedDocStringTest.java

index a5bf2960e4edab530ac8b3487761c972fe7a1d1d..d720604ed24c43d42de5da63e8eb681459034ebe 100644 (file)
@@ -16,6 +16,7 @@
 package com.jetbrains.python.documentation;
 
 import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.containers.ContainerUtil;
 import com.jetbrains.python.toolbox.Substring;
 import org.jetbrains.annotations.NonNls;
@@ -120,8 +121,9 @@ public class GoogleCodeStyleDocString extends SectionBasedDocString {
     final Substring line = getLine(lineNum);
     final Matcher matcher = SECTION_HEADER.matcher(line);
     if (matcher.matches()) {
-      @NonNls final Substring title = line.getMatcherGroup(matcher, 1).trim();
-      if (SECTION_NAMES.contains(title.toString().toLowerCase())) {
+      final Substring title = line.getMatcherGroup(matcher, 1).trim();
+      @NonNls final String titleText = title.toString();
+      if (StringUtil.isCapitalized(titleText) && SECTION_NAMES.contains(titleText.toLowerCase())) {
         return Pair.create(title, lineNum + 1);
       }
     }
diff --git a/python/testData/docstrings/googleParamNamedLikeSection.py b/python/testData/docstrings/googleParamNamedLikeSection.py
new file mode 100644 (file)
index 0000000..4dd7921
--- /dev/null
@@ -0,0 +1,6 @@
+def func(x, *args):
+    """
+    Args:
+      x:
+      args:
+    """
\ No newline at end of file
index 531dfb23388a045f1269cb068473993a226b8ddb..85219a1893885243a3a02bf2ed165fa1cff114e7 100644 (file)
@@ -319,6 +319,15 @@ public class PySectionBasedDocStringTest extends PyTestCase {
     assertEquals("Something", returnSection.getFields().get(0).getType());
   }
 
+  public void testGoogleParamNamedLikeSection() {
+    final GoogleCodeStyleDocString docString = findAndParseGoogleStyleDocString();
+    assertSize(1, docString.getSections());
+    final Section paramSection = docString.getSections().get(0);
+    assertSize(2, paramSection.getFields());
+    assertEquals("x", paramSection.getFields().get(0).getName());
+    assertEquals("args", paramSection.getFields().get(1).getName());
+  }
+
   @Override
   protected String getTestDataPath() {
     return super.getTestDataPath() + "/docstrings";