Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

changeset 4445
5636dc48e1a0
parent 4150
a0cece581ad0
child 4541
e8ddd9d76414
equal deleted inserted replaced
4444:4867c8189b62 4445:5636dc48e1a0
126 "E211": self.__fixE201, 126 "E211": self.__fixE201,
127 "E221": self.__fixE221, 127 "E221": self.__fixE221,
128 "E222": self.__fixE221, 128 "E222": self.__fixE221,
129 "E223": self.__fixE221, 129 "E223": self.__fixE221,
130 "E224": self.__fixE221, 130 "E224": self.__fixE221,
131 "E225": self.__fixE221, 131 "E225": self.__fixE225,
132 "E226": self.__fixE221, 132 "E226": self.__fixE225,
133 "E227": self.__fixE221, 133 "E227": self.__fixE225,
134 "E228": self.__fixE221, 134 "E228": self.__fixE225,
135 "E231": self.__fixE231, 135 "E231": self.__fixE231,
136 "E241": self.__fixE221, 136 "E241": self.__fixE221,
137 "E242": self.__fixE221, 137 "E242": self.__fixE221,
138 "E251": self.__fixE251, 138 "E251": self.__fixE251,
139 "E261": self.__fixE261, 139 "E261": self.__fixE261,
1190 def __fixE221(self, code, line, pos): 1190 def __fixE221(self, code, line, pos):
1191 """ 1191 """
1192 Private method to fix extraneous whitespace around operator or 1192 Private method to fix extraneous whitespace around operator or
1193 keyword. 1193 keyword.
1194 1194
1195 Codes: E221, E222, E223, E224, E225, E226, E227, E228, E241, 1195 Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274
1196 E242, E271, E272, E273, E274).
1197 1196
1198 @param code code of the issue (string) 1197 @param code code of the issue (string)
1199 @param line line number of the issue (integer) 1198 @param line line number of the issue (integer)
1200 @param pos position inside line (integer) 1199 @param pos position inside line (integer)
1201 @return value indicating an applied/deferred fix (-1, 0, 1), 1200 @return value indicating an applied/deferred fix (-1, 0, 1),
1211 newText = self.__fixWhitespace(text, pos, ' ') 1210 newText = self.__fixWhitespace(text, pos, ' ')
1212 if newText == text: 1211 if newText == text:
1213 return (0, "", 0) 1212 return (0, "", 0)
1214 1213
1215 self.__source[line] = newText 1214 self.__source[line] = newText
1216 if code in ["E225", "E226", "E227", "E228"]: 1215 return (1, "FE221", 0)
1217 # Missing whitespace added. 1216
1218 return (1, "", 0) 1217 def __fixE225(self, code, line, pos):
1219 else: 1218 """
1220 # Extraneous whitespace removed. 1219 Private method to fix extraneous whitespaces around operator.
1221 return (1, "", 0) 1220
1221 Codes: E225, E226, E227, E228
1222
1223 @param code code of the issue (string)
1224 @param line line number of the issue (integer)
1225 @param pos position inside line (integer)
1226 @return value indicating an applied/deferred fix (-1, 0, 1),
1227 a message for the fix (string) and an ID for a deferred
1228 fix (integer)
1229 """
1230 line = line - 1
1231 text = self.__source[line]
1232
1233 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'):
1234 return (0, "", 0)
1235
1236 newText = text
1237 # determine length of operator
1238 tokens = '<>*/=^&|%!+-'
1239 pos2 = pos
1240 token_delimiter = len(tokens)
1241 for i in range(3):
1242 if pos2 < len(text) and text[pos2] in tokens[:token_delimiter]:
1243 pos2 += 1
1244 # only the first five could be repeated
1245 token_delimiter = 5
1246 else:
1247 break
1248 if pos2 < len(text) and text[pos2] not in ' \t':
1249 newText = self.__fixWhitespace(newText, pos2, ' ')
1250 newText = self.__fixWhitespace(newText, pos, ' ')
1251 if newText == text:
1252 return (0, "", 0)
1253
1254 self.__source[line] = newText
1255 # Missing whitespaces added.
1256 return (1, "FE225", 0)
1222 1257
1223 def __fixE231(self, code, line, pos): 1258 def __fixE231(self, code, line, pos):
1224 """ 1259 """
1225 Private method to fix missing whitespace after ',;:'. 1260 Private method to fix missing whitespace after ',;:'.
1226 1261

eric ide

mercurial