Use Ruff for linting and fix a ton of issues

This commit is contained in:
Veronica Berglyd Olsen
2025-04-03 01:15:52 +02:00
parent d2796d27c3
commit 53a2d0e691
43 changed files with 257 additions and 235 deletions
+7 -5
View File
@@ -978,7 +978,7 @@ class GuiDocEditor(QPlainTextEdit):
super().dropEvent(event)
return
def focusNextPrevChild(self, next: bool) -> bool:
def focusNextPrevChild(self, _next: bool) -> bool:
"""Capture the focus request from the tab key on the text
editor. If the editor has focus, we do not change focus and
allow the editor to insert a tab. If the search bar has focus,
@@ -1037,7 +1037,7 @@ class GuiDocEditor(QPlainTextEdit):
logger.error("Invalid keyword '%s'", keyword)
return False
logger.debug("Inserting keyword '%s'", keyword)
state = self.insertNewBlock("%s: " % keyword)
state = self.insertNewBlock(f"{keyword}: ")
return state
@pyqtSlot()
@@ -1528,10 +1528,10 @@ class GuiDocEditor(QPlainTextEdit):
if fLen == min(numA, numB):
cursor.beginEditBlock()
cursor.setPosition(posS)
for i in range(fLen):
for _ in range(fLen):
cursor.deletePreviousChar()
cursor.setPosition(posE)
for i in range(fLen):
for _ in range(fLen):
cursor.deletePreviousChar()
cursor.endEditBlock()
@@ -1943,7 +1943,9 @@ class GuiDocEditor(QPlainTextEdit):
exist = False
cPos = cursor.selectionStart() - block.position()
tExist = SHARED.project.index.checkThese(tBits, self._docHandle)
for sTag, sPos, sExist in zip(reversed(tBits), reversed(tPos), reversed(tExist)):
for sTag, sPos, sExist in zip(
reversed(tBits), reversed(tPos), reversed(tExist), strict=False
):
if cPos >= sPos:
# The cursor is between the start of two tags
if cPos <= sPos + len(sTag):
+3 -6
View File
@@ -610,12 +610,9 @@ class GuiDocViewHistory:
for loop, it is skipped entirely if log level isn't DEBUG.
"""
if CONFIG.isDebug: # pragma: no cover
for i, (h, p) in enumerate(zip(self._navHistory, self._posHistory)):
logger.debug(
"History %02d: %s %13s [x:%d]" % (
i + 1, ">" if i == self._currPos else " ", h, p
)
)
for i, (h, p) in enumerate(zip(self._navHistory, self._posHistory, strict=False)):
a = ">" if i == self._currPos else " "
logger.debug(f"History {i + 1:02d}: {a} {h:13s} [x:{p}]")
return
+3 -3
View File
@@ -936,7 +936,7 @@ class GuiMainMenu(QMenuBar):
# Search > Find in Project
self.aFindProj = qtAddAction(self.srcMenu, self.tr("Find in Project"))
self.aFindProj.setShortcut("Ctrl+Shift+F")
self.aFindProj.triggered.connect(lambda: self.requestViewChange.emit(nwView.SEARCH))
self.aFindProj.triggered.connect(qtLambda(self.requestViewChange.emit, nwView.SEARCH))
return
@@ -956,10 +956,10 @@ class GuiMainMenu(QMenuBar):
self.mSelectLanguage = qtAddMenu(self.toolsMenu, self.tr("Spell Check Language"))
languages = SHARED.spelling.listDictionaries()
languages.insert(0, ("None", self.tr("Default")))
for n, (tag, language) in enumerate(languages):
for tag, language in languages:
aSpell = QAction(self.mSelectLanguage)
aSpell.setText(language)
aSpell.triggered.connect(lambda n, tag=tag: self._changeSpelling(tag))
aSpell.triggered.connect(qtLambda(self._changeSpelling, tag))
self.mSelectLanguage.addAction(aSpell)
# Tools > Re-Run Spell Check
+4 -4
View File
@@ -259,17 +259,17 @@ class GuiProjectToolBar(QWidget):
self.mQuick = QMenu(self)
self.tbQuick = NIconToolButton(self, iSz)
self.tbQuick.setToolTip("%s [Ctrl+L]" % self.tr("Quick Links"))
self.tbQuick.setToolTip("{0} [Ctrl+L]".format(self.tr("Quick Links")))
self.tbQuick.setShortcut("Ctrl+L")
self.tbQuick.setMenu(self.mQuick)
# Move Buttons
self.tbMoveU = NIconToolButton(self, iSz)
self.tbMoveU.setToolTip("%s [Ctrl+Up]" % self.tr("Move Up"))
self.tbMoveU.setToolTip("{0} [Ctrl+Up]".format(self.tr("Move Up")))
self.tbMoveU.clicked.connect(self.projTree.moveItemUp)
self.tbMoveD = NIconToolButton(self, iSz)
self.tbMoveD.setToolTip("%s [Ctrl+Down]" % self.tr("Move Down"))
self.tbMoveD.setToolTip("{0} [Ctrl+Down]".format(self.tr("Move Down")))
self.tbMoveD.clicked.connect(self.projTree.moveItemDown)
# Add Item Menu
@@ -309,7 +309,7 @@ class GuiProjectToolBar(QWidget):
self._buildRootMenu()
self.tbAdd = NIconToolButton(self, iSz)
self.tbAdd.setToolTip("%s [Ctrl+N]" % self.tr("Add Item"))
self.tbAdd.setToolTip("{0} [Ctrl+N]".format(self.tr("Add Item")))
self.tbAdd.setShortcut("Ctrl+N")
self.tbAdd.setMenu(self.mAdd)
+1 -1
View File
@@ -155,4 +155,4 @@ class _PopRightMenu(QMenu):
if isinstance(parent := self.parent(), QWidget):
offset = QPoint(parent.width(), parent.height() - self.height())
self.move(parent.mapToGlobal(offset))
return super(_PopRightMenu, self).event(event)
return super().event(event)