eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

changeset 7256
4ef3b78ebb4e
parent 7247
bf9379f964f3
child 7360
9190402e4505
equal deleted inserted replaced
7255:d595f6f9cbf8 7256:4ef3b78ebb4e
11 import os 11 import os
12 import fnmatch 12 import fnmatch
13 13
14 from PyQt5.QtCore import pyqtSlot, Qt, QTimer 14 from PyQt5.QtCore import pyqtSlot, Qt, QTimer
15 from PyQt5.QtGui import QIcon 15 from PyQt5.QtGui import QIcon
16 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QAbstractButton, \ 16 from PyQt5.QtWidgets import (
17 QDialogButtonBox, QApplication, QHeaderView, QListWidgetItem 17 QDialog, QTreeWidgetItem, QAbstractButton, QDialogButtonBox, QApplication,
18 QHeaderView, QListWidgetItem
19 )
18 20
19 from E5Gui.E5Application import e5App 21 from E5Gui.E5Application import e5App
20 22
21 from .Ui_CodeStyleCheckerDialog import Ui_CodeStyleCheckerDialog 23 from .Ui_CodeStyleCheckerDialog import Ui_CodeStyleCheckerDialog
22 24
197 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png")) 199 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png"))
198 else: 200 else:
199 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) 201 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png"))
200 if fixed: 202 if fixed:
201 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png")) 203 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png"))
202 elif code in FixableCodeStyleIssues and not autofixing and \ 204 elif (
203 code not in self.__noFixCodesList: 205 code in FixableCodeStyleIssues and not autofixing and
206 code not in self.__noFixCodesList
207 ):
204 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable.png")) 208 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable.png"))
205 fixable = True 209 fixable = True
206 210
207 itm.setTextAlignment(0, Qt.AlignRight) 211 itm.setTextAlignment(0, Qt.AlignRight)
208 itm.setTextAlignment(1, Qt.AlignHCenter) 212 itm.setTextAlignment(1, Qt.AlignHCenter)
299 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 303 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
300 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 304 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
301 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 305 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
302 306
303 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker") 307 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker")
304 if self.__data is None or \ 308 if (
305 len(self.__data) < 6: 309 self.__data is None or
310 len(self.__data) < 6
311 ):
306 # initialize the data structure 312 # initialize the data structure
307 self.__data = { 313 self.__data = {
308 "ExcludeFiles": "", 314 "ExcludeFiles": "",
309 "ExcludeMessages": pycodestyle.DEFAULT_IGNORE, 315 "ExcludeMessages": pycodestyle.DEFAULT_IGNORE,
310 "IncludeMessages": "", 316 "IncludeMessages": "",
334 self.__data["LineComplexity"] = 15 340 self.__data["LineComplexity"] = 15
335 if "LineComplexityScore" not in self.__data: 341 if "LineComplexityScore" not in self.__data:
336 self.__data["LineComplexityScore"] = 10 342 self.__data["LineComplexityScore"] = 10
337 if "ValidEncodings" not in self.__data: 343 if "ValidEncodings" not in self.__data:
338 self.__data["ValidEncodings"] = "latin-1, utf-8" 344 self.__data["ValidEncodings"] = "latin-1, utf-8"
339 if "CopyrightMinFileSize" not in self.__data or \ 345 if (
340 "CopyrightAuthor" not in self.__data: 346 "CopyrightMinFileSize" not in self.__data or
347 "CopyrightAuthor" not in self.__data
348 ):
341 self.__data["CopyrightMinFileSize"] = 0 349 self.__data["CopyrightMinFileSize"] = 0
342 self.__data["CopyrightAuthor"] = "" 350 self.__data["CopyrightAuthor"] = ""
343 if "FutureChecker" not in self.__data: 351 if "FutureChecker" not in self.__data:
344 self.__data["FutureChecker"] = "" 352 self.__data["FutureChecker"] = ""
345 if "BuiltinsChecker" not in self.__data: 353 if "BuiltinsChecker" not in self.__data:
435 if self.files: 443 if self.files:
436 filterString = self.excludeFilesEdit.text() 444 filterString = self.excludeFilesEdit.text()
437 filterList = [f.strip() for f in filterString.split(",") 445 filterList = [f.strip() for f in filterString.split(",")
438 if f.strip()] 446 if f.strip()]
439 for fileFilter in filterList: 447 for fileFilter in filterList:
440 self.files = \ 448 self.files = [
441 [f for f in self.files 449 f for f in self.files
442 if not fnmatch.fnmatch(f, fileFilter.strip())] 450 if not fnmatch.fnmatch(f, fileFilter.strip())
451 ]
443 452
444 self.__errorItem = None 453 self.__errorItem = None
445 self.__resetStatistics() 454 self.__resetStatistics()
446 self.__clearErrors(self.files) 455 self.__clearErrors(self.files)
447 456
455 excludeMessages = self.excludeMessagesEdit.text() 464 excludeMessages = self.excludeMessagesEdit.text()
456 includeMessages = self.includeMessagesEdit.text() 465 includeMessages = self.includeMessagesEdit.text()
457 repeatMessages = self.repeatCheckBox.isChecked() 466 repeatMessages = self.repeatCheckBox.isChecked()
458 fixCodes = self.fixIssuesEdit.text() 467 fixCodes = self.fixIssuesEdit.text()
459 noFixCodes = self.noFixIssuesEdit.text() 468 noFixCodes = self.noFixIssuesEdit.text()
460 self.__noFixCodesList = \ 469 self.__noFixCodesList = [
461 [c.strip() for c in noFixCodes.split(",") if c.strip()] 470 c.strip() for c in noFixCodes.split(",") if c.strip()
471 ]
462 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages 472 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages
463 self.showIgnored = self.ignoredCheckBox.isChecked() and \ 473 self.showIgnored = (
464 repeatMessages 474 self.ignoredCheckBox.isChecked() and repeatMessages
475 )
465 maxLineLength = self.lineLengthSpinBox.value() 476 maxLineLength = self.lineLengthSpinBox.value()
466 maxDocLineLength = self.docLineLengthSpinBox.value() 477 maxDocLineLength = self.docLineLengthSpinBox.value()
467 blankLines = ( 478 blankLines = (
468 self.blankBeforeTopLevelSpinBox.value(), 479 self.blankBeforeTopLevelSpinBox.value(),
469 self.blankBeforeMethodSpinBox.value() 480 self.blankBeforeMethodSpinBox.value()
527 @return list of checker options 538 @return list of checker options
528 """ 539 """
529 options = self.__options[:] 540 options = self.__options[:]
530 flags = Utilities.extractFlags(source) 541 flags = Utilities.extractFlags(source)
531 if "noqa" in flags and isinstance(flags["noqa"], basestring): 542 if "noqa" in flags and isinstance(flags["noqa"], basestring):
532 excludeMessages = \ 543 excludeMessages = options[0].strip().rstrip(",")
533 options[0].strip().rstrip(",")
534 if excludeMessages: 544 if excludeMessages:
535 excludeMessages += "," 545 excludeMessages += ","
536 excludeMessages += flags["noqa"] 546 excludeMessages += flags["noqa"]
537 options[0] = excludeMessages 547 options[0] = excludeMessages
538 return options 548 return options
1333 @pyqtSlot() 1343 @pyqtSlot()
1334 def on_addBuiltinButton_clicked(self): 1344 def on_addBuiltinButton_clicked(self):
1335 """ 1345 """
1336 Private slot to add a built-in assignment to be ignored. 1346 Private slot to add a built-in assignment to be ignored.
1337 """ 1347 """
1338 from .CodeStyleAddBuiltinIgnoreDialog import \ 1348 from .CodeStyleAddBuiltinIgnoreDialog import (
1339 CodeStyleAddBuiltinIgnoreDialog 1349 CodeStyleAddBuiltinIgnoreDialog
1350 )
1340 dlg = CodeStyleAddBuiltinIgnoreDialog(self) 1351 dlg = CodeStyleAddBuiltinIgnoreDialog(self)
1341 if dlg.exec_() == QDialog.Accepted: 1352 if dlg.exec_() == QDialog.Accepted:
1342 left, right = dlg.getData() 1353 left, right = dlg.getData()
1343 QTreeWidgetItem(self.builtinsAssignmentList, [left, right]) 1354 QTreeWidgetItem(self.builtinsAssignmentList, [left, right])
1344 1355

eric ide

mercurial