src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py

branch
eric7
changeset 10683
779cda568acb
parent 10458
2074b8393649
child 11090
f5f5f5803935
equal deleted inserted replaced
10682:47be220abdaf 10683:779cda568acb
811 and docstring.strip("'\"").strip() == "Class documentation goes here." 811 and docstring.strip("'\"").strip() == "Class documentation goes here."
812 ): 812 ):
813 self.__error(docstringContext.end(), 0, "D206") 813 self.__error(docstringContext.end(), 0, "D206")
814 return 814 return
815 815
816 def __checkTripleDoubleQuotes(self, docstringContext, context): # noqa: U100 816 def __checkTripleDoubleQuotes(self, docstringContext, _context):
817 """ 817 """
818 Private method to check, that all docstrings are surrounded 818 Private method to check, that all docstrings are surrounded
819 by triple double quotes. 819 by triple double quotes.
820 820
821 @param docstringContext docstring context 821 @param docstringContext docstring context
822 @type DocStyleContext 822 @type DocStyleContext
823 @param context context of the docstring 823 @param _context context of the docstring (unused)
824 @type DocStyleContext 824 @type DocStyleContext
825 """ 825 """
826 if docstringContext is None: 826 if docstringContext is None:
827 return 827 return
828 828
829 docstring = docstringContext.ssource().strip() 829 docstring = docstringContext.ssource().strip()
830 if not docstring.startswith(('"""', 'r"""', 'u"""')): 830 if not docstring.startswith(('"""', 'r"""', 'u"""')):
831 self.__error(docstringContext.start(), 0, "D111") 831 self.__error(docstringContext.start(), 0, "D111")
832 832
833 def __checkBackslashes(self, docstringContext, context): # noqa: U100 833 def __checkBackslashes(self, docstringContext, _context):
834 """ 834 """
835 Private method to check, that all docstrings containing 835 Private method to check, that all docstrings containing
836 backslashes are surrounded by raw triple double quotes. 836 backslashes are surrounded by raw triple double quotes.
837 837
838 @param docstringContext docstring context 838 @param docstringContext docstring context
839 @type DocStyleContext 839 @type DocStyleContext
840 @param context context of the docstring 840 @param _context context of the docstring (unused)
841 @type DocStyleContext 841 @type DocStyleContext
842 """ 842 """
843 if docstringContext is None: 843 if docstringContext is None:
844 return 844 return
845 845
900 0 if context.contextType() == "module" else len(context.indent()) + 4 900 0 if context.contextType() == "module" else len(context.indent()) + 4
901 ) 901 )
902 if indent != expectedIndent: 902 if indent != expectedIndent:
903 self.__error(docstringContext.start(), 0, "D122") 903 self.__error(docstringContext.start(), 0, "D122")
904 904
905 def __checkSummary(self, docstringContext, context): # noqa: U100 905 def __checkSummary(self, docstringContext, _context):
906 """ 906 """
907 Private method to check, that docstring summaries contain some text. 907 Private method to check, that docstring summaries contain some text.
908 908
909 @param docstringContext docstring context 909 @param docstringContext docstring context
910 @type DocStyleContext 910 @type DocStyleContext
911 @param context context of the docstring 911 @param _context context of the docstring (unused)
912 @type DocStyleContext 912 @type DocStyleContext
913 """ 913 """
914 if docstringContext is None: 914 if docstringContext is None:
915 return 915 return
916 916
917 summary, lineNumber = self.__getSummaryLine(docstringContext) 917 summary, lineNumber = self.__getSummaryLine(docstringContext)
918 if summary == "": 918 if summary == "":
919 self.__error(docstringContext.start() + lineNumber, 0, "D130") 919 self.__error(docstringContext.start() + lineNumber, 0, "D130")
920 920
921 def __checkEndsWithPeriod(self, docstringContext, context): # noqa: U100 921 def __checkEndsWithPeriod(self, docstringContext, _context):
922 """ 922 """
923 Private method to check, that docstring summaries end with a period. 923 Private method to check, that docstring summaries end with a period.
924 924
925 @param docstringContext docstring context 925 @param docstringContext docstring context
926 @type DocStyleContext 926 @type DocStyleContext
927 @param context context of the docstring 927 @param _context context of the docstring (unused)
928 @type DocStyleContext 928 @type DocStyleContext
929 """ 929 """
930 if docstringContext is None: 930 if docstringContext is None:
931 return 931 return
932 932
933 summary, lineNumber = self.__getSummaryLine(docstringContext) 933 summary, lineNumber = self.__getSummaryLine(docstringContext)
934 if not summary.endswith("."): 934 if not summary.endswith("."):
935 self.__error(docstringContext.start() + lineNumber, 0, "D131") 935 self.__error(docstringContext.start() + lineNumber, 0, "D131")
936 936
937 def __checkImperativeMood(self, docstringContext, context): # noqa: U100 937 def __checkImperativeMood(self, docstringContext, _context):
938 """ 938 """
939 Private method to check, that docstring summaries are in 939 Private method to check, that docstring summaries are in
940 imperative mood. 940 imperative mood.
941 941
942 @param docstringContext docstring context 942 @param docstringContext docstring context
943 @type DocStyleContext 943 @type DocStyleContext
944 @param context context of the docstring 944 @param _context context of the docstring (unused)
945 @type DocStyleContext 945 @type DocStyleContext
946 """ 946 """
947 if docstringContext is None: 947 if docstringContext is None:
948 return 948 return
949 949
1064 if contextLines[start - 1].strip(): 1064 if contextLines[start - 1].strip():
1065 self.__error(docstringContext.start(), 0, "D142") 1065 self.__error(docstringContext.start(), 0, "D142")
1066 if contextLines[end + 1].strip(): 1066 if contextLines[end + 1].strip():
1067 self.__error(docstringContext.end(), 0, "D143") 1067 self.__error(docstringContext.end(), 0, "D143")
1068 1068
1069 def __checkBlankAfterSummary(self, docstringContext, context): # noqa: U100 1069 def __checkBlankAfterSummary(self, docstringContext, _context):
1070 """ 1070 """
1071 Private method to check, that docstring summaries are followed 1071 Private method to check, that docstring summaries are followed
1072 by a blank line. 1072 by a blank line.
1073 1073
1074 @param docstringContext docstring context 1074 @param docstringContext docstring context
1075 @type DocStyleContext 1075 @type DocStyleContext
1076 @param context context of the docstring 1076 @param _context context of the docstring (unused)
1077 @type DocStyleContext 1077 @type DocStyleContext
1078 """ 1078 """
1079 if docstringContext is None: 1079 if docstringContext is None:
1080 return 1080 return
1081 1081
1086 1086
1087 summary, lineNumber = self.__getSummaryLine(docstringContext) 1087 summary, lineNumber = self.__getSummaryLine(docstringContext)
1088 if len(docstrings) > 2 and docstrings[lineNumber + 1].strip(): 1088 if len(docstrings) > 2 and docstrings[lineNumber + 1].strip():
1089 self.__error(docstringContext.start() + lineNumber, 0, "D144") 1089 self.__error(docstringContext.start() + lineNumber, 0, "D144")
1090 1090
1091 def __checkBlankAfterLastParagraph(self, docstringContext, context): # noqa: U100 1091 def __checkBlankAfterLastParagraph(self, docstringContext, _context):
1092 """ 1092 """
1093 Private method to check, that the last paragraph of docstrings is 1093 Private method to check, that the last paragraph of docstrings is
1094 followed by a blank line. 1094 followed by a blank line.
1095 1095
1096 @param docstringContext docstring context 1096 @param docstringContext docstring context
1097 @type DocStyleContext 1097 @type DocStyleContext
1098 @param context context of the docstring 1098 @param _context context of the docstring (unused)
1099 @type DocStyleContext 1099 @type DocStyleContext
1100 """ 1100 """
1101 if docstringContext is None: 1101 if docstringContext is None:
1102 return 1102 return
1103 1103
1111 1111
1112 ################################################################## 1112 ##################################################################
1113 ## Checking functionality below (eric specific ones) 1113 ## Checking functionality below (eric specific ones)
1114 ################################################################## 1114 ##################################################################
1115 1115
1116 def __checkEricQuotesOnSeparateLines(self, docstringContext, context): # noqa: U100 1116 def __checkEricQuotesOnSeparateLines(self, docstringContext, _context):
1117 """ 1117 """
1118 Private method to check, that leading and trailing quotes are on 1118 Private method to check, that leading and trailing quotes are on
1119 a line by themselves. 1119 a line by themselves.
1120 1120
1121 @param docstringContext docstring context 1121 @param docstringContext docstring context
1122 @type DocStyleContext 1122 @type DocStyleContext
1123 @param context context of the docstring 1123 @param _context context of the docstring (unused)
1124 @type DocStyleContext 1124 @type DocStyleContext
1125 """ 1125 """
1126 if docstringContext is None: 1126 if docstringContext is None:
1127 return 1127 return
1128 1128
1130 if lines[0].strip().strip("ru\"'"): 1130 if lines[0].strip().strip("ru\"'"):
1131 self.__error(docstringContext.start(), 0, "D221") 1131 self.__error(docstringContext.start(), 0, "D221")
1132 if lines[-1].strip().strip("\"'"): 1132 if lines[-1].strip().strip("\"'"):
1133 self.__error(docstringContext.end(), 0, "D222") 1133 self.__error(docstringContext.end(), 0, "D222")
1134 1134
1135 def __checkEricEndsWithPeriod(self, docstringContext, context): # noqa: U100 1135 def __checkEricEndsWithPeriod(self, docstringContext, _context):
1136 """ 1136 """
1137 Private method to check, that docstring summaries end with a period. 1137 Private method to check, that docstring summaries end with a period.
1138 1138
1139 @param docstringContext docstring context 1139 @param docstringContext docstring context
1140 @type DocStyleContext 1140 @type DocStyleContext
1141 @param context context of the docstring 1141 @param _context context of the docstring (unused)
1142 @type DocStyleContext 1142 @type DocStyleContext
1143 """ 1143 """
1144 if docstringContext is None: 1144 if docstringContext is None:
1145 return 1145 return
1146 1146
1391 # step 3: report undefined signals 1391 # step 3: report undefined signals
1392 for signal in documentedSignals: 1392 for signal in documentedSignals:
1393 if signal not in definedSignals: 1393 if signal not in definedSignals:
1394 self.__error(docstringContext.end(), 0, "D263", signal) 1394 self.__error(docstringContext.end(), 0, "D263", signal)
1395 1395
1396 def __checkEricBlankAfterSummary(self, docstringContext, context): # noqa: U100 1396 def __checkEricBlankAfterSummary(self, docstringContext, _context):
1397 """ 1397 """
1398 Private method to check, that docstring summaries are followed 1398 Private method to check, that docstring summaries are followed
1399 by a blank line. 1399 by a blank line.
1400 1400
1401 @param docstringContext docstring context 1401 @param docstringContext docstring context
1402 @type DocStyleContext 1402 @type DocStyleContext
1403 @param context context of the docstring 1403 @param _context context of the docstring (unused)
1404 @type DocStyleContext 1404 @type DocStyleContext
1405 """ 1405 """
1406 if docstringContext is None: 1406 if docstringContext is None:
1407 return 1407 return
1408 1408
1474 ): 1474 ):
1475 return 1475 return
1476 1476
1477 self.__error(docstringContext.end(), 0, "D245") 1477 self.__error(docstringContext.end(), 0, "D245")
1478 1478
1479 def __checkEricNBlankAfterLastParagraph( 1479 def __checkEricNBlankAfterLastParagraph(self, docstringContext, _context):
1480 self, docstringContext, context # noqa: U100
1481 ):
1482 """ 1480 """
1483 Private method to check, that the last paragraph of docstrings is 1481 Private method to check, that the last paragraph of docstrings is
1484 not followed by a blank line. 1482 not followed by a blank line.
1485 1483
1486 @param docstringContext docstring context 1484 @param docstringContext docstring context
1487 @type DocStyleContext 1485 @type DocStyleContext
1488 @param context context of the docstring 1486 @param _context context of the docstring (unused)
1489 @type DocStyleContext 1487 @type DocStyleContext
1490 """ 1488 """
1491 if docstringContext is None: 1489 if docstringContext is None:
1492 return 1490 return
1493 1491
1612 ) 1610 )
1613 1611
1614 def __checkEricDocumentationSequence( 1612 def __checkEricDocumentationSequence(
1615 self, 1613 self,
1616 docstringContext, 1614 docstringContext,
1617 context, # noqa: U100 1615 _context,
1618 ): 1616 ):
1619 """ 1617 """
1620 Private method to check, that method docstring follows the correct sequence 1618 Private method to check, that method docstring follows the correct sequence
1621 of entries (e.g. @param is followed by @type). 1619 of entries (e.g. @param is followed by @type).
1622 1620
1623 @param docstringContext docstring context 1621 @param docstringContext docstring context
1624 @type DocStyleContext 1622 @type DocStyleContext
1625 @param context context of the docstring 1623 @param _context context of the docstring (unused)
1626 @type DocStyleContext 1624 @type DocStyleContext
1627 """ 1625 """
1628 if docstringContext is None: 1626 if docstringContext is None:
1629 return 1627 return
1630 1628
1667 ) 1665 )
1668 1666
1669 def __checkEricDocumentationDeprecatedTags( 1667 def __checkEricDocumentationDeprecatedTags(
1670 self, 1668 self,
1671 docstringContext, 1669 docstringContext,
1672 context, # noqa: U100 1670 _context,
1673 ): 1671 ):
1674 """ 1672 """
1675 Private method to check the use of deprecated documentation tags. 1673 Private method to check the use of deprecated documentation tags.
1676 1674
1677 @param docstringContext docstring context 1675 @param docstringContext docstring context
1678 @type DocStyleContext 1676 @type DocStyleContext
1679 @param context context of the docstring 1677 @param _context context of the docstring (unused)
1680 @type DocStyleContext 1678 @type DocStyleContext
1681 """ 1679 """
1682 if docstringContext is None: 1680 if docstringContext is None:
1683 return 1681 return
1684 1682
1705 ) 1703 )
1706 1704
1707 def __checkEricDocumentationIndent( 1705 def __checkEricDocumentationIndent(
1708 self, 1706 self,
1709 docstringContext, 1707 docstringContext,
1710 context, # noqa: U100 1708 _context,
1711 ): 1709 ):
1712 """ 1710 """
1713 Private method to check the the correct indentation of the tag lines. 1711 Private method to check the the correct indentation of the tag lines.
1714 1712
1715 @param docstringContext docstring context 1713 @param docstringContext docstring context
1716 @type DocStyleContext 1714 @type DocStyleContext
1717 @param context context of the docstring 1715 @param _context context of the docstring (unused)
1718 @type DocStyleContext 1716 @type DocStyleContext
1719 """ 1717 """
1720 if docstringContext is None or not docstringContext.source(): 1718 if docstringContext is None or not docstringContext.source():
1721 return 1719 return
1722 1720

eric ide

mercurial