158 ) |
158 ) |
159 return False |
159 return False |
160 |
160 |
161 return True |
161 return True |
162 |
162 |
|
163 def __codeMatch(self, code): |
|
164 """ |
|
165 Private method to check, if the code should be fixed. |
|
166 |
|
167 @param code to check (string) |
|
168 @return flag indicating it should be fixed (boolean) |
|
169 """ |
|
170 def mutualStartswith(a, b): |
|
171 """ |
|
172 Local helper method to compare the beginnings of two strings |
|
173 against each other. |
|
174 |
|
175 @return flag indicating that one string starts with the other |
|
176 (boolean) |
|
177 """ |
|
178 return b.startswith(a) or a.startswith(b) |
|
179 |
|
180 if self.__noFixCodes: |
|
181 for noFixCode in [c.strip() for c in self.__noFixCodes]: |
|
182 if mutualStartswith(code.lower(), noFixCode.lower()): |
|
183 return False |
|
184 |
|
185 if self.__fixCodes: |
|
186 for fixCode in [c.strip() for c in self.__fixCodes]: |
|
187 if mutualStartswith(code.lower(), fixCode.lower()): |
|
188 return True |
|
189 return False |
|
190 |
|
191 return True |
|
192 |
163 def fixIssue(self, line, pos, message): |
193 def fixIssue(self, line, pos, message): |
164 """ |
194 """ |
165 Public method to fix the fixable issues. |
195 Public method to fix the fixable issues. |
166 |
196 |
167 @param line line number of issue (integer) |
197 @param line line number of issue (integer) |
171 the fix (string) |
201 the fix (string) |
172 """ |
202 """ |
173 code = message.split(None, 1)[0].strip() |
203 code = message.split(None, 1)[0].strip() |
174 |
204 |
175 if line <= len(self.__source) and \ |
205 if line <= len(self.__source) and \ |
176 code not in self.__noFixCodes and \ |
206 self.__codeMatch(code) and \ |
177 (code in self.__fixCodes or len(self.__fixCodes) == 0) and \ |
|
178 code in self.__fixes: |
207 code in self.__fixes: |
179 res = self.__fixes[code](code, line, pos) |
208 res = self.__fixes[code](code, line, pos) |
180 if res[0]: |
209 if res[0]: |
181 self.__modified = True |
210 self.__modified = True |
182 self.fixed += 1 |
211 self.fixed += 1 |