@@ -21,15 +21,15 @@ class DocumentationStyleBear(DocBaseClass, LocalBear):
21
21
CAN_FIX = {'Documentation' }
22
22
23
23
def process_documentation (self ,
24
- parsed ,
24
+ doc_comment : DocumentationComment ,
25
25
allow_missing_func_desc : str = False ,
26
26
indent_size : int = 4 ,
27
27
expand_one_liners : str = False ):
28
28
"""
29
29
This fixes the parsed documentation comment.
30
30
31
- :param parsed :
32
- Contains parsed documentation comment .
31
+ :param doc_comment :
32
+ Contains instance of DocumentationComment .
33
33
:param allow_missing_func_desc:
34
34
When set ``True`` this will allow functions with missing
35
35
descriptions, allowing functions to start with params.
@@ -40,6 +40,7 @@ def process_documentation(self,
40
40
:return:
41
41
A tuple of fixed parsed documentation comment and warning_desc.
42
42
"""
43
+ parsed = doc_comment .parse ()
43
44
# Assuming that the first element is always the only main
44
45
# description.
45
46
metadata = iter (parsed )
@@ -92,7 +93,36 @@ def process_documentation(self,
92
93
new_desc = new_desc .rstrip () + '\n '
93
94
94
95
new_metadata .append (m ._replace (desc = new_desc .lstrip (' ' )))
95
- return (new_metadata , warning_desc )
96
+
97
+ new_comment = DocumentationComment .from_metadata (
98
+ new_metadata , doc_comment .docstyle_definition ,
99
+ doc_comment .marker , doc_comment .indent , doc_comment .position )
100
+
101
+ # Instantiate default padding.
102
+ class_padding = doc_comment .docstyle_definition .class_padding
103
+ function_padding = doc_comment .docstyle_definition .function_padding
104
+ # Check if default padding exist in the coalang file.
105
+ if (class_padding != DocstyleDefinition .ClassPadding ('' , '' ) and
106
+ function_padding != DocstyleDefinition .FunctionPadding (
107
+ '' , '' )):
108
+ # Check docstring_type
109
+ if doc_comment .docstring_type == 'class' :
110
+ new_comment .top_padding = class_padding .top_padding
111
+ new_comment .bottom_padding = class_padding .bottom_padding
112
+ elif doc_comment .docstring_type == 'function' :
113
+ new_comment .top_padding = function_padding .top_padding
114
+ new_comment .bottom_padding = function_padding .bottom_padding
115
+ else :
116
+ # Keep paddings as they are originally.
117
+ new_comment .top_padding = doc_comment .top_padding
118
+ new_comment .bottom_padding = doc_comment .bottom_padding
119
+ else :
120
+ # If there's no default paddings defined. Keep padding as
121
+ # they are originally.
122
+ new_comment .top_padding = doc_comment .top_padding
123
+ new_comment .bottom_padding = doc_comment .bottom_padding
124
+
125
+ return (new_comment , warning_desc )
96
126
97
127
def run (self , filename , file , language : str ,
98
128
docstyle : str = 'default' , allow_missing_func_desc : str = False ,
@@ -131,18 +161,15 @@ def run(self, filename, file, language: str,
131
161
file = filename ,
132
162
line = doc_comment .line + 1 )
133
163
else :
134
- parsed = doc_comment .parse ()
135
-
136
- (new_metadata , warning_desc ) = self .process_documentation (
137
- parsed , allow_missing_func_desc , indent_size ,
138
- expand_one_liners )
139
-
140
- new_comment = DocumentationComment .from_metadata (
141
- new_metadata , doc_comment .docstyle_definition ,
142
- doc_comment .marker , doc_comment .indent ,
143
- doc_comment .position )
144
-
145
- if new_comment != doc_comment :
164
+ (new_comment , warning_desc ) = self .process_documentation (
165
+ doc_comment , allow_missing_func_desc ,
166
+ indent_size , expand_one_liners )
167
+
168
+ # Cache cleared so a fresh docstring is assembled
169
+ doc_comment .assemble .cache_clear ()
170
+ # Assembled docstring check, because paddings are only
171
+ # amended after assemble()
172
+ if new_comment .assemble () != doc_comment .assemble ():
146
173
# Something changed, let's apply a result.
147
174
diff = self .generate_diff (file , doc_comment , new_comment )
148
175
yield Result (
0 commit comments