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

branch
eric7
changeset 10457
4bef44d7a378
parent 10455
bed8a0c90d11
child 10458
2074b8393649
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py	Sun Dec 31 17:08:39 2023 +0100
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py	Sun Dec 31 17:44:59 2023 +0100
@@ -187,6 +187,7 @@
         "D270",
         "D271",
         "D272",
+        "D273",
     ]
 
     def __init__(
@@ -316,6 +317,7 @@
                     (self.__checkEricException, ("D250", "D251", "D252", "D253")),
                     (self.__checkEricDocumentationSequence, ("D270", "D271")),
                     (self.__checkEricDocumentationDeprecatedTags, ("D272",)),
+                    (self.__checkEricDocumentationIndent, ("D273",))
                 ],
                 "docstring": [
                     (self.__checkTripleDoubleQuotes, ("D111",)),
@@ -1703,3 +1705,36 @@
                         tag,
                         deprecationsList[tag],
                     )
+
+    def __checkEricDocumentationIndent(
+        self,
+        docstringContext,
+        context,  # noqa: U100
+    ):
+        """
+        Private method to check the the correct indentation of the tag lines.
+
+        @param docstringContext docstring context
+        @type DocStyleContext
+        @param context context of the docstring
+        @type DocStyleContext
+        """
+        if docstringContext is None or not docstringContext.source():
+            return
+
+        lines = docstringContext.source()
+        for line in lines[1:]:
+            if line.strip():
+                indentationLength = len(line) - len(line.lstrip())
+                break
+        else:
+            # only empty lines except the first one
+            return
+
+        for lineno, line in enumerate(lines):
+            strippedLine = line.lstrip()
+            if strippedLine.startswith("@"):
+                tag = strippedLine.split(None, 1)[0]
+                currentIndentation = len(line) - len(strippedLine)
+                if currentIndentation != indentationLength:
+                    self.__error(docstringContext.start() + lineno, 0, "D273", tag)

eric ide

mercurial